-
Notifications
You must be signed in to change notification settings - Fork 0
/
windTest
50 lines (42 loc) · 831 Bytes
/
windTest
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
int count;
bool pulseFlag;
bool goodCount;
unsigned long newTime;
unsigned long oldTime;
unsigned long velocity;
unsigned long deltaT;
byte sampleCount;
const byte interruptPin = 3;
void setup() {
Serial.begin(115200);
sampleCount = 0;
oldTime = 0;
newTime = 0;
pinMode(6, OUTPUT);
digitalWrite(6, LOW);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), setFlag, FALLING);
}
void loop() {
if (pulseFlag == true){
oldTime = newTime;
newTime = millis();
deltaT = newTime - oldTime;
velocity = 1400 / deltaT;
if (oldTime != 0) {
txData();
}
else {
oldTime = newTime;
pulseFlag = false;
Serial.println("Error");
}
}
}
void setFlag() {
pulseFlag = true;
}
void txData (){
Serial.println(velocity);
pulseFlag = false;
}