This section of the code is for the alarm function on a binary clock. (For the full code, please see the attached .ino file)
I suspect that the problem is related to alarmRepeats++ not resetting and remembering the accumulated value.
When alarm starts playing, (goes off) it has been designed so that the owner can snooze it with pressing of any button. When snoozed, alarm should play again after 5 minutes. This is OK. Or the owner can switch alarm off by LongPressing Alarm button. Also is working fine.
But if alarm is let to run the scheduled 10 minutes without owner input, the alarm switches itself off automatically -- then, something happens in the system and if you make a new alarm time, and the alarm time is reached, alarm starts playing and switches itself OFF immediately within 2 seconds. Doesn't even allow the alarm to run. It is as if, it remembers to switch itself off immediately. Something is broken there. It only happens if alarm is let to run 10 minutes and switch itself off. Cycling the power to the clock, fixes that.
Any idea why it is so? (How to change the code??)
if (playAlarm) {
alarmPlaying = true;
effectsPlaying = true;
effectsStage = 0;
nextEffectMillis = millis();
playAlarm = false;
}
if (alarmPlaying && effectsPlaying) {
if (millis() > nextEffectMillis) {
effectsStage++;
switch (effectsStage) {
case 1:
effectDisplayClock = false;
ledsOn();
tone(speakerPin, 1865);
nextEffectMillis += 500;
break;
case 2:
effectDisplayClock = true;
noTone(speakerPin);
nextEffectMillis += 500;
break;
case 3:
effectDisplayClock = false;
ledsOn();
tone(speakerPin, 1865);
nextEffectMillis += 1000;
break;
case 4:
noTone(speakerPin);
effectDisplayClock = true;
nextEffectMillis += 1000;
alarmRepeats++;
if (alarmRepeats < 200) { // 3 seconds per sequence; 200x2 = 600 seconds = 10 minutes.
effectsStage = 0;
}
break;
default:
alarmPlaying = false;
effectDisplayClock = false;
effectsPlaying = false;
clockMode = MODE_CLOCK;
}
}
}
arduinoware_sketch.ino (27.2 KB)