Browse Source

fix decimal place behavior

main
mm 3 years ago
parent
commit
61063d04d0
  1. 14
      CountUp/CountUp.ino

14
CountUp/CountUp.ino

@ -34,27 +34,29 @@ void setup() {
sevseg.setBrightness(10); sevseg.setBrightness(10);
pinMode(A5, INPUT_PULLUP); pinMode(A5, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP); pinMode(A1, INPUT_PULLUP);
// Serial.begin(9600); // debugging Serial.begin(9600); // debugging
} }
int decPlaces = 3; int decPlaces = 1;
float lastReset = 0; // optional button reset - orange wire connected to A1, or programmable button on A5 float lastReset = 0; // optional button reset - orange wire connected to A1, or programmable button on A5
void loop() { void loop() {
unsigned long runMillis= millis(); unsigned long runMillis= millis();
float actualDays = runMillis/86400000.0; float actualDays = runMillis/86400000.0;
float days = actualDays - lastReset; float days = actualDays - lastReset;
sevseg.setNumber(days, decPlaces); sevseg.setNumber(days*pow(10,decPlaces), decPlaces);
sevseg.refreshDisplay(); // Must run repeatedly sevseg.refreshDisplay(); // Must run repeatedly
// Serial.println(actualDays,5); // debugging // Serial.print(actualDays,5); // debugging
// Serial.print(' ');
// Serial.println(days,4);
// Serial.println(digitalRead(A1)); // debugging // Serial.println(digitalRead(A1)); // debugging
if(!digitalRead(A1)){lastReset -= 0.001;} if(!digitalRead(A1)){lastReset -= 0.0005;}
// if(!digitalRead(A5)){lastReset = actualDays;} // if(!digitalRead(A5)){lastReset = actualDays;}
// program A5 as decimal place changer // program A5 as decimal place changer
if(!digitalRead(A5)){ if(!digitalRead(A5)){
// if(decPlaces == 2){decPlaces = 3;} // if(decPlaces == 2){decPlaces = 3;}
// if(decPlaces == 3){decPlaces = 2;} // if(decPlaces == 3){decPlaces = 2;}
decPlaces = (decPlaces + 1)%2 + 2; decPlaces = (decPlaces + 1)%4;
delay(250); delay(250);
} }
} }

Loading…
Cancel
Save