From 204f2bcf7728a87d59dfa4f8c65bd7536e3eae41 Mon Sep 17 00:00:00 2001 From: Luke McKenzie Date: Sat, 27 Oct 2018 16:27:41 -0500 Subject: [PATCH] Add TODO file; remove tests for encoder, v8a, v8b, and weekday; README tweaks --- TODO.md | 11 ++ encoder_test/encoder_test.ino | 213 ---------------------------------- sixtube_lm/sixtube_lm.ino | 20 ++-- v8a_mod_test/v8a_mod_test.ino | 129 -------------------- v8b_mod_test/v8b_mod_test.ino | 129 -------------------- v8c_mod_test/v8c_mod_test.ino | 2 +- weekday_test/weekday_test.ino | 111 ------------------ 7 files changed, 19 insertions(+), 596 deletions(-) create mode 100644 TODO.md delete mode 100644 encoder_test/encoder_test.ino delete mode 100644 v8a_mod_test/v8a_mod_test.ino delete mode 100644 v8b_mod_test/v8b_mod_test.ino delete mode 100644 weekday_test/weekday_test.ino diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..1283cac --- /dev/null +++ b/TODO.md @@ -0,0 +1,11 @@ +# To-dos + +* Option to display weekdays as Sun=0 or Sun=1 (per Portuguese!) +* Implement options for full date every 5 minutes +* Is it possible to trip the chime *after* determining if we're in night mode or not +* Reenable rotary encoder with libraries with workable licenses +* In display code, consider using `delayMicroseconds()` which, with its tighter resolution, may give better control over fades and dim levels +* 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` +* in `ctrlEvt()`, could we do release/shorthold on mainSel so we can exit without making changes? + +See other TODOs throughout code. \ No newline at end of file diff --git a/encoder_test/encoder_test.ino b/encoder_test/encoder_test.ino deleted file mode 100644 index 9878c3b..0000000 --- a/encoder_test/encoder_test.ino +++ /dev/null @@ -1,213 +0,0 @@ -// #include -#include -#include -RTC_DS1307 rtc; -#include -#include - -AdaEncoder mainRot = AdaEncoder('a',A1,A0); - -word val = 500; - -// Display formatting -byte displayNext[6] = {15,15,15,15,15,15}; //Internal representation of display. Blank to start. Change this to change tubes. - -// Hardware outputs -//This clock is 2x3 multiplexed: two tubes powered at a time. -//The anode channel determines which two tubes are powered, -//and the two SN74141 cathode driver chips determine which digits are lit. -//4 pins out to each SN74141, representing a binary number with values [1,2,4,8] -byte binOutA[4] = {2,3,4,5}; -byte binOutB[4] = {6,7,8,9}; -//3 pins out to anode channel switches -byte anodes[3] = {11,12,13}; -void initOutputs(); -float fadeMax = 5.0f; -float fadeStep = 1.0f; -int displayLast[6]={11,11,11,11,11,11}; //What is currently being displayed. We slowly fade away from this. -float displayNextFade[6]={0.0f,0.0f,0.0f,0.0f,0.0f,0.0f}; //Fading in displayNext values -float displayLastFade[6]={8.0f,8.0f,8.0f,8.0f,8.0f,8.0f}; //Fading out displayLast values -unsigned long setStartLast = 0; //to control flashing -void cycleDisplay(); //Run on every "clock cycle" to keep multiplexing going. -void setCathodes(byte decValA, byte decValB); -void decToBin(bool binVal[], byte i); - - -////////// Main code control ////////// - -void setup(){ - Serial.begin(57600); - Wire.begin(); - rtc.begin(); - if(!rtc.isrunning()) rtc.adjust(DateTime(2017,1,1,0,0,0)); //TODO test - initOutputs(); - initInputs(); - - //mainRot.write(rotCount); - - editDisplay(val,0,3,false); - - //initEEPROM(readInput(mainSel)==LOW); - //debugEEPROM(); - //setCaches(); -} - -void loop(){ - //Things done every "clock cycle" - checkRTC(); //if clock has ticked, decrement timer if running, and updateDisplay - checkInputs(); //if inputs have changed, this will do things + updateDisplay as needed - - //long mainRotNew = mainRot.read(); - - - //doSetHold(); //if inputs have been held, this will do more things + updateDisplay as needed - cycleDisplay(); //keeps the display hardware multiplexing cycle going -} - - -////////// Control inputs ////////// -void initInputs(){ - //TODO are there no "loose" pins left floating after this? per https://electronics.stackexchange.com/q/37696/151805 - //Buttons - //pinMode(A0, INPUT_PULLUP); - //pinMode(A1, INPUT_PULLUP); - pinMode(A2, INPUT_PULLUP); - pinMode(A3, INPUT_PULLUP); - pinMode(A6, INPUT); digitalWrite(A6, HIGH); - pinMode(A7, INPUT); digitalWrite(A7, HIGH); - - //Encoders - //If using rotary encoders, capture their initial state - //if(mainAdjType==2) checkRot(mainAdjA,mainAdjB,mainRotLast,false); - //if(altAdjType==2) checkRot(altAdjA,altAdjB,altRotLast,false); -} - -void checkInputs(){ - AdaEncoder *thisEncoder=NULL; - thisEncoder = AdaEncoder::genie(); - if(thisEncoder!=NULL) { - int8_t clicks = thisEncoder->query(); - Serial.print(thisEncoder->getID()); Serial.print(':'); Serial.println(clicks); - //editDisplay(clicks,4,5,false); - //thisEncoder->getID(); - val += clicks; - editDisplay(val,0,3,false); - } -} - -////////// Clock ticking and timed event triggering ////////// -unsigned long rtcPollLast = 0; //maybe don't poll the RTC every loop? would that be good? -byte rtcSecLast = 61; -void checkRTC(){ - //Checks for new time-of-day second; decrements timer; checks for timed events; - //updates display for running time or date. - if(rtcPollLast 0015) - word place; - for(byte i=0; i<=posEnd-posStart; i++){ - //place = int(pow(10,i)); TODO PROBLEM: int(pow(10,2))==99 and int(pow(10,3))==999. Why?????????? - switch(i){ - case 0: place=1; break; - case 1: place=10; break; - case 2: place=100; break; - case 3: place=1000; break; - default: break; - } - displayNext[posEnd-i] = (i==0&&n==0 ? 0 : (n>=place ? (n/place)%10 : (leadingZeros?0:15))); - } -} //end editDisplay() -void blankDisplay(byte posStart, byte posEnd){ - for(byte i=posStart; i<=posEnd; i++) displayNext[i]=15; -} //end blankDisplay(); - - -////////// Hardware outputs ////////// -void initOutputs() { - for(byte i=0; i<4; i++) { pinMode(binOutA[i],OUTPUT); pinMode(binOutB[i],OUTPUT); } - for(byte i=0; i<3; i++) { pinMode(anodes[i],OUTPUT); } - pinMode(10, OUTPUT); //Alarm signal pin -} - -void cycleDisplay(){ - bool dim = 0;//(opts[2]>0?true:false); //Under normal circumstances, dim constantly if the time is right - // if(fnSet>0) { //but if we're setting, dim for every other 500ms since we started setting - // if(setStartLast==0) setStartLast = millis(); - // dim = 1-(((millis()-setStartLast)/500)%2); - // } else { - // if(setStartLast>0) setStartLast=0; - // } - - //Anode channel 0: tubes #2 (min x10) and #5 (sec x1) - setCathodes(displayLast[2],displayLast[5]); //Via d2b decoder chip, set cathodes to old digits - digitalWrite(anodes[0], HIGH); //Turn on tubes - delay(displayLastFade[0]/(dim?4:1)); //Display for fade-out cycles - setCathodes(displayNext[2],displayNext[5]); //Switch cathodes to new digits - delay(displayNextFade[0]/(dim?4:1)); //Display for fade-in cycles - digitalWrite(anodes[0], LOW); //Turn off tubes - - if(dim) delay(fadeMax/1.5); - - //Anode channel 1: tubes #4 (sec x10) and #1 (hour x1) - setCathodes(displayLast[4],displayLast[1]); - digitalWrite(anodes[1], HIGH); - delay(displayLastFade[1]/(dim?4:1)); - setCathodes(displayNext[4],displayNext[1]); - delay(displayNextFade[1]/(dim?4:1)); - digitalWrite(anodes[1], LOW); - - if(dim) delay(fadeMax/1.5); - - //Anode channel 2: tubes #0 (hour x10) and #3 (min x1) - setCathodes(displayLast[0],displayLast[3]); - digitalWrite(anodes[2], HIGH); - delay(displayLastFade[2]/(dim?4:1)); - setCathodes(displayNext[0],displayNext[3]); - delay(displayNextFade[2]/(dim?4:1)); - digitalWrite(anodes[2], LOW); - - if(dim) delay(fadeMax*0.75); - - // Loop thru and update all the arrays, and fades. - for( byte i = 0 ; i < 6 ; i ++ ) { - if( displayNext[i] != displayLast[i] ) { - displayNextFade[i] += fadeStep; - displayLastFade[i] -= fadeStep; - - if( displayNextFade[i] >= fadeMax ){ - displayNextFade[i] = 0.0f; - displayLastFade[i] = fadeMax; - displayLast[i] = displayNext[i]; - } - } - } -} //end cycleDisplay() - -void setCathodes(byte decValA, byte decValB){ - bool binVal[4]; //4-bit binary number with values [1,2,4,8] - decToBin(binVal,decValA); //have binary value of decVal set into binVal - for(byte i=0; i<4; i++) digitalWrite(binOutA[i],binVal[i]); //set bin inputs of SN74141 - decToBin(binVal,decValB); - for(byte i=0; i<4; i++) digitalWrite(binOutB[i],binVal[i]); //set bin inputs of SN74141 -} //end setCathodes() - -void decToBin(bool binVal[], byte i){ - //binVal is a reference (modify in place) of a binary number bool[4] with values [1,2,4,8] - if(i<0 || i>15) i=15; //default value, turns tubes off - binVal[3] = int(i/8)%2; - binVal[2] = int(i/4)%2; - binVal[1] = int(i/2)%2; - binVal[0] = i%2; -} //end decToBin() \ No newline at end of file diff --git a/sixtube_lm/sixtube_lm.ino b/sixtube_lm/sixtube_lm.ino index b123093..d58a020 100644 --- a/sixtube_lm/sixtube_lm.ino +++ b/sixtube_lm/sixtube_lm.ino @@ -1,19 +1,13 @@ -// Digital clock code for the Arduino Nano in RLB Designs' Universal Nixie Driver Board v5.0 +// Digital clock code for the Arduino Nano in RLB Designs' Universal Nixie Driver Board // featuring timekeeping by DS3231 RTC, driving up to six digits multiplexed 3x2 via two SN74141 driver chips -// An alternate sketch by Luke McKenzie (luke@theclockspot.com) - https://github.com/clockspot/arduino-nixie -// based on original sketch by Robin Birtles (rlb-designs.com) and Chris Gerekos -// based on http://arduinix.com/Main/Code/ANX-6Tube-Clock-Crossfade.txt - -//TODO: implement options for full date every 5 minutes -//TODO: see other TODOs throughout -//TODO: is it possible to trip the chime *after* determining if we're in night mode or not -//TODO: reenable rotary encoder with libraries with workable licenses +// Sketch by Luke McKenzie (luke@theclockspot.com) - https://github.com/clockspot/arduino-nixie +// Inspired by original sketch by Robin Birtles (rlb-designs.com) and Chris Gerekos +// Display cycling code derived from http://arduinix.com/Main/Code/ANX-6Tube-Clock-Crossfade.txt ////////// Hardware configuration ////////// //Include the config file that matches your hardware setup. If needed, duplicate an existing one. #include "configs/v8c-6tube-relayswitch-pwm-top.h" -// #include "configs/v5-6tube-red.h" ////////// Other includes, global consts, and vars ////////// @@ -31,8 +25,8 @@ These ones are set outside the options menu (defaults defined in initEEPROM()): 3-4 Day count year 5 Day count month 6 Day count date - 7 Alt function (if not power switching) -( 7-15 are available ) + 7 Function preset (done by Alt when not power-switching) +( 8-15 are available ) These ones are set inside the options menu (defaults defined in arrays below). Some are skipped when they wouldn't apply to a given clock's hardware config, see fnOptScroll(); these ones will also be set at startup to the start= values, see setup(). Otherwise, make sure these ones' defaults work for all configs. @@ -298,7 +292,7 @@ void ctrlEvt(byte ctrl, byte evt){ startSet(timerInitial/60,0,1080,1); break; case fnIsDayCount: //set year like date, but from eeprom like startOpt startSet(readEEPROM(3,true),2000,9999,1); break; - case fnIsTemp: //is this where we do the calibration? TODO + case fnIsTemp: //could do calibration here if so inclined case fnIsTubeTester: default: break; } diff --git a/v8a_mod_test/v8a_mod_test.ino b/v8a_mod_test/v8a_mod_test.ino deleted file mode 100644 index ec73001..0000000 --- a/v8a_mod_test/v8a_mod_test.ino +++ /dev/null @@ -1,129 +0,0 @@ -//For testing mods to the v8.0 board, style A, with LED PWM - -const byte btnSel = A1; //was A1 -const byte btnAlt = A0; //was A0 -const byte btnUp = A6; //was A2 -const byte btnDn = A7; //was A3 -const byte pinLED = 11; //was A6 -const byte pinRelay = A3; //was A7 -byte binOutA[4] = {2,3,4,5}; -byte binOutB[4] = {6,7,8,9}; -byte anodes[3] = {16,12,13}; //first was 11 - -byte btnCur = 0; //Momentary button currently in use - only one allowed at a time - -byte ledStateNow = 0; -byte ledStateTarget = 0; - -void setup(){ - Serial.begin(9600); - //0 and 1: set as digital input - pinMode(A0, INPUT_PULLUP); - pinMode(A1, INPUT_PULLUP); - //2 and 3: set as digital output - pinMode(A2, OUTPUT); - pinMode(A3, OUTPUT); - //4 and 5: for I2C - //6 and 7: input, but analog pins with hardware pullup resistors, so nothing to do - analogWrite(pinLED,0); //0 = LEDs off - digitalWrite(pinRelay,1); //1 = connected device off - - //Set up just enough tube output to confirm the changed first anode is working - for(byte i=0; i<4; i++) { pinMode(binOutA[i],OUTPUT); pinMode(binOutB[i],OUTPUT); digitalWrite(binOutA[i],LOW); digitalWrite(binOutB[i],LOW); } - for(byte i=0; i<3; i++) { pinMode(anodes[i],OUTPUT); digitalWrite(anodes[i],LOW); } - digitalWrite(anodes[0],HIGH); //the one we want to test - - Serial.println(); - Serial.println(F("Ready for input.")); - Serial.println(F("Display should now read 0 on 3rd and 6th tubes.")); - Serial.println(F("SEL should change them to a 1; ALT should change them to 2.")); - Serial.println(F("UP should fade the LEDs in and out.")); - Serial.println(F("DOWN should toggle the relay.")); -} - -void loop(){ - checkInputs(); - if(ledStateNow != ledStateTarget) { - if(ledStateNow > ledStateTarget) { ledStateNow -= 5; } - else if(ledStateNow < ledStateTarget) { ledStateNow += 5; } - // Serial.print(ledStateNow,DEC); - // Serial.print(F(" => ")); - // Serial.println(ledStateTarget,DEC); - analogWrite(pinLED,ledStateNow); - } - delay(5); //in case of switch bounce? -} - -void checkInputs(){ - checkBtn(btnSel); - checkBtn(btnAlt); - checkBtn(btnUp); - checkBtn(btnDn); -} -bool readInput(byte pin){ - if(pin==A6 || pin==A7) return analogRead(pin)<100?0:1; //analog-only pins - else return digitalRead(pin); -} -void checkBtn(byte btn){ - //Changes in momentary buttons, LOW = pressed. - //When a button event has occurred, will call ctrlEvt - bool bnow = readInput(btn); - //If the button has just been pressed, and no other buttons are in use... - if(btnCur==0 && bnow==LOW) { - btnCur = btn; - Serial.println(); - bool newState = LOW; - switch(btn) { - case btnSel: - Serial.println(F("btnSel pressed")); - digitalWrite(binOutA[0],HIGH); - digitalWrite(binOutA[1],LOW); - digitalWrite(binOutB[0],HIGH); - digitalWrite(binOutB[1],LOW); - break; - case btnAlt: - Serial.println(F("btnAlt pressed")); - digitalWrite(binOutA[0],LOW); - digitalWrite(binOutA[1],HIGH); - digitalWrite(binOutB[0],LOW); - digitalWrite(binOutB[1],HIGH); - break; - case btnUp: - Serial.println(F("btnUp pressed")); - ledStateTarget = (ledStateTarget==0?255:0); - Serial.println(); - if(ledStateTarget==0) Serial.println(F("LED switched off. LED PWM pin should fade to open circuit.")); - else Serial.println(F("LED switched on. LED PWM pin should fade to closed circuit.")); - break; - case btnDn: - Serial.println(F("btnDn pressed")); - newState = !digitalRead(pinRelay); - digitalWrite(pinRelay, newState); - Serial.println(); - if(newState) Serial.println(F("Relay switched on. Relay pins should measure open circuit now (connected device off).")); - else Serial.println(F("Relay switched off. Relay pins should measure closed circuit now (connected device on).")); - break; - default: break; - } //end button printing switch - } //end if button presed - //If the button has just been released... - if(btnCur==btn && bnow==HIGH) { - Serial.println(); - switch(btn){ - case btnSel: - Serial.println(F("btnSel released")); - break; - case btnAlt: - Serial.println(F("btnAlt released")); - break; - case btnUp: - Serial.println(F("btnUp released")); - break; - case btnDn: - Serial.println(F("btnDn released")); - break; - default: break; - } - btnCur = 0; - } -} \ No newline at end of file diff --git a/v8b_mod_test/v8b_mod_test.ino b/v8b_mod_test/v8b_mod_test.ino deleted file mode 100644 index 2dbed76..0000000 --- a/v8b_mod_test/v8b_mod_test.ino +++ /dev/null @@ -1,129 +0,0 @@ -//For testing mods to the v8.0 board, style B, with LED PWM - -const byte btnSel = A6; //was A1 -const byte btnAlt = A7; //was A0 -const byte btnUp = A0; //was A2 -const byte btnDn = A1; //was A3 -const byte pinLED = 11; //was A6 -const byte pinRelay = A3; //was A7 -byte binOutA[4] = {2,3,4,5}; -byte binOutB[4] = {6,7,8,9}; -byte anodes[3] = {16,12,13}; //first was 11 - -byte btnCur = 0; //Momentary button currently in use - only one allowed at a time - -byte ledStateNow = 0; -byte ledStateTarget = 0; - -void setup(){ - Serial.begin(9600); - //0 and 1: set as digital input - pinMode(A0, INPUT_PULLUP); - pinMode(A1, INPUT_PULLUP); - //2 and 3: set as digital output - pinMode(A2, OUTPUT); - pinMode(A3, OUTPUT); - //4 and 5: for I2C - //6 and 7: input, but analog pins with hardware pullup resistors, so nothing to do - analogWrite(pinLED,0); //0 = LEDs off - digitalWrite(pinRelay,1); //1 = connected device off - - //Set up just enough tube output to confirm the changed first anode is working - for(byte i=0; i<4; i++) { pinMode(binOutA[i],OUTPUT); pinMode(binOutB[i],OUTPUT); digitalWrite(binOutA[i],LOW); digitalWrite(binOutB[i],LOW); } - for(byte i=0; i<3; i++) { pinMode(anodes[i],OUTPUT); digitalWrite(anodes[i],LOW); } - digitalWrite(anodes[0],HIGH); //the one we want to test - - Serial.println(); - Serial.println(F("Ready for input.")); - Serial.println(F("Display should now read 0 on 3rd and 6th tubes.")); - Serial.println(F("SEL should change them to a 1; ALT should change them to 2.")); - Serial.println(F("UP should fade the LEDs in and out.")); - Serial.println(F("DOWN should toggle the relay.")); -} - -void loop(){ - checkInputs(); - if(ledStateNow != ledStateTarget) { - if(ledStateNow > ledStateTarget) { ledStateNow -= 5; } - else if(ledStateNow < ledStateTarget) { ledStateNow += 5; } - // Serial.print(ledStateNow,DEC); - // Serial.print(F(" => ")); - // Serial.println(ledStateTarget,DEC); - analogWrite(pinLED,ledStateNow); - } - delay(5); //in case of switch bounce? -} - -void checkInputs(){ - checkBtn(btnSel); - checkBtn(btnAlt); - checkBtn(btnUp); - checkBtn(btnDn); -} -bool readInput(byte pin){ - if(pin==A6 || pin==A7) return analogRead(pin)<100?0:1; //analog-only pins - else return digitalRead(pin); -} -void checkBtn(byte btn){ - //Changes in momentary buttons, LOW = pressed. - //When a button event has occurred, will call ctrlEvt - bool bnow = readInput(btn); - //If the button has just been pressed, and no other buttons are in use... - if(btnCur==0 && bnow==LOW) { - btnCur = btn; - Serial.println(); - bool newState = LOW; - switch(btn) { - case btnSel: - Serial.println(F("btnSel pressed")); - digitalWrite(binOutA[0],HIGH); - digitalWrite(binOutA[1],LOW); - digitalWrite(binOutB[0],HIGH); - digitalWrite(binOutB[1],LOW); - break; - case btnAlt: - Serial.println(F("btnAlt pressed")); - digitalWrite(binOutA[0],LOW); - digitalWrite(binOutA[1],HIGH); - digitalWrite(binOutB[0],LOW); - digitalWrite(binOutB[1],HIGH); - break; - case btnUp: - Serial.println(F("btnUp pressed")); - ledStateTarget = (ledStateTarget==0?255:0); - Serial.println(); - if(ledStateTarget==0) Serial.println(F("LED switched off. LED PWM pin should fade to open circuit.")); - else Serial.println(F("LED switched on. LED PWM pin should fade to closed circuit.")); - break; - case btnDn: - Serial.println(F("btnDn pressed")); - newState = !digitalRead(pinRelay); - digitalWrite(pinRelay, newState); - Serial.println(); - if(newState) Serial.println(F("Relay switched on. Relay pins should measure open circuit now (connected device off).")); - else Serial.println(F("Relay switched off. Relay pins should measure closed circuit now (connected device on).")); - break; - default: break; - } //end button printing switch - } //end if button presed - //If the button has just been released... - if(btnCur==btn && bnow==HIGH) { - Serial.println(); - switch(btn){ - case btnSel: - Serial.println(F("btnSel released")); - break; - case btnAlt: - Serial.println(F("btnAlt released")); - break; - case btnUp: - Serial.println(F("btnUp released")); - break; - case btnDn: - Serial.println(F("btnDn released")); - break; - default: break; - } - btnCur = 0; - } -} \ No newline at end of file diff --git a/v8c_mod_test/v8c_mod_test.ino b/v8c_mod_test/v8c_mod_test.ino index 3cbd09a..ab3e4ad 100644 --- a/v8c_mod_test/v8c_mod_test.ino +++ b/v8c_mod_test/v8c_mod_test.ino @@ -1,4 +1,4 @@ -//For testing mods to the v8.0 board, style B, with LED PWM +//For testing mods to the v8.0 board to bring it up to v9 spec, per v8c config files const byte btnSel = A6; //was A1 const byte btnAlt = A7; //was A0 diff --git a/weekday_test/weekday_test.ino b/weekday_test/weekday_test.ino deleted file mode 100644 index 5fc4375..0000000 --- a/weekday_test/weekday_test.ino +++ /dev/null @@ -1,111 +0,0 @@ -// #include - -// #include -// #include -// DS3231 ds3231; -// RTClib rtc; -// DateTime tod; -// byte toddow; - -////////// Main code control ////////// - -void setup(){ - Serial.begin(9600); - //Wire.begin(); - //ds3231.setDate(2); - Serial.println(); - testDate(1900,1,1); - testDate(1985,10,7); - testDate(1996,2,15); - testDate(1996,3,15); - testDate(1997,2,15); - testDate(1997,3,15); - testDate(2000,2,15); - testDate(2000,3,15); - testDate(2018,3,8); - testDate(2018,3,9); - testDate(2018,3,10); - testDate(2018,3,11); - testDate(2018,3,12); - testDate(2018,3,13); - testDate(2018,3,14); - testDate(2018,3,15); - testDate(2040,3,15); -} - -byte testDate(word y, byte m, byte d){ - Serial.print(y,DEC); - Serial.print("-"); - Serial.print(m,DEC); - Serial.print("-"); - Serial.print(d,DEC); - Serial.print(" is "); - Serial.println(dayOfWeek(y,m,d),DEC); -} - - -byte dayOfWeek(word y, byte m, byte d){ - //DS3231 doesn't really calculate the day of the week, it just keeps a counter. - //We'll calculate per https://en.wikipedia.org/wiki/Zeller%27s_congruence - byte yb = y%100; //2-digit year - byte ya = y/100; //century - //For this formula, Jan and Feb are considered months 11 and 12 of the previous year. - //So if it's Jan or Feb, add 10 to the month, and set back the year and century if applicable - if(m<3) { m+=10; if(yb==0) { yb=99; ya-=1; } else yb-=1; } - else m -= 2; //otherwise subtract 2 from the month - return (d + ((13*m-1)/5) + yb + (yb/4) + (ya/4) + 5*ya) %7; -} - -void loop(){ - //Things done every "clock cycle" - //checkRTC(); //if clock has ticked, decrement timer if running, and updateDisplay -} - -////////// Clock ticking and timed event triggering ////////// -unsigned long rtcPollLast = 0; //maybe don't poll the RTC every loop? would that be good? -byte rtcSecLast = 61; -bool h12=false; -bool PM=false; -bool century=false; -void checkRTC(){ - // //Checks for new time-of-day second; decrements timer; checks for timed events; - // //updates display for running time or date. - // if(rtcPollLast