Skip to content
Jim Lee edited this page Oct 7, 2019 · 9 revisions

blinker

Abstract:

There are so many times, when working with code, you want something to blink an LED. Its the "hello world" of micro processor work. But there's more to it isn't there? A blinking LED shouldn't consume the entire useful output of your processor. It would be nice to just have it go off and do its blink thing, in the background, without getting in the way. This is what blinker was designed for. Hook an LED to a pin and ground, with the appropriate resistor, tell blinker what pin its using, and let it go. The LED blinks. It's magic!

Well actually, there is one caveat. You have to include a call to idle(); in your loop() method. idle() is what allows things that "run in the background" to run in the background. More on that later.

Constructor.

blinker(int inPin=defPin,float inOnMs=defOnMs,float inPeriodMs=defPeriodMs,bool inInverse=false);

Everything that can be passed in has defaults. Meaning you can call this without any parameters and it'll just work. Actually, it will blink pin 13, the usual pin number that Arduinos have their built in LED attached to.

inPin : the pin number you have your LED attached to.

inOnMs : How long in milliseconds will the LED be on when it blinks. This is a float so it can have partial millisecond granularity.

inPeriodMs : Total time in milliseconds summing both on and off times in milliseconds. Again, a float so it has partial millisecond granularity.

inInverse : If your LED comes on when you ground the LED pin instead of putting power to it, set this to "true".

Other methods..

void setInverse(bool inInverse)

This call sets either using power or ground to switch on the LED. Typically this is set in the constructor and the user doesn't ever need to call this implicitly.

void setLight(bool onOff)

Turn the LED on or off. Again, this is used by the object and not typically called by the user. Its there if you want it. Or, if someone wants to override it and do something else.

void setBlink(bool onOff)

Starts or stops the blinker. Used quite frequently by the user for turning the blinking on and off.

bool blinking();

Returns the running state of the blinker. Is it running or not?

void setTimes(float inOnMs, float inPeriodMs)

Used for changing the times of the blinker. Slower, faster, longer shorter. Very handy for dynamic blinking.

void idle(void)

Because blinker inherits idler, it has an idle method. This is where everything happens in the background.

Clone this wiki locally