from machine import Pin, PWM
from time import sleep
import random as rd
red = Pin(1,Pin.OUT)
green = Pin(2,Pin.OUT)
blue = Pin(5,Pin.OUT)
yellow = Pin(7,Pin.OUT)
pir = Pin(28, Pin.IN)
buz = PWM(26)
def margot(args):
aleatorio = rd.randint(1, 10)
print("Número gerado", aleatorio)
resp = int(input('Escolha um numero entre 1 e 10: '))
if resp == aleatorio:
buz.freq(123)
buz.duty_u16(100)
red.on()
sleep(2)
buz.freq(246)
buz.duty_u16(100)
green.on()
sleep(2)
buz.freq(369)
buz.duty_u16(100)
blue.on()
sleep(2)
buz.freq(492)
buz.duty_u16(100)
yellow.on()
sleep(2)
else:
print('os numeros nao foram iguais, que pena, tente novamente')
pir.irq(handler=margot,trigger=Pin.IRQ_RISING)
while True:
red.off()
yellow.off()
blue.off()
green.off()
buz.duty_u16(0)
sleep(1)