class Chrono {
public:
void start();
void stop();
void reset();
private:
long int stopTijd = 0;
long int startTijd = 0;
long int klok = 0;
long int chronoTijd = 0;
byte actief = true;
byte start = false;
byte stop = false;
byte reset = false;
byte einde = false;
};
void Chrono::start() {
if (start) { //startknop GROEN
if (actief) { //Dit wil zeggen dat de startknop 1,3, ... onpaar keer gedrukt is en dat de tijd loopt.
actief = not actief;
startTijd = millis();
// lcd.setCursor(0,1); lcd.print("Start loopt ");
} else { // Dit wil zeggen dat de startknop 2,4, ... paar keer gedrukt is en dat de tijd gestopt is. Nu moet er resultaat getoond worden.
actief = not actief;
stopTijd = millis();
chronoTijd = chronoTijd + stopTijd - startTijd;
//lcd.setCursor(0,1); lcd.print("Start gestopt ");
//lcd.setCursor(14,1); lcd.print(chronoTijd);
}
}
}
void Chrono::stop() {
if (stop and not actief) { //Stopknop is gedrukt GEEL
stopTijd = millis();
einde = true;
chronoTijd = stopTijd - startTijd;
}
//lcd.setCursor(0,2); lcd.print("Stop gedrukt ");
//lcd.setCursor(14,2); lcd.print(chronoTijd);
}
void Chrono::reset() {
if (reset and not actief) { //resetknop is gedruk Rood
if (einde) {
//lcd.clear();
//lcd.setCursor(0,4); lcd.print(" EINDE ");
einde = not einde;
actief = true;
} else {
stopTijd = millis();
chronoTijd = stopTijd - startTijd;
startTijd = stopTijd;
//lcd.setCursor(0,3); lcd.print("reset gedrukt ");
//lcd.setCursor(14,3); lcd.print(chronoTijd);
}
}
}