You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A somewhat unsuccessful attempt to control display cycling with millis() polling instead of delays. It gets brightness-flickery because I think the duty cycling durations are not consistent.
@@ -63,7 +63,7 @@ const byte signalType = 0; //What is the signal pin connected to?
63
63
// 0 = Piezo. When alarm and timer go off, it will output a beep pattern with tone() for signalDur seconds.
64
64
// 1 = Relay, signal style. Same as above, but it will simply switch the pin, for e.g. a solenoid striking a bell.
65
65
// 2 = Relay, radio style. When alarm goes off, output will stay on for signalDur seconds (e.g. clock radio or appliance timer). When timer is running, output will stay on until timer runs down (e.g. clock radio "sleep" function) – but note that if the connected device has its own switch (see below), this will only work if the device is switched on.
66
-
const word signalDur = 180; //Per above. Use e.g. 180 secs (3min) for signalType 0/1, 7200 secs (2hr) for signalType 2. Up to 65535 secs (just over 18 hrs).
66
+
67
67
const word signalBeepDur = 500; //With signalType 0/1, "beeps" happen once per second; how long is each beep in ms?
68
68
//Particularly when driving a solenoid with signalType 1, this should be set to a comfortable activation duration for the solenoid.
69
69
@@ -206,7 +206,7 @@ void setup(){
206
206
Wire.begin();
207
207
initOutputs();
208
208
initInputs();
209
-
if(readInput(mainSel)==LOW) initEEPROM();
209
+
//if(readInput(mainSel)==LOW) initEEPROM(); TODO why is this firing so much
int displayLast[6]={11,11,11,11,11,11}; //What is currently being displayed. We slowly fade away from this.
1035
+
int displayIn[6]={11,11,11,11,11,11};
1036
+
int displayOut[6]={11,11,11,11,11,11};
1036
1037
1037
1038
//ms
1038
1039
/*
@@ -1058,14 +1059,19 @@ at 4ms per digit, 4x4x3 = 48ms
1058
1059
at 3ms per digit, 3x3x3 = 27ms
1059
1060
at 6ms 6x6x3 = 108ms
1060
1061
*/
1061
-
constchar fadeDur = 6; //each multiplexed pair of digits appears for this amount of time: partly next digit, partly last digit, partly dim (if applicable)
1062
-
constchar dimDur = 4; //half of fadeDur for half brightness? don't go over fadeDur-2
1063
-
char fadeNextDur = 0; //Fading in displayNext values --TODO put back at 0
1064
-
char fadeLastDur = 6; //Fading out displayLast values
1062
+
1063
+
/*
1064
+
I'm thinking this can't be done with ms polling, because at 6ms it's flickery enough to see it, and at 4ms it's not, because if we use polling, the actual lighting durations may not be as consistent as they need to be, mils() are not precise enough. durations may not necessarily be the same every time, but I don't think the durations are the same every time. So the alternative is to use delay()
1065
+
*/
1066
+
1067
+
constint fadeDur = 4; //each multiplexed pair of digits appears for this amount of time: partly next digit, partly last digit, partly dim (if applicable)
1068
+
constint dimDur = 2; //half of fadeDur for half brightness? don't go over fadeDur-2
1069
+
int fadeNextDur = 0; //Fading in displayNext values
1070
+
int fadeLastDur = 0; //Fading out displayOut values
1065
1071
unsignedlong fadeStartLast = 0; //when the last digit fade was started
1066
1072
byte cycleStage = 0; //Which stage of the multiplexing cycle we're in
1067
1073
unsignedlong cycleLast = 0; //when the last stage was started
1068
-
char cycleDelay = 0; //how long until the next stage starts - set from fadeNextDur and fadeLastDur
1074
+
int cycleDelay = 0; //how long until the next stage starts - set from fadeNextDur and fadeLastDur
1069
1075
unsignedlong setStartLast = 0; //to control flashing during start
1070
1076
1071
1077
word outputCounter = 0;
@@ -1077,96 +1083,18 @@ void initOutputs() {
1077
1083
}
1078
1084
1079
1085
voidcycleDisplay(){
1086
+
unsignedlong mics = micros();
1080
1087
unsignedlong mils = millis();
1081
1088
1082
-
//Other display code decides whether we should dim per function or time of day
1083
-
bool dim = (displayDim==1?1:0);
1084
-
//But if we're setting, decide here to dim for every other 500ms since we started setting
1085
-
if(fnSetPg>0) {
1086
-
if(setStartLast==0) setStartLast = mils;
1087
-
dim = 1-(((mils-setStartLast)/500)%2);
1088
-
} else {
1089
-
if(setStartLast>0) setStartLast=0;
1089
+
if(mics < cycleLast) { //because mics will overflow every 70 mins
1090
+
cycleLast = 0;
1091
+
//need some more elegant stuff here with fadeStartLast
1090
1092
}
1091
-
1092
-
// Loop thru and update all the arrays, and fades.
1093
-
fadeLastDur = fadeDur-(dim?dimDur:0); //default value
fadeNextDur = (((mils-fadeStartLast)*(fadeDur-(dim?dimDur:0)-1))/(readEEPROM(20,false)*10))+1; //partial based on time since fadeStatLast and EEPROM overall digit fade setting
if(fadeStartLast!=0) { //If we're working on fading
1189
-
fadeNextDur = ((mils-fadeStartLast*(fadeDur-(dim?dimDur:0)-1))/(readEEPROM(20,false)*10))+1; //partial based on time since fadeStatLast and EEPROM overall digit fade setting
elseif(fadeLastDur>0) { //if we've just shut off the display in the middle of a fade (does this ever happen?), set things up for when display comes back
1237
1182
fadeLastDur = 0; //force a full fade in to the new value...
0 commit comments