Counting from 1 to 9 with LEDs, Python code and the mraa library
Once we finish the wirings and we make sure that all the components and the wires are in the right place, we can write our first version of the Python code to count from 1 to 9 with the LEDs, transfer it to the board via SFTP and execute it.
We will write a few lines of Python code that will use the mraa
library to run the following steps to count from 1 to 9, with a 3 seconds pause between each step:
- Turn on LED1
- Turn on LED1 and LED2
- Turn on LED1, LED2 and LED3
- Turn on LED1, LED2, LED3 and LED4
- Turn on LED1, LED2, LED3, LED4 and LED5
- Turn on LED1, LED2, LED3, LED4, LED5 and LED6
- Turn on LED1, LED2, LED3, LED4, LED5, LED6 and LED7
- Turn on LED1, LED2, LED3, LED4, LED5, LED6, LED7 and LED8
- Turn on LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8 and LED9
The following lines show the Python code that performs the previously explained actions. The code file for the sample is iot_python_chapter_03_02.py
.
import mraa import time if __name__...