import time, machine

try: 
    if snd: snd.deinit()
except:pass 
sndon = machine.Pin(17,3); sndon.value(1)
snd = machine.PWM(machine.Pin(25,3));snd.duty(0)

wb.cls(0);wb.colors(0x01ff, 0);wb.str("Match 06",20,10,2,2)
wb.line(5,27,123,27,0xf800,2)
count = 0; level = 1
while True:
    dt = 0
    wb.colors(0xe00f, 0)
    wb.str("Count: %02d"%count, 20, 90, 2, 2)
    wb.str("Level: %02d"%level, 23, 110, 2, 2)
    t = int((time.ticks_ms()%10000)/100)  
    wb.str("%02d"%(dt),42,40,2,4)
    while wb.getkey() == 0:
    	dt = int((time.ticks_ms()%10000)/100) - t
        if dt > 20 or dt < 0: t = int((time.ticks_ms()%10000)/100)
        elif dt == 6: wb.colors(0xff, 0); wb.str("%02d"%(dt),42,40,2,4)
        else: wb.colors(0xffff, 0); wb.str("%02d"%(dt),42,40,2,4)
    if dt == 6:
        snd.freq(440);snd.duty(80);time.sleep(0.1)
        snd.freq(880);time.sleep(0.1)
        snd.freq(990);time.sleep(0.1);snd.duty(0)
        count = count+1
        if count == level: level = level+1;count = 0;
    else: 
        snd.freq(220);snd.duty(80);time.sleep(0.2);snd.duty(0)
        count = 0
    while wb.getkey()!=0: pass
          
 
