Blinky
Remember Blinky?
The very first project from the Makecode Robotics course caused a single LED to cycle back and forth between on and off.
Recall it used a single while loop containing 4 blocks:
- set the LED to on
- sleep for half a second
- set the LED to off
- sleep for half a second
Now we do the same thing, just using 4 lines of Python code instead of 4 Makecode blocks:
# This section lets the system know which libraries we want to use
from adafruit_circuitplayground import cp
import time
# This section is where our main code goes
# Everything indented under the 'while True' will repeat forever
# We call this a 'while loop'
while True:
cp.red_led = True
time.sleep(0.5)
cp.red_led = False
time.sleep(0.5)
# Note - anything with a '#' infront is a comment and is ignored
Challenge Problem
Can you do the same thing using only 2 lines of Python code within the while loop?