from machine import Pin
import utime
# Define pin numbers for LED bar
LED_PINS = [10, 11, 12, 13, 14, 15, 16, 17]
# Initialize LED pins
leds = [Pin(pin, Pin.OUT) for pin in LED_PINS]
def hamming_distance(char1, char2):
char1_ascii = ord(char1)
char2_ascii = ord(char2)
xor_result = char1_ascii ^ char2_ascii
distance = 0
while xor_result:
distance += xor_result & 1
xor_result >>= 1
return distance
str1 = "hello"
str2 = "world"
max_distance = max(len(str1), len(str2))
for i in range(max_distance):
if i < len(str1) and i < len(str2):
distance = hamming_distance(str1[i], str2[i])
for j, led_pin in enumerate(LED_PINS):
if j < distance:
leds[j].on()
else:
leds[j].off()
else:
for led in leds:
led.off()
utime.sleep(1)