#
# Original: https://wokwi.com/projects/393849360067450881
#
import machine
import time
from utime import sleep
LED_COUNT = 9
LED_GPIO_START = 7
def Chaser(pins):
delay = 0.2
for pin in pins:
pin.toggle()
time.sleep(delay)
pin.toggle()
for pin in reversed(pins[0:len(pins) - 1]):
pin.toggle()
time.sleep(delay)
pin.toggle()
def ToggleBits(pins, code):
pinId = 0
while code > 0:
if code & 1:
pins[pinId].toggle()
code = code >> 1
pinId = pinId + 1
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
outputPins = []
for outputId in range(0, LED_COUNT):
pin = machine.Pin(LED_GPIO_START + outputId, machine.Pin.OUT)
outputPins.append(machine.Pin(LED_GPIO_START + outputId, machine.Pin.OUT))
Chaser(outputPins)
binaryCode = 12
if binaryCode == 0:
for pin in outputPins:
pin.off()
else:
ToggleBits(outputPins, binaryCode)
# for outputId in range(0, LED_COUNT):
# outputPins[outputId].toggle()
# time.sleep(0.2)
# outputPins[outputId].toggle()
# for outputId in range(LED_COUNT - 2, -1, -1):
# outputPins[outputId].toggle()
# time.sleep(0.2)
# outputPins[outputId].toggle()