To check that our LEDs are all correctly wired up and that we can control them using Python, we will write this short program to test them.
First, move into our project directory by typing this:
cd ~/WearableTech/
Now, make a new directory for this chapter by typing this:
mkdir Chapter3
Now, move into our new directory:
cd Chapter3
Next, we create our test program by typing this:
nano testLED.py
Then, we enter the following code into Nano:
#!/usr/bin/python3
from gpiozero import LED
from time import sleep
pair1 = LED(11)
pair2 = LED(9)
pair3 = LED(10)
pair4 = LED(7)
pair5 = LED(8)
for i in range(4):
pair1.on()
sleep(2)
pair1.off()
pair2.on()
sleep(2)
pair2.off()
pair3.on()
sleep(2)
pair3.off()
pair4.on()
sleep(2)
pair4.off()
pair5.on()
sleep(2)
pair5.off()
Press Ctrl + O followed by Enter to save the file, and then Ctrl + X to exit Nano. We can then run our file by typing this:
python3 ./testLED.py
All being well, we should see each pair of LEDs light up for two seconds in turn, and then the next pair; and the whole loop should repeat four times.