Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Bool to return a value to pattern blink #1

Open
Rimbaldo opened this issue Dec 15, 2022 · 5 comments
Open

Add a Bool to return a value to pattern blink #1

Rimbaldo opened this issue Dec 15, 2022 · 5 comments

Comments

@Rimbaldo
Copy link

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!

@tfeldmann
Copy link
Owner

tfeldmann commented Dec 22, 2022

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.

@Rimbaldo
Copy link
Author

Great! Will you update the library then? :)

@tfeldmann
Copy link
Owner

Yep, first thing in the new year ;)

@Rimbaldo
Copy link
Author

Rimbaldo commented Jan 5, 2023

Hi! Any news?? 😊😊😊

@tfeldmann
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants