Arduino-Blinkenlight
Arduino-Blinkenlight copied to clipboard
Add a Bool to return a value to pattern blink
There could be a function like this:
bool pattern(int num, SpeedSetting speed, bool repeat = false)
Then the blink code would play only once, and some action by another function could be taken as soon as the blink is over. Like this:
If I put my hand over a distance sensor, it would blink the number of millimeters that the hand is over the sensor. But then some function could only allow another "distance measure by the sensor" when the number of mms blinked is over. So the bool argument would indicate the end of the blink pattern (for a repeat = false)
Thanks!
Good idea! This could also be solved by a function which returns the current state, something like an enum BLINKING
, IDLE
, ON
, OFF
...
Your example would become something like this:
int distance_mm = read_distance();
if light.state == IDLE {
light.pattern(distance_mm);
}
Let me know what you think about this.
Great! Will you update the library then? :)
Yep, first thing in the new year ;)
Hi! Any news?? 😊😊😊
Hey, yes I found that you can already do this with the existing code:
#include <Blinkenlight.h>
Blinkenlight led(13);
int count = 1;
void setup()
{
led.setSpeed(200);
}
void loop()
{
if (!led.isOn()) {
count++;
if (count >= 5) {
count = 1;
}
led.pattern(count, false);
}
led.update();
}
This will blink 1, 2, 3, 4, 1, 2, 3, ... I just tested this and it seems to work. The API could be clearer, though.
For your usecase you just have to replace count
with your distance measurement and maybe adjust the timing to have a longer pause between the patterns.