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 43
|
import random import RPi.GPIO as GPIO import time
BOTTOM_LEFT = 26 BOTTOM_RIGHT = 5 MIDDLE_LEFT = 13 MIDDLE_RIGHT = 19 TOP = 6
GPIO.setmode(GPIO.BCM) GPIO.setup(BOTTOM_LEFT, GPIO.OUT) GPIO.setup(BOTTOM_RIGHT, GPIO.OUT) GPIO.setup(MIDDLE_LEFT, GPIO.OUT) GPIO.setup(MIDDLE_RIGHT, GPIO.OUT) GPIO.setup(TOP, GPIO.OUT)
try: while True: GPIO.output(BOTTOM_LEFT, random.randint(0, 1)) GPIO.output(BOTTOM_RIGHT, random.randint(0, 1)) GPIO.output(MIDDLE_LEFT, random.randint(0, 1)) GPIO.output(MIDDLE_RIGHT, random.randint(0, 1)) GPIO.output(TOP, random.randint(0, 1))
time.sleep(0.5)
GPIO.output(BOTTOM_LEFT, GPIO.LOW) GPIO.output(BOTTOM_RIGHT, GPIO.LOW) GPIO.output(MIDDLE_LEFT, GPIO.LOW) GPIO.output(MIDDLE_RIGHT, GPIO.LOW) GPIO.output(TOP, GPIO.LOW)
time.sleep(0.5) except KeyboardInterrupt: GPIO.cleanup()
|