#include <Wire.h>
#include "rgb_lcd.h"
rgb_lcd lcd;
const int colorR = 0;
const int colorG = 100;
const int colorB = 150;
const int startButtonMain = 6;
const int startButton = 5;
const int b1 = 4;
const int b2 = 3;
const int b3 = 2;
bool started = false;
bool time1Taken = false;
bool time2Taken = false;
bool time3Taken = false;
bool showAbout = true;
unsigned long initTime, timer1, timer2, timer3 = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
pinMode(startButtonMain, INPUT_PULLUP);
pinMode(startButton, INPUT_PULLUP);
pinMode(b1, INPUT_PULLUP);
pinMode(b2, INPUT_PULLUP);
pinMode(b3, INPUT_PULLUP);
lcd.setCursor(0, 0);
lcd.print("Experiencia");
lcd.setCursor(0, 1);
lcd.print("Brachistochrone");
delay(1000);
lcd.clear();
}
void loop() {
if (showAbout) {
lcd.scrollDisplayLeft();
lcd.setCursor(1,0);
lcd.print(" ** Tiago Hortas ** Simao Cabral **");
lcd.setCursor(1,1);
lcd.print(" ** Tiago Alves ** Miguel Leal **");
delay(500);
}
// put your main code here, to run repeatedly:
if ((digitalRead(startButtonMain) == 0) && (!started)){
//Serial.println("timer started 0");
lcd.clear();
lcd.noAutoscroll();
lcd.setCursor(0, 0);
lcd.print("timer started 1");
initTime = millis();
started = true;
showAbout = false;
}
if (started && (digitalRead(b1) == 0) && (!time1Taken)){
lcd.setCursor(0, 1);
lcd.print("b1");
timer1 = millis();
time1Taken = true;
}
if (started && (digitalRead(b2) == 0) && (!time2Taken)){
lcd.setCursor(5, 1);
lcd.print("b2");
timer2 = millis();
time2Taken = true;
}
if (started && (digitalRead(b3) == 0) && (!time3Taken)){
lcd.setCursor(10, 1);
lcd.print("b3");
timer3 = millis();
time3Taken = true;
}
if (time1Taken && time2Taken && time3Taken){
lcd.clear();
delay(1000);
lcd.setCursor(1, 0);
lcd.print("t1");
lcd.setCursor(7, 0);
lcd.print("t2");
lcd.setCursor(13, 0);
lcd.print("t3");
lcd.setCursor(0, 1);
lcd.print((float)(timer1-initTime)/1000);
lcd.setCursor(6, 1);
lcd.print((float)(timer2-initTime)/1000);
lcd.setCursor(12, 1);
lcd.print((float)(timer3-initTime)/1000);
started = false;
time1Taken = false;
time2Taken = false;
time3Taken = false;
}
}