1 - Blink

Blink the Red LED

Video

Code with Detailed Comments

'''
Pico Slice 1 - RGB Mixer
Tutorial 1 - Blink
'''

# CircuitPython comes with a bunch of modules
# that makes programming microcontrollers easy!
# To get started, we're going to blink our red LED.

# First we import the modules we're going to use in our code

import time
import board
from digitalio import DigitalInOut, Direction, Pull

# To control our red LED, we need to create it in code as a DigitalInOut object.
# When we do, we specify which I/O pin to connect to.
# The board module we imported makes this really easy!
# If you check your Pico Slice, you'll see GP2 labeling the red LED,
# that's what you need to tell the board module to connect to the red LED!

red_led = DigitalInOut(board.GP2)

# red_led is now a DigitalInOut object with built-in attributes and functionality!
# By default, its pin direction attribute is set to input, but we'll have to change it
# to output in order to drive the LED.
# Naturally there's a built in method for doing so!

red_led.switch_to_output()

# Now that that it's an output, we can simply turn it on and off!
# Let's set up an endless while loop and to do that continuously.


while True:                     # Loop Forever:
    red_led.value = True            # Turn the red LED on
    time.sleep(0.5)                 # Do nothing for 0.5 seconds
    red_led.value = False           # Turn the red LED off
    time.sleep(0.5)                 # Do nothing for 0.5 seconds


Just Code

'''
Pico Slice 1 - RGB Mixer
Tutorial 1 - Blink
'''

import time
import board
from digitalio import DigitalInOut, Direction, Pull

red_led = DigitalInOut(board.GP2)
red_led.switch_to_output()

while True:
    red_led.value = True
    time.sleep(0.5)
    red_led.value = False
    time.sleep(0.5)


Blink in action

Last updated