5. Both LEDs should have turned on! Turn your LEDs off by typing “p13.value(0)” and pressing enter. Like in the last exercise with the on-board LED, try blinking your LEDs by going back and forth between the on and off commands.
What if you want to blink your LED many times in a row but don’t want to type out the commands every time? Write a loop! In coding, a loop is a few lines of commands that will repeat many times over until you tell it to stop. Let’s try writing a loop that will blink your LED 10 times.
6. In the same Beagle Term session type “import time” and press enter to load the library called time. Then use the following code to write the loop. First type “for i in range(10):” and press enter. This command begins a loop which will repeat 10 times. Beagle Term will automatically know you have begun a loop and the next line will be indented to show you are adding instructions to your loop.
7. Type “p13.value(1)”. This instruction will turn on your LED. Press enter. The next line will be indented too so you can continue to add code instructions to your loop.
8. Type “time.sleep(0.5)”. This instructs your microcontroller to rest for 0.5 seconds while the LED remains on.
9. Type “p13.value(0)” and press enter. This instruction turns the LED off.
10. Type “time.sleep(0.5)” and press enter. This instructs your microcontroller to rest for another 0.5 seconds while the LED remains off.
11. Press enter to start running the loop. You may have to press enter a few times until the LED starts blinking.
Note: Let’s say you set the LED to blink 100 times but you don’t want that loop to finish, you can interrupt it by pressing CTRL+C