Skip to content

Commit c84204a

Browse files
authored
Merge pull request #5 from clockspot/dev
PR for v1.6.0
2 parents aa3ac2c + 38145d8 commit c84204a

18 files changed

+886
-353
lines changed

README.md

+85-60
Large diffs are not rendered by default.

TODO.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
* Timer count up, ending options - maybe separate chrono and timer à la Timex?
44
* Different setting option for pushbutton (à la Timex) vs. rotary (à la microwave ovens) - external file?
5-
* Set current DST state in EEPROM so when the clock is connected to power, it can determine whether correction is needed
65
* Option to display weekdays as Sun=0 or Sun=1 (per Portuguese!)
76
* When setting times of day, make 1439 (minutes) roll over to 0 and vice versa
87
* Implement options for full date every 5 minutes
9-
* Is it possible to trip the chime *after* determining if we're in night mode or not
8+
* Is it possible to trip the chime *after* determining if we're in night shutoff or not
109
* Reenable rotary encoder with libraries with workable licenses
1110
* In display code, consider using `delayMicroseconds()` which, with its tighter resolution, may give better control over fades and dim levels
1211
* in `checkInputs()`, can all this if/else business be defined at load instead of evaluated every sample? OR is it compiled that way? maybe use `#ifdef`
1312
* in `ctrlEvt()`, could we do release/shorthold on mainSel so we can exit without making changes?
13+
* Should functions be modular in the code, and have a reserved memory location / 100 per each?
14+
* Should functions have their own options menu?
15+
* I2C display to help with setting?
16+
* I2C multicolor LED to indicate which function we're in?
17+
* Metronome function
18+
* Alarm option should be beeping patterns, including a slow wake which defeats the 2 minute delay
19+
* Signalstart should create a situation where there's time on the counter, but doesn't make sound since the rtc can do that. Other beepable actions would probably cancel that counter anyway
1420

1521
See other TODOs throughout code.

arduino-nixie/Song.h

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//Try to make the beeper play Woody's chorus part from "1612"
2+
class Song {
3+
int bpm = 80;
4+
int pin = 10; //that piezo is connected to
5+
int dur = 10000; //max note length in millis
6+
//This'll be like a proto-MIDI with events that represent sounds (notes, chords) or to stop sound.
7+
//Need to represent chords as a single event since the beeper is mono and has to cycle through the notes.
8+
//Event timing is in centibeats (e.g. in */4, quarters are 100, eights 50, sixteenths 25)
9+
//First index is a placeholder. eventtimes[] has an extra time, at which it loops back to index 1.
10+
int eventtimes[30] = {0, 0, 15, 75, 90,100,115,175,190,225,240,275,290,300,315,400,415,475,490,500,515,575,590,625,640,675,690,700,715,800};
11+
int eventtypes[29] = {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0};
12+
int curevent = 0; //Current event (index in arrays above)
13+
int cureventnote = 0; //Current note in the event (to support cycling through a chord). 1 for single note. 0 when not playing a note presently.
14+
float transpose = 1;
15+
unsigned long eventstart = 0; //0 when not playing a song presently.
16+
//we will only keep track of time since last event, thus bpm may vary due to rounding errors, but millis() rollover will only cause one event skip (I think?).
17+
public:
18+
Song(int zero) {}
19+
void play(){
20+
check(true); //the true means this starts the song
21+
} //end void play
22+
void check(bool start){ if(start || curevent){ //if song starting or playing
23+
unsigned long mils = millis();
24+
//Are we moving to a new event?
25+
int neweventdiff = (eventtimes[curevent+1]-eventtimes[curevent])*(600/bpm); //*(600/bpm) converts diff in centibeats to milliseconds
26+
if(start || mils-eventstart >= neweventdiff){
27+
if(start) eventstart = mils; //true start of event
28+
else eventstart = eventstart + neweventdiff; //set start of event relative to start of last, for better timekeeping
29+
curevent++; //Next event
30+
if(curevent+1 == 30){ curevent=1; } //Have we looped? Go back to first event //eventtimes.size
31+
}
32+
//Should we do anything about the current event?
33+
int neweventnote = (((mils-eventstart)%120)/40)+1; //a cycle of 3 every 120 ms (40ms/ea), based on current time
34+
switch(eventtypes[curevent]){ //The type of note/chord/stop
35+
case 1: //C Major chord, cycle of 523.25, 659.25, 784 Hz
36+
if(cureventnote!=neweventnote) {
37+
cureventnote = neweventnote;
38+
tone(pin, (cureventnote==1? 523.25*transpose: (cureventnote==2? 659.25*transpose: 784*transpose)), dur);
39+
}
40+
break;
41+
case 2: //F Major chord, cycle of 523.25, 698.45, 880 Hz
42+
if(cureventnote!=neweventnote) {
43+
cureventnote = neweventnote;
44+
tone(pin, (cureventnote==1? 523.25*transpose: (cureventnote==2? 698.45*transpose: 880*transpose)), dur);
45+
}
46+
break;
47+
case 0: //Stop - turn off sound, if playing
48+
if(cureventnote!=0){ cureventnote=0; noTone(pin); } break;
49+
default: break;
50+
}
51+
}} //end void check if song playing
52+
void stop(){
53+
noTone(pin);
54+
curevent = 0;
55+
cureventnote = 0;
56+
eventstart = 0;
57+
} //end void stop
58+
}; //end class Song

0 commit comments

Comments
 (0)