無障礙紅綠燈
This pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!
- import RPi.GPIO as GPIO
- import time
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- led_pin1 = (2, 3, 4)
- led_pin2 = (23,24,25)
- buttom=(21)
- GPIO.setup(21, GPIO.IN)
- for each_led_pin in led_pin1:
- GPIO.setup(each_led_pin, GPIO.OUT)
- for each_led_pin in led_pin2:
- GPIO.setup(each_led_pin, GPIO.OUT)
- def isPush():
- return True if GPIO.input(21) else False
- def f(led_pins):
- for each_led_pin in led_pins:
- GPIO.output(each_led_pin, False)
- GPIO.output(led_pins[2],True)
- for t in range(1000000):
- if isPush():
- break
- time.sleep(1)
- GPIO.output(led_pins[2],False)
- GPIO.output(led_pins[1],True)
- time.sleep(3)
- GPIO.output(led_pins[1],False)
- GPIO.output(led_pins[0],True)
- while True:
- f(led_pin1)
- f(led_pin2)
- GPIO.cleanup()