forked from JoshuaKaplan1/Photogate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhotogate.ino
More file actions
48 lines (38 loc) · 783 Bytes
/
Copy pathPhotogate.ino
File metadata and controls
48 lines (38 loc) · 783 Bytes
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
int led = 13;
int photo = A0;
float MPH;
long time1;
long afterTime;
long currentTime;
float cmms;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(photo, INPUT);
Serial.begin(9600);
digitalWrite(led, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0);
delay(1);
while (analogRead(A0) > 900) { //>500 when the gate is not blocked.
;//
}
currentTime = millis();
delay(50);
while (analogRead(A0) < 900) {
;//
}
afterTime = millis();
delay(50);
time1 = afterTime - currentTime;
Serial.print("MS =");
Serial.println(time1);
cmms = 8.5/time1;
MPH = cmms * 22.369;
Serial.print("MPH = ");
Serial.println(MPH);
delay(250);
time1 = 0;
}