树莓派-1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| import RPi.GPIO as GPIO import time
LED_BULE = 38 BTN1 = 7
def init(): GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(LED_BULE, GPIO.OUT) GPIO.setup(BTN1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(BTN1, GPIO.RISING, bouncetime=200)
def main(): init()
while 1: if GPIO.event_detected(BTN1): GPIO.output(LED_BULE, GPIO.HIGH) time.sleep(1) GPIO.output(LED_BULE, GPIO.LOW) time.sleep(1)
if __name__ == '__main__': main()
|