I'm having trouble writing code to create a stopwatch/timer. I'm using an Arduino Mega board and a 20x4 LCD screen. This timer is only one portion of the data I'll be displaying. Below is the code I've written do calculate the time:
int getE_minutes() {
double Emin;
int curTime = millis();
Emin = floor((curTime - pumpStartTime)/60000);
Serial.print("Minutes: ");
Serial.println(Emin);
return Emin;
}
int getE_seconds(int Emin) {
int curTime = millis();
double sec = (curTime - pumpStartTime)/1000;
int Esec = floor(sec - (60*Emin));
Serial.print("Seconds: ");
Serial.println(Esec);
return Esec;
}
I've written them as functions so that I can call it whenever I need to and not have them taking up time processing when I don't need it (my LCD will have multiple screens, so I only need it to be calculated when the LCD is in that particular state).
I've gotten it to display, and using this code results in the seconds counting up from 0 to 32 and then suddenly switching from 32 to -32 and counting up to 0 and starting over again. The minutes just display 0.
Any suggestions? Thanks for your help!