led_bikewheel/led_bikewheel.ino

32 lines
565 B
Arduino
Raw Normal View History

2020-12-28 16:46:07 +01:00
const int HALL_PIN = 2;
2020-12-28 17:02:46 +01:00
const int ROUND_COUNT = 2;
2020-12-28 15:47:40 +01:00
void setup() {
2020-12-28 17:02:46 +01:00
Serial.begin(115200);
2020-12-28 15:47:40 +01:00
pinMode(LED_BUILTIN, OUTPUT);
pinMode(HALL_PIN, INPUT);
}
void loop() {
2020-12-28 17:02:46 +01:00
float start = micros();
int count = 0;
bool change = false;
while (count < ROUND_COUNT) {
if (digitalRead(HALL_PIN) == LOW) {
if(!change) {
change = true;
count++;
}
} else {
change = false;
}
2020-12-28 16:47:45 +01:00
}
2020-12-28 17:02:46 +01:00
float end = micros();
float passed = (end - start);
Serial.print("Diff: ");
Serial.print(passed);
Serial.println("micro seconds");
2020-12-28 15:47:40 +01:00
}