From ad676c5b5eeddb6c4d75ba77932fa1830da015f5 Mon Sep 17 00:00:00 2001 From: Simon Couball Date: Wed, 12 Aug 2020 00:07:33 +0200 Subject: [PATCH] Emit Strobe for second LED --- src/main.cpp | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 95d4c8e..4429afc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include +static uint8_t led_duration = 4; + /* * Function: configureTimer * ---------------------------- @@ -55,6 +57,7 @@ void setup() Serial.println("set output pins..."); pinMode(2, OUTPUT); + pinMode(3, OUTPUT); pinMode(9, OUTPUT); pinMode(7, INPUT); @@ -73,8 +76,11 @@ void loop() uint32_t period = 0; uint16_t rotations = 0; - uint16_t led_period = (uint16_t)-1; - uint16_t led_counter = led_period; + uint16_t led_a_period = (uint16_t)-1; + uint16_t led_a_counter = led_a_period; + + uint16_t led_b_period = (uint16_t)-1; + uint16_t led_b_counter = led_b_period; while (1) { iterator++; @@ -88,22 +94,34 @@ void loop() } else { tacho_counter = 0; period = iterator; - led_period = period / 3; + led_a_period = period / 3; + led_b_period = period * 20 / 61; iterator = 0; rotations++; } } tacho_last = tacho_current; - /* Emit strobe for LED */ - led_counter--; - if (led_counter < 12) { + /* Emit strobe for LED A */ + led_a_counter--; + if (led_a_counter < led_duration) { digitalWrite(2, HIGH); - if (!led_counter) { - led_counter = led_period; + if (!led_a_counter) { + led_a_counter = led_a_period; } } else { digitalWrite(2, LOW); } + + /* Emit strobe for LED B */ + led_b_counter--; + if (led_b_counter < led_duration) { + digitalWrite(3, HIGH); + if (!led_b_counter) { + led_b_counter = led_b_period; + } + } else { + digitalWrite(3, LOW); + } } }