본문 바로가기
HW/Raspberry Pi | Arduino

라즈베리파이 - 실습

by 코젼 2022. 8. 17.
728x90
반응형

2022-08-17(42일차)


지니 사용


📃 LED 깜빡이기

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

LED = 8

GPIO.setup(LED, GPIO.OUT, initial=GPIO.LOW)

try:
		while 1:
			GPIO.output(LED, GPIO.HIGH)
			time.sleep(0.5)
			
			GPIO.output(LED, GPIO.LOW)
			time.sleep(0.5)
except KeyboardInterrupt:
	pass
	
GPIO.cleanup()
음극 - GND
양극 - 저항, 8

📃 스위치 누를 때마다 LED 켜기


📃 LED 세개 켜기


📃 LED 세개 번갈아가며 켜기

// C++ code
//
void setup()
{
  pinMode(12, OUTPUT);
}

void loop()
{
  digitalWrite(12, HIGH);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  
  digitalWrite(12, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(7, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  
  digitalWrite(12, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  
}

전압을 확인할 수있다.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setwarnings(False)

LED_R = 8
LED_G = 11
LED_B = 16

GPIO.setup(LED_R, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(LED_G, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(LED_B, GPIO.OUT, initial=GPIO.LOW)

try:
		while 1:
			GPIO.output(LED_R, GPIO.HIGH)
			GPIO.output(LED_G, GPIO.LOW)
			GPIO.output(LED_B, GPIO.LOW)
			time.sleep(1.0)
			
			GPIO.output(LED_R, GPIO.LOW)
			GPIO.output(LED_G, GPIO.HIGH)
			GPIO.output(LED_B, GPIO.LOW)
			time.sleep(1.0)
			
			GPIO.output(LED_R, GPIO.LOW)
			GPIO.output(LED_G, GPIO.LOW)
			GPIO.output(LED_B, GPIO.HIGH)
			time.sleep(1.0)
			
except KeyboardInterrupt:
	pass
	
GPIO.cleanup()

 


 

728x90
반응형

댓글