Revision ade8d74a
Added by dsorber over 13 years ago
| 525.743/code/test scripts/blinky_pattern.py | ||
|---|---|---|
|
import random
|
||
|
import sys
|
||
|
import time
|
||
|
|
||
|
import RPi.GPIO as GPIO
|
||
|
|
||
|
outputs = [23, 24, 25, 8, 7]
|
||
|
|
||
|
def main():
|
||
|
# Use the BCM addressing scheme
|
||
|
GPIO.setmode(GPIO.BCM)
|
||
|
|
||
|
# Setup all five outputs
|
||
|
for gpio in outputs:
|
||
|
GPIO.setup(gpio, GPIO.OUT)
|
||
|
GPIO.output(gpio, False)
|
||
|
|
||
|
while True:
|
||
|
cylon()
|
||
|
randomize()
|
||
|
|
||
|
turn_on_top_down()
|
||
|
turn_off_top_down()
|
||
|
turn_on_bottom_up()
|
||
|
turn_off_bottom_up()
|
||
|
|
||
|
|
||
|
def turn_on_top_down():
|
||
|
for gpio in outputs:
|
||
|
GPIO.output(gpio, True)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def turn_on_bottom_up():
|
||
|
for gpio in reversed(outputs):
|
||
|
GPIO.output(gpio, True)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def turn_off_top_down():
|
||
|
for gpio in outputs:
|
||
|
GPIO.output(gpio, False)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def turn_off_bottom_up():
|
||
|
for gpio in reversed(outputs):
|
||
|
GPIO.output(gpio, False)
|
||
|
time.sleep(.25)
|
||
|
|
||
|
def cylon():
|
||
|
for gpio in outputs[:-1]:
|
||
|
GPIO.output(gpio, True)
|
||
|
time.sleep(.08)
|
||
|
GPIO.output(gpio, False)
|
||
|
|
||
|
for gpio in outputs[::-1][:-1]:
|
||
|
GPIO.output(gpio, True)
|
||
|
time.sleep(.08)
|
||
|
GPIO.output(gpio, False)
|
||
|
|
||
|
def randomize():
|
||
|
rand_val = random.randint(0, 31)
|
||
|
# LED1 - GPIO23
|
||
|
if rand_val & 0b00001:
|
||
|
GPIO.output(23, True)
|
||
|
else:
|
||
|
GPIO.output(23, False)
|
||
|
# LED2 - GPIO24
|
||
|
if rand_val & 0b00010:
|
||
|
GPIO.output(24, True)
|
||
|
else:
|
||
|
GPIO.output(24, False)
|
||
|
# LED3 - GPIO25
|
||
|
if rand_val & 0b00100:
|
||
|
GPIO.output(25, True)
|
||
|
else:
|
||
|
GPIO.output(25, False)
|
||
|
# LED4 - GPIO8
|
||
|
if rand_val & 0b01000:
|
||
|
GPIO.output(8, True)
|
||
|
else:
|
||
|
GPIO.output(8, False)
|
||
|
# LED5 - GPIO7
|
||
|
if rand_val & 0b10000:
|
||
|
GPIO.output(7, True)
|
||
|
else:
|
||
|
GPIO.output(7, False)
|
||
|
time.sleep(0.1)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
sys.exit(main())
|
||
Adding the first version of my LED blink test script which should be able to be reused verbatim as a test program for the actual board. Also adding correct mechanic drawing for SMT switch.