diff --git a/src/main.cpp b/src/main.cpp index 199b335..95d4c8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,28 +73,37 @@ void loop() uint32_t period = 0; uint16_t rotations = 0; + uint16_t led_period = (uint16_t)-1; + uint16_t led_counter = led_period; + while (1) { iterator++; uint8_t tacho_current = digitalRead(7); + /* Get number of loop iterations per fan revolution */ if (!tacho_last && tacho_current) { if (tacho_counter == 0) { tacho_counter = 1; - digitalWrite(2, LOW); } else { tacho_counter = 0; - digitalWrite(2, HIGH); period = iterator; + led_period = period / 3; iterator = 0; rotations++; } + } + tacho_last = tacho_current; + + /* Emit strobe for LED */ + led_counter--; + if (led_counter < 12) { + digitalWrite(2, HIGH); + if (!led_counter) { + led_counter = led_period; + } } else { digitalWrite(2, LOW); } - - tacho_last = tacho_current; - - delayMicroseconds(100); } }