1. Led Blink

Out first project will blink both the onboard LED and an LED connected external LED

This is our code:

#LED Blink
import board
import digitalio
import time

#Tell Circuitpython that we want to control the output of the onboard LED Pin
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

print('hello world')

while True:
    print('off')
    led.value = False
    time.sleep(1)
    
    led.value = True
    time.sleep(1)
    print('on')
    
    
#TASK 1: Change the 'Hello World' message to "LED Blink"

#TASK 2: Change the speed of the blinking.
# How fast can you go before you can't see it blinking
```

To Get Started, open the Circuit Python folder from the Desktop

Navigate to the 1_LED folder and double click 1_blinkOnboard.py to open it in Thonny

Make sure that your PICO is plugged into the PI

In Thonny, make sure that the Pi Pico (Circuit Python) is selected in the bottom right hand corner

Now click RUN to start the program

External LED

Next, we will connect an external LED to GP1 and the ground pin next to it.

LEDs have polarity. This means they will not work if connected the wrong way around. The longer leg is positive and goes into GP1, and the shorter leg is negative (Ground)

Make sure you unplug your PICO from the PI before making changes to the circuit or you could brink your PICO

Open the file 2_BlinkExternal.py in Thonny. Make sure that you click Stop to shut down the previous program.

import board
import digitalio
import time

led = digitalio.DigitalInOut(board.GP1)
led.direction = digitalio.Direction.OUTPUT

print('hello world')

while True:
    print('on')
    led.value = False
    time.sleep(1)
    
    print('off')
    led.value = True
    time.sleep(1)

#TASK: Modify your circuit and code to blink a second LED
# so that when one is off, the other is on
```

Last updated