Code Monkey home page Code Monkey logo

Comments (5)

tfeldmann avatar tfeldmann commented on September 27, 2024

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.

from arduino-blinkenlight.

Rimbaldo avatar Rimbaldo commented on September 27, 2024

Great! Will you update the library then? :)

from arduino-blinkenlight.

tfeldmann avatar tfeldmann commented on September 27, 2024

Yep, first thing in the new year ;)

from arduino-blinkenlight.

Rimbaldo avatar Rimbaldo commented on September 27, 2024

Hi! Any news?? 😊😊😊

from arduino-blinkenlight.

tfeldmann avatar tfeldmann commented on September 27, 2024

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.

from arduino-blinkenlight.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.