-
Notifications
You must be signed in to change notification settings - Fork 0
/
Speedometer.ino
75 lines (56 loc) · 1.48 KB
/
Speedometer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <LiquidCrystal.h>
const int reedSwitch = 8;
int flag = 0;
int Contrast = 100;
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);
//Changing variables
int lastState = LOW;
int currentState;
unsigned long pressedTime = 0;
unsigned long releasedTime = 0;
//Calculating variables
float circ = 65.973; //inches
float speedi; //inches/sec
float speedm; //kmph... speedm = 0.0914 speedi
void setup() {
analogWrite(6, Contrast);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Team Yantriki");
lcd.setCursor(0,1);
lcd.print("MAC0061");
delay(2000);
Serial.begin(9600);
pinMode(reedSwitch, INPUT);
//led blink program
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
currentState = digitalRead(reedSwitch);
if(lastState == LOW && currentState == HIGH){
pressedTime = millis();
} else if(lastState == HIGH && currentState == LOW){
releasedTime = millis();
}
long pressDuration = releasedTime - pressedTime;
speedm = -(circ*91.44)/pressDuration;
if(pressDuration < 0){
if(flag == 0){
Serial.println(speedm);
lcd.begin(16,2);
lcd.setCursor(0,1);
lcd.print(speedm);
lcd.print(" kmph");
lcd.print(" ");
flag = 1;
} else if(flag == 1){
Serial.println(speedm);
lcd.setCursor(0,1);
lcd.print(speedm);
lcd.print(" kmph");
lcd.print(" ");
flag = 0;
}
}
lastState = currentState;
}