Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- #include <LiquidCrystal.h>
- // laps info
- unsigned long car20currentRunStartMillis;
- unsigned long car20lastRunInMillis;
- int car20currentLap;
- // laser gate
- boolean car20lastgatesensorstate = LOW; // the previous reading from sensor
- unsigned long car20lastDebounceTime = 0; // the last time the sensor pin was toggled
- boolean car20reading = LOW;
- unsigned long bestRunInMillis;
- int debounceDelay = 5000;
- const int RECV_PIN = 7;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
- void setup() {
- Serial.begin(9600);
- // pin mode
- delay(50); // to late the sensor and laser work, so we wont get the lap triggered.
- lcd.begin(16,4);
- lcd.setCursor(0,0);
- lcd.print("Car Tracker");
- delay(3000);
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("C20:");
- delay(50);
- lcd.setCursor(10,0);
- lcd.print("|:");
- irrecv.enableIRIn();
- irrecv.blink13(true);
- // reset params
- car20currentRunStartMillis = 0;
- car20lastRunInMillis = 0;
- car20currentLap = 0;
- }
- void loop()
- {
- if (irrecv.decode(&results) && ((millis() - car20lastDebounceTime) >= (3000))){
- car20lastDebounceTime = millis();
- Serial.println(results.value, HEX);
- if (results.value == 0xBA4500FF) {
- car20reading = HIGH;
- }
- Car20();
- irrecv.resume();
- }
- }
- void Car20() {
- unsigned long car20savedMillis;
- unsigned long car20fastestlap;
- // If the switch changed, due to noise or pressing:
- if (car20reading != car20lastgatesensorstate) {
- // reset the debouncing timer
- car20lastDebounceTime = millis();
- }
- if (car20reading != car20lastgatesensorstate) {
- car20lastgatesensorstate = car20reading;
- // If we went High, this mean the beam was broken
- if (car20lastgatesensorstate == HIGH) {
- // save the millis so all the math on it will be done with the same value.
- car20savedMillis = millis();
- // if its not the first lap
- if (car20currentLap > 0) {
- // save the last run
- car20lastRunInMillis = car20savedMillis - car20currentRunStartMillis;
- // if last run is faster then best run
- if (car20lastRunInMillis < car20fastestlap || car20fastestlap == 0) {
- car20fastestlap = car20lastRunInMillis;
- }
- }
- car20currentRunStartMillis = car20savedMillis;
- car20currentLap++;
- lcd.setCursor(4,0);
- lcd.print(car20lastRunInMillis / 1000.0, 3);
- lcd.setCursor(12,0);
- lcd.print(car20fastestlap / 1000.0, 3);
- if (car20fastestlap < bestRunInMillis || bestRunInMillis == 0) {
- bestRunInMillis = car20fastestlap;
- }
- car20lastgatesensorstate = LOW;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement