# blink_all.py

# Demo for the Cytron Maker Pi Pico with Raspberry Pi Pico installed.
# Blink all the available LEDs.

import board
import time

# load the CircuitPython GPIO support
from digitalio import DigitalInOut, Direction, Pull

# load the low-level CircuitPython NeoPixel support
from neopixel_write import neopixel_write

#---------------------------------------------------------------
# list of all the blue indicator LED pins in pin order
indicator_pins = [
    # left side, top to bottom
    board.GP0, board.GP1,
    board.GP2, board.GP3, board.GP4, board.GP5,
    board.GP6, board.GP7, board.GP8, board.GP9,
    board.GP10, board.GP11, board.GP12, board.GP13,
    board.GP14, board.GP15,

    # right side, bottom to top
    board.GP16, board.GP17,
    board.GP18, board.GP19, board.GP20, board.GP21,
    board.GP22,
    board.GP26, board.GP27,
    # board.GP28, this indicator LED is shared with the NeoPixel
    ]

# the NeoPixel in on GP28
neopixel = DigitalInOut(board.GP28)
neopixel.direction = Direction.OUTPUT

# the LED on board the Pico is GP25
Pico_LED_pin = board.LED

#---------------------------------------------------------------
# Create a list of output devices to flash in order.
outputs = [DigitalInOut(pin) for pin in indicator_pins]
outputs.append(DigitalInOut(Pico_LED_pin))

# and set them all to output
for io in outputs:
    io.direction = Direction.OUTPUT

#---------------------------------------------------------------

# run forever
while True:
    # sequence the LEDs on and off
    print("strobing LEDs")
    for io in outputs:
        io.value = True
        time.sleep(0.05)
        io.value = False

    # cycle through colors on the NeoPixel: green, red, blue, off
    for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 0, 0)):
        print("neopixel color:", color)
        neopixel_write(neopixel, bytearray(color))
        time.sleep(0.25)
