Tonight, my dad an I decided to do a chasing LED. I want to do an LED cube, but it was too close to my bedtime. We got the basic instructions from this instructables. Here’s what you’ll need to complete the project:
Raspberry Pi with accessories
LEDs, breadboard, resistors, and wires
The circuit is set up basically by having each of the positive legs of the LEDs (the longer leg) in one of the rails of the breadboard that go all the way from one end to the other. The positive 5 Volts from the PiFace is connected to the rail next to that one and then a resistor connects the two rails so that the 5 volts must pass through the resistor to get to the LEDs. I used a 180 ohm resistor because that’s what came with the Raspberry Pi CanaKit. I ended up adding a second resistor for the video because the LEDs were too bright.
Then, each short leg of the LED goes to its own row on the breadboard and is connected to a different output on the PiFace from LED0 to LED7.
Here’s a picture of the code:
Here’s what each line does:
Lines 1 and two import libraries to be used later. Line 3 is blank. Line 4 shortens that long code into shorter pfd. Line 5 makes sure that all of the LEDs are turned off. Line 6 is going to make the entire sequence run 5 times. Lines 7 to 11 is the loop that sequentially turns each LED on and then back off again after waiting .o2 seconds. Lines 12 to 16 is the loop that reverses the sequence and turns the LEDs on and off from the other end. The last line just once again makes sure that all of the LEDs are turned off before ending the program.
I did one new thing tonight. I normally use VIM to type my programs into the terminal window but I keep forgetting the commands. So, tonight, I used nano. To run nano, just type “sudo nano filename.py” at the command prompt. Then you use ctrl and the “O” key to save the file and ctrl and the “X” key to exit nano. Then to run the program from the command line, I just type “sudo python chasing.py” (my program’s name was chasing.py).
Here’s a video of the LEDs working.