Skip to content

Instantly share code, notes, and snippets.

@dglaude
Created October 18, 2022 22:03

Revisions

  1. dglaude created this gist Oct 18, 2022.
    57 changes: 57 additions & 0 deletions code.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    """Seeeduino XIAO RP2040: Build in RGB LED simultaniously as NeoPixel."""
    import time
    import board
    import neopixel
    import digitalio

    BLACK = (0, 0, 0)
    RED = (255, 0, 0)
    GREEN = (0, 255, 0)
    BLUE = (0, 0, 255)
    WHITE = (255, 255, 255)

    pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
    pixel.brightness = 0.3

    led_blue = digitalio.DigitalInOut(board.LED_BLUE)
    led_blue.direction = digitalio.Direction.OUTPUT

    led_green = digitalio.DigitalInOut(board.LED_GREEN)
    led_green.direction = digitalio.Direction.OUTPUT

    led_red = digitalio.DigitalInOut(board.LED_RED)
    led_red.direction = digitalio.Direction.OUTPUT

    led_red.value = False
    led_blue.value = False
    led_green.value = False
    pixel.fill(WHITE)
    time.sleep(1)

    led_red.value = True
    led_blue.value = True
    led_green.value = True
    pixel.fill(BLACK)
    time.sleep(4)

    while True:
    led_red.value = True
    led_blue.value = True
    led_green.value = True
    led_red.value = False
    pixel.fill(RED)
    time.sleep(0.5)

    led_red.value = True
    led_blue.value = True
    led_green.value = True
    led_green.value = False
    pixel.fill(GREEN)
    time.sleep(0.5)

    led_red.value = True
    led_blue.value = True
    led_green.value = True
    led_blue.value = False
    pixel.fill(BLUE)
    time.sleep(0.5)