import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
from machine import Pin
import utime
LED_BAR_PINS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
NUM_LEDS = len(LED_BAR_PINS)
led_bar = [Pin(pin, Pin.OUT) for pin in LED_BAR_PINS]
def hamming_distance(char1, char2):
binary_str1 = '{0:08b}'.format(ord(char1))
binary_str2 = '{0:08b}'.format(ord(char2))
distance = sum(bit1 != bit2 for bit1, bit2 in zip(binary_str1, binary_str2))
print(distance)
return distance
def light_up_led_bar(hamming_dist):
for i in range(NUM_LEDS):
if i < hamming_dist:
led_bar[i].value(1)
else:
led_bar[i].value(0)
string1 = "Narayan"
string2 = "Nidumol"
for char1, char2 in zip(string1, string2):
hamming_dist = hamming_distance(char1, char2)
light_up_led_bar(hamming_dist)
utime.sleep(1)
for led in led_bar:
led.value(0)