from machine import Pin
import utime
# Define the GPIO pins for the binary counter bits
bit0 = Pin(12, Pin.OUT) #LSB
bit1 = Pin(13, Pin.OUT)
bit2 = Pin(14, Pin.OUT)
bit3 = Pin(15, Pin.OUT)
bit4 = Pin(16, Pin.OUT)
bit5 = Pin(17,Pin.OUT)
bit6 = Pin(18, Pin.OUT)
bit7 = Pin(19,Pin.OUT)
# Initialize the counter value
counter = 0 # we will count up to the max bit depth 2^8 (256 or 0-255 because 0 is used)
print(counter)
while True:
print(counter)
# Set the LED states based on the counter value
bit0.value(counter & 1)
bit1.value((counter >> 1) & 1)
bit2.value((counter >> 2) & 1)
bit3.value((counter >> 3) & 1)
bit4.value((counter >> 4) & 1)
bit5.value((counter >> 5) & 1)
bit6.value((counter >> 6) & 1)
bit7.value((counter >> 7) & 1)
# Increment the counter and wrap around when it reaches 256 (8 bits)
counter = (counter + 1) % 256
# Delay to control the counter speed
utime.sleep(1) # Adjust the sleep duration to change the counter speed