[Python] 라즈베리 파이의 GPIO를 이용해 스위치/LED 제어하기 (2)

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)

LED = [18,23,24,25]

GPIO.setup(21,GPIO.IN,pull_up_down=GPIO.PUD_UP)

GPIO.setup(LED,GPIO.OUT)
GPIO.output(LED,False)

flag = False
def LED369(channel):
    for num in range(1,101): 
        N = num % 4
        
        if((num%10) == 3 or (num%10) == 6 or (num%10) == 9):
            print(num,"jap")
        elif((num//10) == 3 or (num//10) == 6 or (num//10) == 9):
            print(num,"jap")
        else:
            print(num)
            GPIO.output(LED[N],1)
        
        sleep(0.1)
        GPIO.output(LED[N],0)
        
        if flag:break
    

GPIO.add_event_detect(21,GPIO.FALLING,callback=LED369,bouncetime=300)
print("Wait for the switch event.")

while True:
    try:
        sleep(5)
    except KeyboardInterrupt:
        print("Au revoir!".center(20))
        flag = True
        sleep(0.1)
        GPIO.cleanup()
        break