#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
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 setup() {
// Init
lcd.init();
lcd.backlight();
pinMode(13, INPUT);
pinMode(12, INPUT);
pinMode(11, INPUT);
}
void loop() {
lcd.setCursor(0,0); lcd.print(" ");
lcd.setCursor(0,0); lcd.print(millis());
start= digitalRead(13); //startknop lezen (groen)
stop=digitalRead(12);//stopknop lezen (geel)
reset=digitalRead(11);//resetknop gedrukt (rood)
delay(200);
/* Functie van de startknop.
0 16 29 39 59 72
|-----------------| |----------| |-------------| chronoTijd = 16+10+13 = 39
Start Start Start Start Start start
Funtcie van de stopknop.
0 16 29 39 59 72
|-----------------|-----------|----------|--------------------|-------------| chronoTijd = 16, 29, 39, 59, 72.
Start stop stop stop stop stop
Funtcie van de resetknop.
Funtcie van de stopknop.
0 16 29 39 59 72
|-----------------|-----------|----------|--------------------|-------------| chronoTijd = 16, 13, 10, 20, 13.
Start reset reset reset reset reset
Om de meting te stoppen moet je altijd eerst stop drukken en dan reset. */
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);
}
}
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);
}
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);
}
}
}