//Created by Rehaan Irani 2019

#include <LiquidCrystal.h>
double distance;
double Circumference = 2.042;
float Speed;
int roundedDistance;

float startTime = 0;

float endTime = 0;

float Time = 0;

LiquidCrystal lcd(7,6,5,4,3,2);

void setup() {
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, INPUT);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);

  lcd.begin(16,2);
  lcd.print("Distance: ");
  lcd.setCursor(0,1);
  lcd.print("Speed: ");

}

void loop() {
  int x;
  int y;
  
  x = digitalRead(11);
 // Serial.print(x);
  delay(1);
  y = digitalRead(11);

  if (x == 1 && y == 0) {
    distance += Circumference;  //m
    roundedDistance = round(distance);
    lcd.setCursor(10,0);
    lcd.print(roundedDistance);
   
    endTime = millis();
    Time = (endTime - startTime)/1000;  
    Speed = (3.6*2.042)/Time; //km/h
    Serial.print(Time);

    lcd.setCursor(7,1);
    lcd.print(Speed);
    startTime = millis();

  } 

}