#include #include #include #include #include #include #include #define OLED_RESET 4 #define NUMBUTTONS 3 Adafruit_SSD1306 display(OLED_RESET); int buttons[NUMBUTTONS]= {2, 3, 4}; int lap=0; bool isRunning=false; //unsigned long runningTime[10]; unsigned long startedTime, finishedTime, elapsedTime; int m, s, ms; Bounce debouncer_tab[NUMBUTTONS]= {Bounce(), Bounce(), Bounce()}; void setup() { init_disp(); blesetup(); for (int i=0; i < NUMBUTTONS; i++){ pinMode(buttons[i],INPUT_PULLUP); debouncer_tab[i].attach(buttons[i]); debouncer_tab[i].interval(50); // interval in ms } } void loop() { for (int i=0; i < NUMBUTTONS; i++){ debouncer_tab[i].update(); if(debouncer_tab[i].fell()){ switch(i){ case 0: if(!isRunning){ startedTime=millis(); isRunning=true; lap++; scrolltext(lap); Serial.println(" Button 0 is pressed. Starting timer..."); } break; case 1: if(isRunning){ elapsedTime=elapsedt(startedTime); startedTime=millis(); lap++; scrolltext(lap); Serial.print(" Button 1 is pressed. Next lap..."); Serial.print("millis : "); Serial.println(elapsedTime); sendDataBLE(lap-1, elapsedTime, 0); } break; case 2: if(isRunning){ finishedTime=millis(); elapsedTime=elapsedt(startedTime); //elapsed(); Serial.print(" Button 2 is pressed. Stopping timer... "); /*Serial.print(m); Serial.print(":"); Serial.print(s); Serial.print(":"); Serial.println(ms);*/ Serial.print("millis : "); Serial.println(elapsedTime); isRunning=false; lap=0; scrolltext(lap); } break; } break; } } }