-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenius.lua
101 lines (101 loc) · 2.22 KB
/
genius.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local red=3
local verde = 6
local sw = 1
local sw2 = 2
cont=1
sec=""
compsec=""
cont2=0
lasttime=0
math.randomseed(tmr.now())
gpio.mode(verde,gpio.OUTPUT)
gpio.mode(red,gpio.OUTPUT)
gpio.mode(sw,gpio.INT,gpio.PULLUP)
gpio.mode(sw2,gpio.INT,gpio.PULLUP)
gpio.write(red,gpio.LOW)
gpio.write(verde,gpio.LOW)
local cbchave , restabelece
local mytimer = tmr.create()
local mytimer2 = tmr.create()
function ascred (level,time)
if time >= lasttime + 300000 then
lasttime = time
if cont2 < 7 then
if cont2 == 0 then
criasec()
else
gpio.write(red,gpio.HIGH)
tmr.delay(500000)
gpio.write(red,gpio.LOW)
compsec=compsec.."1"
cont2=cont2+1
gpio.trig(sw)
mytimer:alarm (500,tmr.ALARM_SINGLE,restabelece)
if cont2 == 6 then
verifica(sec,compsec)
cont2=7
end
end
else
gpio.write(verde,gpio.LOW)
gpio.write(red,gpio.LOW)
end
end
end
function restabelece()
gpio.trig(sw,"down",ascred)
end
function ascverde (level,time)
if time >= lasttime + 300000 then
lasttime = time
if cont2 < 7 then
gpio.write(verde,gpio.HIGH)
tmr.delay(500000)
gpio.write(verde,gpio.LOW)
compsec=compsec.."0"
cont2=cont2+1
gpio.trig(sw2)
mytimer2:alarm (500,tmr.ALARM_SINGLE,restabelece2)
if cont2 == 6 then
verifica(sec,compsec)
cont2=7
end
else
gpio.write(verde,gpio.LOW)
gpio.write(red,gpio.LOW)
end
end
end
function restabelece2()
gpio.trig(sw2,"down",ascverde)
end
function verifica (sec,compsec)
tmr.delay(500000)
if sec == compsec then
gpio.write(verde,gpio.HIGH)
else
gpio.write(red,gpio.HIGH)
end
end
function criasec ()
tmr.delay(500000)
while cont <= 5 do
num=math.random(0,1)
if num == 1 then
gpio.write(red,gpio.HIGH)
tmr.delay(500000)
gpio.write(red,gpio.LOW)
sec=sec..tostring(num)
else
gpio.write(verde,gpio.HIGH)
tmr.delay(500000)
gpio.write(verde,gpio.LOW)
sec=sec..tostring(num)
end
cont=cont+1
tmr.delay(500000)
cont2=1
end
end
gpio.trig(sw,"down",ascred)
gpio.trig(sw2,"down",ascverde)