' demo use of the keypad scan
' a complete help of Annex32 can be found here
' https://cicciocb.com/annex32help/V1.442/
I2C.SETUP 21, 22
pin.mode 2, output
TM1637.SETUP 15, 16, 100
TM1637.PRINT "00:00"
TM1637.PRINT MID$(RTC.TIME$,1,5)
tempo = 0
tempoStr$ = ""
display$ = ""
dim rows(4) = 26, 25, 33, 32
dim cols(4) = 35, 34, 39, 36
dim sym$(16) = "1", "2", "3", "A", "4", "5", "6", "B", "7", "8", "9", "C", "*", "0", "#", "D"
' set the pins as input and output
for z = 0 to 3
pin.mode rows(z), output
pin.mode cols(z), input, pulldown
pin(rows(z)) = 0
next z
maxscroll.setup 8, 21
maxscroll.print "Press Keys"
maxscroll.show 63, 5
k$ = ""
Kp$ = ""
do
scan k$
if (k$ <> kp$) and (k$ <> "") then
print k$
if k$ = "A" then
tempo = 70
rodar
end if
if k$ = "1" then
tempoStr$ = tempoStr$ + "1"
end if
if k$ = "2" then
tempoStr$ = tempoStr$ + "2"
end if
if k$ = "3" then
tempoStr$ = tempoStr$ + "3"
end if
if k$ = "4" then
tempoStr$ = tempoStr$ + "4"
end if
if k$ = "5" then
tempoStr$ = tempoStr$ + "5"
end if
if k$ = "6" then
tempoStr$ = tempoStr$ + "6"
end if
if k$ = "7" then
tempoStr$ = tempoStr$ + "7"
end if
if k$ = "8" then
tempoStr$ = tempoStr$ + "8"
end if
if k$ = "9" then
tempoStr$ = tempoStr$ + "9"
end if
if k$ = "0" then
tempoStr$ = tempoStr$ + "0"
end if
if k$ = "*" then
tempoStr$ = ""
end if
if k$ = "#" then
rodarStr
end if
formatarDisplay
TM1637.PRINT display$
if tempoStr$ = "" then
pause 1000
TM1637.PRINT MID$(RTC.TIME$,1,5)
end if
end if
kp$ = k$
'pause 100
loop
sub scan(key$)
local r, c, l, code
code = -1
for r = 0 to 3
pin(rows(r)) = 1
for c = 0 to 3
l = pin(cols(c))
if (l=1) then
code = r*4 + c
exit for
end if
next c
pin(rows(r)) = 0
if (code <> -1) then exit for
next r
if (code <> -1) then key$ = sym$(code) else key$ = ""
end sub
sub formatarDisplay
quantideZeros = 4 - LEN(tempoStr$)
if quantideZeros = 4 then
display$ = "00:00"
end if
if quantideZeros = 3 then
display$ = "00:0"+tempoStr$
end if
if quantideZeros = 2 then
display$ = "00:"+tempoStr$
end if
if quantideZeros = 1 then
display$ = "0"+MID$(tempoStr$,1,1)+":"+MID$(tempoStr$,2,2)
end if
if quantideZeros = 0 then
display$ = MID$(tempoStr$,1,2)+":"+MID$(tempoStr$,3,2)
end if
end sub
sub rodarStr
if LEN(tempoStr$) = 4 then
tempo = VAL(MID$(tempoStr$,1,2)) * 60
tempo = tempo + VAL(MID$(tempoStr$,3,2))
end if
if LEN(tempoStr$) = 3 then
tempo = VAL(MID$(tempoStr$,1,1)) * 60
tempo = tempo + VAL(MID$(tempoStr$,2,2))
end if
if LEN(tempoStr$) = 2 or LEN(tempoStr$) = 1 then
tempo = VAL(tempoStr$)
end if
rodar
end sub
sub rodar
meuled = 1
while tempo > 0
minutos = FIX(tempo/60)
segundos = ((tempo/60) - minutos)*60
minutosStr$ = str$(minutos)
segundosStr$ = str$(segundos)
if LEN(minutosStr$) = 1 then
minutosStr$ = "0" + minutosStr$
end if
if LEN(segundosStr$) = 1 then
segundosStr$ = "0" + segundosStr$
end if
TM1637.PRINT minutosStr$+":"+segundosStr$
tempo = tempo - 1
if meuled = 1 then
pin(2) = 1
meuled = 0
else
pin(2) = 0
meuled = 1
end if
pause 500
wend
tempoStr$ = ""
pin(2) = 0
PRINT "Terminou a pipoquinha"
FOR i=1 to 5
TM1637.PRINT "00:00", 1
pause 500
TM1637.PRINT "00:00", 7
pause 500
NEXT i
end sub