# Modules
from machine import Pin
from time import sleep
# Declaring LED Pins
led_pins = [19, 18, 5, 17]
leds = [Pin(i, Pin.OUT, value = 0) for i in led_pins]
# Declaring registers sequence and an index variable
register = [0, 0, 0, 0]
dat_seq = [1, 0, 1, 1, 0, 1, 0, 1, 0, 1]
dat_ind = 0
# A function that shifts the register's bits to the right
def shift_right(reg, new_bit):
for i in range(len(reg) - 1, 0, -1):
reg[i] = reg[i - 1]
reg[0] = new_bit
# A function that visualizes the register into LEDs
def write_register_to_leds():
for i, led in enumerate(leds):
led.value(register[i])
# Main loop
while True:
# Assigning a new value for new_bit
new_bit = dat_seq[dat_ind]
# Shifting the register by the new bit
shift_right(register, new_bit)
# Displaying the register with the new bit
print(f"Register: {register}, New Bit: {new_bit}")
# Visualising the register with LEDs
write_register_to_leds()
# Increasing index by one
dat_ind += 1
# If statement that makes sure that no IndexError will happen
if dat_ind >= len(dat_seq):
dat_ind = 0
sleep(1) # 1 second delay