🍞
Breadstick
  • Breadstick Innovations Website
  • Breadsticks
    • đŸĨ–Raspberry Breadstick
      • Code Examples
        • Demo Code
        • POV Wand
        • Pride Flags POV Wand
        • 6-Axis IMU
        • RGB Blink
        • AsyncIO RGB Blink
        • Digital Input
        • Digital Output
        • PWM
        • ADC
        • Servo Motor
    • đŸĨ–Raspberry Breadstick Lite
    • 🍞Support Boards
      • I2C Devices
        • 🚌I2C Bus Rail Adapter
        • đŸŒĻī¸Weather Crouton
        • 😎Brightness Crouton
        • 📏Distance Crouton
        • đŸĢ¨Motion Crouton
      • I2S Devices
        • đŸ“ĸBoombox
      • SPI Devices
      • đŸ•šī¸Buttons/Switches
    • Learning Resources
    • Troubleshooting
  • Nougat
    • Nougat C3
    • Nougat Quad
    • Installing WLED
  • Pico Slices
    • 🔴Slice 1 - LED Mixer
      • Assembly Guide
      • CircuitPython Code
        • 1 - Blink
        • 2 - Analog Read to Plotter
        • 3 - PWM Fade
        • 4 - Pot Controlled PWM
        • 5 - Gamma Correction
    • âąī¸Slice 2 - Stopwatch
      • Assembly Guide
      • Coding Lessons
        • 1 - 7-Segment Display Intro
        • 2 - Cycling Through All Segments
    • âŦœSlice 3 - 8x8 Dot Matrix
      • Assembly Guide
      • MicroPython Code
        • 1 - Moveable Pixel
        • 2 - Snake
    • Circuit Python Setup
    • Reset Bricked Pico
  • Christmas
    • Christmas Tree DIY kit
  • Protoboards
    • â¤ī¸Proto-Heart
    • đŸĨĒProto-Toast
  • SHOP
Powered by GitBook
On this page
  • Video
  • Code with Detailed Comments
  • Just Code

Was this helpful?

  1. Pico Slices
  2. Slice 1 - LED Mixer
  3. CircuitPython Code

1 - Blink

Blink the Red LED

PreviousCircuitPython CodeNext2 - Analog Read to Plotter

Last updated 2 years ago

Was this helpful?

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