Skip to content

Commit 54cb5ef

Browse files
committed
Support setting timer to the second
1 parent 466ac51 commit 54cb5ef

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ This feature can count down (timer) or up (chrono) to 100 hours. When idle, it d
4949

5050
* To start and stop, use **Up**. While at `0`, this will start the chrono.
5151
* While the chrono is running, **Down** will briefly display a lap time.
52-
* To set the timer, hold **Select** while at `0`. It will prompt for hours/minutes first, then seconds. For convenience, it will recall the last-used time.
52+
* To set the timer, hold **Select** while at `0`. It will prompt for hours/minutes first, then seconds. For convenience, it will recall the last-used time. Once the timer is set, use **Up** to start it.
5353
* While the timer is running, **Down** will cycle through the runout options (what the timer will do when it runs out – clocks with beeper only):
5454
* 1 beep: simply stop, with a long signal (default)
5555
* 2 beeps: restart, with a short signal (makes a great interval timer!)
5656
* 3 beeps: start the chrono, with a long signal
5757
* 4 beeps: start the chrono, with a short signal
58-
* To reset to `0`, use **Down** while the timer/chrono is stopped, or hold **Select**.
58+
* To reset to `0`, hold **Select**.
5959
* When the timer signal sounds, press **Select** to silence it.
6060
* You can switch displays while the timer/chrono is running, and it will continue to run in the background. If you switch displays while it is stopped, it will reset. It will also reset if it is stopped for an hour, if it reaches 100 hours, or if power is lost.
6161

