import utime
import machine
utime.sleep(0.1) # Wait for USB to become ready
# print("Hello, Pi Pico W!")
# Hardware Setup
# Onboard LED (GP25 on Pico / Pico W)
led = machine.Pin("LED", machine.Pin.OUT)
# 8 LEDs connected to GPIO0–7
leds_list = [machine.Pin(i, machine.Pin.OUT) for i in range(8)] # GPIO0–7
# Variables
# state of the 8 LEDs are stored in leds as a single byte
leds = 0b00000000 # initialize
# Functions
def Led_Driver():
'''
Reads led state and lit them accordingly
'''
global leds, leds_list
mask = 0b00000001
for i in range(0, 8):
leds_list[i].value(leds & mask<<i)
utime.sleep(0.5)
# Main
# turn on led 2 and led 3
leds = 0b00001100
Led_Driver()
# turn on led 5
leds |= (1<<5)
Led_Driver()
# turn off led 2
leds &= ~(1 << 2)
Led_Driver()
# toggle led 0
leds ^= (1<<0)
Led_Driver()
# toggle led 0
leds ^= (1<<0)
Led_Driver()
# toggle all LEDs
leds = 0b00000000
while True:
leds ^= 0b1111111 # toggle all 8
Led_Driver()