1. 터미널에서 pip install RPi.GPIO 입력 후 다운로드
import RPi.GPIO as GPIO
# Set up GPIO mode 설정
GPIO.setmode(GPIO.BCM)
led_pins = [21, 20, 16, 26, 19, 17, 6, 5] #GPIO pins
GPIO.setwarnings(False)
# Set up LED pins 설정
for pin in led_pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.HIGH) # 초기값 설정
try:
while True:
user_input = (input("Enter 1 to turn on LEDs or 0 to turn them off: "))
if user_input == "0":
for pin in led_pins:
GPIO.output(pin, GPIO.HIGH) # Turn on
elif user_input == "1":
for pin in led_pins:
GPIO.output(pin, GPIO.LOW) # Turn off
else:
print("Invalid input. Enter 1 or 0.")
except KeyboardInterrupt: #오류 캐치
pass
GPIO.cleanup()
첫댓글 감사드립니다.