Emit Strobe for second LED
This commit is contained in:
34
src/main.cpp
34
src/main.cpp
@@ -1,5 +1,7 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user