rpm test
This commit is contained in:
parent
5f6f2825fe
commit
60a76d10a1
@ -1,16 +1,31 @@
|
|||||||
const int HALL_PIN = 2;
|
const int HALL_PIN = 2;
|
||||||
|
const int ROUND_COUNT = 2;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
pinMode(HALL_PIN, INPUT);
|
pinMode(HALL_PIN, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int hall_value = digitalRead(HALL_PIN);
|
float start = micros();
|
||||||
if (hall_value == HIGH) {
|
int count = 0;
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
bool change = false;
|
||||||
|
while (count < ROUND_COUNT) {
|
||||||
|
if (digitalRead(HALL_PIN) == LOW) {
|
||||||
|
if(!change) {
|
||||||
|
change = true;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
change = false;
|
||||||
}
|
}
|
||||||
delay(10); //debounce?
|
}
|
||||||
|
|
||||||
|
float end = micros();
|
||||||
|
float passed = (end - start);
|
||||||
|
Serial.print("Diff: ");
|
||||||
|
Serial.print(passed);
|
||||||
|
Serial.println("micro seconds");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user