728x90
반응형
📃 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
반응형
'HW > Raspberry Pi | Arduino' 카테고리의 다른 글
라즈베리파이 - MariaDB 설치 (0) | 2022.08.18 |
---|---|
라즈베리파이 - Flask (0) | 2022.08.18 |
라즈베리파이 - 삼바 구축, 공유폴더 생성, 원격 접속 서비스(RDP) 설치 (0) | 2022.08.17 |
라즈베리파이 - 라즈비안 설정(raspi-config) (0) | 2022.08.17 |
라즈베리파이 - SSH 클라이언트 사용하여 라즈베리파이에 접속 (0) | 2022.08.16 |
댓글