Raspberry Pi LED control with Python

preview_player
Показать описание
Raspberry Pi computer LED display test using Python script and GPIO outputs, breadboard kit, LEDs, 120 ohm resistors and ribbon cable from old hard drive. This is a simple demo showing my first attempt using Raspberry Pi's GPIO. It also shows the case I made using a plastic container (drilled and cut-out holes) and the Python program. Note the program HIGH/LOW commands switched due to bug in RasPi GPIO 0.3.0a library (fixed in 0.3.1a version).
Рекомендации по теме
Комментарии
Автор

Source code: Sorry about the weird formatting, Youtube won't let me post source code directly. Look at the end of the view, you will see the source code on the screen. Pause and copy it. I am sure it can be optimized, this was just a quick cut & paste but you can probably nest the last two for loops and shorten the code even more.

devhackmod
Автор

Source code (part 3) - Setup your while loop, which will never stop because "count" is 0 and you aren't changing it. If you want to cycle for specific number of times, add a line in your loop like count = count + 1, and make your while (count < 40) would cycle 40 times.

while (count<1):

devhackmod
Автор

Source code (part 2) - set up your count as 0 to never exits the while loop, and delay is how fast to make it work (smaller delay like 0.01 is faster, bigger delay 0.10 is slower):

count = 0
delay = 0.04


devhackmod
Автор

Source code (part 5) - Now turn off your lights, but in reverse order:

print "done. turning off."
for i in range(0, 8):
GPIO.output(a[7-i], GPIO.LOW)
time.sleep(delay)
if (i>0):
GPIO.output(a[7-(i-1)], GPIO.HIGH)
GPIO.output(a[7-i], GPIO.HIGH)
print(i)
print "off"

devhackmod
Автор

Source code (part 4) -Turn on your lights, 2 at a time (that is why there are 2 lines making GPIO.output high:

print "turning on..."
for i in range(0, 8):
GPIO.output(a[i], GPIO.LOW)
time.sleep(delay)
if (i>0):
GPIO.output(a[i-1], GPIO.HIGH)
GPIO.output(a[i], GPIO.HIGH)
print(i)

devhackmod
Автор

Source code (part 1) - start by setting up your RasPi:
import time
import RPi.GPIO as GPIO

#to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)

#set up the GPIO channels
from array import *
a = array('i'', [7, 11, 12, 13, 15, 16, 18, 22])

for i in range(0, 8):
print "setup pin", a[i]
GPIO.setup(a[i], GPIO.OUT)
GPIO.output(a[i], GPIO.HIGH)

devhackmod
join shbcf.ru