-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.spin
354 lines (330 loc) · 7.79 KB
/
timer.spin
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
CON
_clkmode=xtal1+pll16x
_xinfreq=5_000_000
run=0
mode=1
reset=2
menu=3
'mode options
sw=4 'stop watch
cd=5 'countdown
obj
Rtc : "DS1302"
SC : "Screen"
SN : "Simple_Numbers"
TC : "trackBallEx"
var
long hour
long minute
long second
long lastSec
long curMode
long isFaded
long tickCounter 'to be used to trigger fadeout
long isSetupMode 'seperate mode for countdown setup.
pub main | curPOS, runSw,runCd,displayTimeDelay
repeat until TC.isPressed == false
TC.Run
init
isFaded:=false
lastSec:=0
curPOS:=0
runSw:=false
runCd:=false
curMode:=sw
isSetupMode:=false
Rtc.init(17,16,18)
displayTimeDelay:=0
DrawTime
repeat
if displayTimeDelay++ > 150
displayTimeDelay:=0
DrawTime
TC.Run
if tickCounter == 15 and isFaded == false
isFaded:=true
SC.FadeOut
if runSw ==true
swRun
if runCd ==true
if cdRun == 1
runCd:=false
if TC.isRight == true
SC.Click
clearSetMenu
case curPOS
run:
SC.DrawRec(65,120,31,108,$F8,$00)
SC.DrawRec(23,120,00,108,$00,$00)
curPOS:=mode
mode:
SC.DrawRec(65,120,31,108,$00,$00)
SC.DrawRec(115,120,75,108,$F8,$00)
curPOS:=reset
reset:
SC.DrawRec(115,120,75,108,$00,$00)
SC.DrawRec(155,120,124,108,$F8,$00)
curPOS:=menu
if TC.isLeft == true
SC.Click
clearSetMenu
case curPOS
mode:
SC.DrawRec(23,120,00,108,$F8,$00)
SC.DrawRec(65,120,31,108,$00,$00)
curPOS:=run
reset:
SC.DrawRec(65,120,31,108,$F8,$00)
SC.DrawRec(115,120,75,108,$00,$00)
curPOS:=mode
menu:
SC.DrawRec(115,120,75,108,$F8,$00)
SC.DrawRec(155,120,124,108,$00,$00)
curPOS:=reset
if TC.isUp == true
SC.Click
'ensure we are in the right mode
if curMode == cd
isSetupMode:=true
SC.DrawRec(95,85,65,100,$F8,$00)
case curPOS
mode:SC.DrawRec(65,120,31,108,$00,$00)
reset: SC.DrawRec(115,120,75,108,$00,$00)
menu: SC.DrawRec(155,120,124,108,$00,$00)
run: SC.DrawRec(23,120,00,108,$00,$00)
if TC.isPressed == true
if isFaded == true
tickCounter:=0
isFaded:=false
SC.FadeIn
DrawTimer
else
if isSetupMode == true
SetTimer
curPOS:=run
isSetupMode:=false
else
case curPOS
run:
if curMode ==sw
if runSw ==true
runSw:=false
tickCounter:=0
else
runSw:=true
else
if runCd == true
runCd:=false
tickCounter:=0
else
runCd:=true
mode:
runSw:=false
runCd:=false
curPOS:=run
if curMode == sw
'to countdown
hour:=1
minute:=0
second:=0
CDInit
curMode:=cd
else
init
curMode:=sw
reset:
if curMode == sw
init
else
hour:=1
minute:=0
second:=0
CDInit
curPOS:=run
menu:
return
repeat until TC.isPressed==false
TC.Run
pri clearSetMenu
if curMode == cd
SC.DrawRec(95,85,65,100,$00,$00)
isSetupMode:=false
pri init
hour:=0
minute:=0
second:=0
SC.Init
SC.Clear
SC.FontSize(0)
SC.TxtColor($FF,$E0)
SC.Position(7,4)
SC.FontSize(2)
SC.Print(SN.decx(hour,2))
SC.Print(string(":"))
SC.Print(SN.decx(minute,2))
SC.Print(string(":"))
SC.Print(SN.decx(second,2))
'Draw menu items
SC.FontSize(1)
SC.Position(0,7)
SC.Print(string("Stopwatch"))
SC.Position(14,0)
SC.Print(string("Run Mode Reset Menu"))
SC.DrawRec(23,120,00,108,$F8,$00)
'Countdown init
pri CDInit
SC.Clear
SC.FontSize(0)
SC.Position(7,4)
SC.FontSize(2)
SC.Print(SN.decx(hour,2))
SC.Print(string(":"))
SC.Print(SN.decx(minute,2))
SC.Print(string(":"))
SC.Print(SN.decx(second,2))
'Draw menu items
SC.FontSize(1)
SC.Position(0,7)
SC.Print(string("Count Down"))
SC.Position(14,0)
SC.Print(string("Run Mode Reset Menu"))
SC.Position(11,10)
SC.Print(string("Set"))
SC.DrawRec(23,120,00,108,$F8,$00)
pri swRun| curHour,curMinute,curSecond
Rtc.readTime(@curHour,@curMinute,@curSecond)
if curSecond <> lastSec
second:=second+1
if second > 59
second:=0
minute:=minute+1
if minute > 59
minute:=0
hour:=hour+1
if curSecond <> lastSec
if isFaded == false
UpdateDisplay
tickCounter:=tickCounter+1
lastSec:=curSecond
pri cdRun| curHour,curMinute,curSecond
Rtc.readTime(@curHour,@curMinute,@curSecond)
if curSecond <> lastSec
second:=second-1
if second ==0 and hour == 0 and minute==0
UpdateDisplay
SC.Beep
return 1
if second < 0
second:=59
minute:=minute-1
if minute < 0
minute:=59
hour:=hour-1
if curSecond <> lastSec
if isFaded == false
UpdateDisplay
tickCounter:=tickCounter+1
lastSec:=curSecond
pri UpdateDisplay
SC.FontSize(0)
SC.Position(7,4)
SC.FontSize(2)
SC.Print(SN.decx(hour,2))
SC.Print(string(":"))
SC.Print(SN.decx(minute,2))
SC.Print(string(":"))
SC.Print(SN.decx(second,2))
pri SetTimer| canExit,setPos
repeat until TC.isPressed == false
TC.Run
'do nothing
canExit:=false
setPos:=0
SC.Clear
SC.FontSize(0)
SC.Position(7,4)
SC.FontSize(2)
SC.Print(SN.decx(hour,2))
SC.Print(string(":"))
SC.Print(SN.decx(minute,2))
SC.Print(string(":"))
SC.Print(SN.decx(second,2))
SC.DrawTri($28,$5A,$18,$66,$38,$66,$F8,$00)'hour
repeat until canExit==true
TC.Run
if TC.isRight==true
case setPos
0:
SC.DrawTri($28,$5A,$18,$66,$38,$66,$00,$00)'hour
SC.DrawTri($50,$5A,$40,$66,$60,$66,$F8,$00)'minute
setPos:=1
1:
SC.DrawTri($50,$5A,$40,$66,$60,$66,$00,$00)'minute
SC.DrawTri($7D,$5A,$6D,$66,$8D,$66,$F8,$00)'second
setPos:=2
if TC.isLeft == true
case setPos
2:
SC.DrawTri($50,$5A,$40,$66,$60,$66,$F8,$00)'minute
SC.DrawTri($7D,$5A,$6D,$66,$8D,$66,$00,$00)'second
setPos:=1
1:
SC.DrawTri($28,$5A,$18,$66,$38,$66,$F8,$00)'hour
SC.DrawTri($50,$5A,$40,$66,$60,$66,$00,$00)'minute
setPos:=0
if TC.isUp == true
case setPos
0:
hour:=hour+1
if hour > 24
hour:=0
1:
minute:=minute+1
if minute > 59
minute:=0
2:
second:=second+1
if second > 59
second:=0
DrawTimer
if TC.isDown == true
case setPos
0:
hour:=hour-1
if hour < 0
hour:=59
1:
minute:=minute-1
if minute < 0
minute:=59
2:
second:=second-1
if second < 0
second:=59
DrawTimer
if TC.isPressed == true
repeat until TC.isPressed == false
TC.Run
'do nothing
canExit:=true
'exit loop
cdInit
pri DrawTimer
SC.FontSize(0)
' SC.TxtColor($FF,$E0)
SC.Position(7,4)
SC.FontSize(2)
SC.Print(SN.decx(hour,2))
SC.Print(string(":"))
SC.Print(SN.decx(minute,2))
SC.Print(string(":"))
SC.Print(SN.decx(second,2))
pri DrawTime|curHour,curMin,curSec
Rtc.readTime(@curHour,@curMin,@curSec)
SC.FontSize(0)
SC.Position(0,0)
SC.Print(SN.Decx(curHour,2))
SC.Print(string(":"))
SC.Print(SN.Decx(curMin,2))
' SC.Print(string(":"))
' SC.Print(SN.Dec(curSec))