@@ -68,7 +68,6 @@ Some variations may apply, depending on your [hardware configuration](#hardware-
6868
* While the chrono is running, **Up** will briefly display a lap time.
6969
* While the timer is running, **Up** will cycle through the runout options.
7070
* To stop, use **Down**.
71-
* To reset, hold **Select**.
7271

7372
### The Alt button
7473

arduino-nixie/arduino-nixie.ino

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ byte signalSource = 0; //which function triggered the signal - fnIsTime (chime),
132132
byte signalPattern = 0; //the pattern for that source
133133
word signalRemain = 0; //alarm/timer signal timeout counter, seconds
134134
word snoozeRemain = 0; //snooze timeout counter, seconds
135-
word timerInitial = 0; //timer original countdown setting, minutes - up to 99:59 (6000 minutes)
136135
byte timerState = 0; //bit 0 is stop/run, bit 1 is down/up, bit 2 is runout repeat / short signal, bit 3 is runout chrono, bit 4 is lap display
136+
word timerInitialMins = 0; //timer original countdown setting, minutes - up to 99h 59m (5999m)
137+
byte timerInitialSecs = 0; //timer original countdown setting, seconds - up to 59s
137138
unsigned long timerTime = 0;
138139
//While timer is running, this holds a timestamp in the past (countdown) or future (countup),
139140
//and the timer continuously calculates and displays the difference between that and the current time.
@@ -338,15 +339,15 @@ void ctrlEvt(byte ctrl, byte evt){
338339
} else if(fnPg==fnDateCounter){ //month, date, direction
339340
startSet(readEEPROM(5,false),1,12,1);
340341
} else if(fnPg==fnDateSunlast || fnPg==fnDateSunnext){ //lat and long
341-
//TODO
342+
//TODO these pages will need different IDs to be told apart from fnDateCounter
342343
} else if(fnPg==fnDateWeathernow || fnDateWeathernext){ //temperature units??
343-
//TODO
344+
//TODO these pages will need different IDs to be told apart from fnDateCounter
344345
} break;
345346
case fnIsAlarm: //set mins
346347
startSet(readEEPROM(0,true),0,1439,1); break;
347348
case fnIsTimer: //set mins
348349
if(timerTime!=0 || timerState&1) { timerClear(); btnStop(); updateDisplay(); break; } //If the timer is nonzero or running, zero it out.
349-
startSet(timerInitial,0,5999,1); break; //99h 59m
350+
startSet(timerInitialMins,0,5999,1); break; //minutes
350351
//fnIsDayCount removed in favor of paginated calendar
351352
case fnIsTemp: //could do calibration here if so inclined
352353
case fnIsTubeTester:
@@ -378,7 +379,7 @@ void ctrlEvt(byte ctrl, byte evt){
378379
}
379380
} else { //mainAdjDown
380381
if(!(timerState&1)){ //stopped
381-
if(mainAdjType!=2) { //button only
382+
if(mainAdjType!=2 && false) { //button only - I think it's too easy to reset the timer like this
382383
timerClear();
383384
updateDisplay();
384385
}
@@ -493,14 +494,23 @@ void ctrlEvt(byte ctrl, byte evt){
493494
case fnIsAlarm:
494495
writeEEPROM(0,fnSetVal,true);
495496
clearSet(); break;
496-
case fnIsTimer: //timer
497-
timerInitial = fnSetVal; //minutes, up to 5999 (99m 59s)
498-
timerTime = timerInitial*60000; //set timer duration
499-
if(timerTime!=0){
500-
bitWrite(timerState,1,0); //set timer direction (bit 1) to down (0)
501-
timerStart();
497+
case fnIsTimer: //timer - depends what page we're on
498+
switch(fnSetPg){
499+
case 1: //save mins, set secs
500+
delay(300); //blink display to indicate save. See fnIsDate for details
501+
timerInitialMins = fnSetVal; //minutes, up to 5999 (99m 59s)
502+
startSet(timerInitialSecs,0,59,2); break;
503+
case 2: //save secs
504+
timerInitialSecs = fnSetVal;
505+
timerTime = (timerInitialMins*60000)+(timerInitialSecs*1000); //set timer duration
506+
if(timerTime!=0){
507+
bitWrite(timerState,1,0); //set timer direction (bit 1) to down (0)
508+
//timerStart(); //we won't automatically start, we'll let the user do that
509+
}
510+
clearSet(); break;
511+
default: break;
502512
}
503-
clearSet(); break;
513+
break;
504514
//fnIsDayCount removed in favor of paginated calendar
505515
case fnIsTemp:
506516
break;
@@ -1163,7 +1173,7 @@ void cycleTimer(){
11631173
fnSetPg = 0; fn = fnIsTimer;
11641174
} else {
11651175
if((timerState>>2)&1){ //runout repeat - keep direction, change target, keep sleep, don't change display
1166-
timerTime += timerInitial*60000; //advance timerTime by the initial setting (not per ms() to avoid drift)
1176+
timerTime += (timerInitialMins*60000)+(timerInitialSecs*1000); //set timer duration ahead by initial setting
11671177
} else { //runout clear - clear timer, change display
11681178
timerClear();
11691179
//If switched relay (radio sleep), go to time of day; otherwise go to empty timer to appear with signal
@@ -1268,12 +1278,16 @@ void updateDisplay(){
12681278
blankDisplay(4, 5, false);
12691279
byte fnOptCurLoc = (fn>=fnOpts? optsLoc[fn-fnOpts]: 0); //current option index loc, to tell what's being set
12701280
if(fnSetValMax==1439) { //Time of day (0-1439 mins, 0:00–23:59): show hrs/mins
1271-
editDisplay(fnSetVal/60, 0, 1, readEEPROM(19,false), false); //hours with leading zero
1281+
editDisplay(fnSetVal/60, 0, 1, readEEPROM(19,false), false); //hours with leading zero per options
12721282
editDisplay(fnSetVal%60, 2, 3, true, false);
1273-
} else if(fnSetValMax==5999) { //Timer duration (0-5999 mins, up to 99:59): show hrs/mins w/minimal leading
1274-
if(fnSetVal>=60) editDisplay(fnSetVal/60, 0, 1, false, false); else blankDisplay(0,1,false); //hour only if present, else blank
1275-
editDisplay(fnSetVal%60, 2, 3, (fnSetVal>=60?true:false), false); //leading zero only if hour present
1276-
editDisplay(0,4,5,true,false); //placeholder seconds
1283+
} else if(fnSetValMax==5999) { //Timer duration mins (0-5999 mins, up to 99:59): show hrs/mins w/regular leading
1284+
editDisplay(fnSetVal/60, 0, 1, readEEPROM(19,false), false); //hours with leading zero per options
1285+
editDisplay(fnSetVal%60, 2, 3, true, false); //minutes with leading zero always
1286+
} else if(fnSetValMax==59) { //Timer duration secs: show with leading
1287+
//If 6 tubes (0-5), display on 4-5
1288+
//If 4 tubes (0-3), dislpay on 2-3
1289+
blankDisplay(0, 3, false);
1290+
editDisplay(fnSetVal, (displaySize>4? 4: 2), (displaySize>4? 5: 3), true, false);
12771291
} else if(fnSetValMax==88) { //A piezo pitch. Play a short demo beep.
12781292
editDisplay(fnSetVal, 0, 3, false, false);
12791293
if(piezoPin>=0) { noTone(piezoPin); tone(piezoPin, getHz(fnSetVal), 100); } //Can't use signalStart since we need to specify pitch directly

0 commit comments

Comments
 (0)