import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
import random
def choices(population, k):
# Equivalent to random.choices(population, k=3)
choices = [random.choice(population) for _ in range(k)]
return choices
from Lights import *
from Buzzer import *
from TerminalEmulator import *
red = Light(15, 'Red') # create a red light on pin 15
green = Light(13, 'Green') # create a green light on pin 13
beeper = PassiveBuzzer(14, 'Beeper') # Create a passive buzzer named beeper on 14
term = TerminalEmulator() # Create a terminal emulator with default parameters
while True:
term.clear()
for x in range(3):
red.on()
time.sleep(0.5)
red.off()
green.on()
time.sleep(0.5)
green.off()
beeper.beep()
name = term.input('Enter name:')
term.print(f'Welcome {name}!')
population = '0123456789ABCD'
choices = choices(population, k=5)
print(choices)
password = "".join(choices)
term.print(f"NEW PWD: {password}")
match = False
while not match:
userpassword = term.input('ENTER PWD:')
if userpassword == password:
match = True
else:
red.on()
term.print('Incorrect! Retry')
beeper.beep(tone=200, duration=1000)
red.off()
green.on()
term.print('Congratulations. Its a match!')
beeper.beep()
green.off()