Skip to content

blinker

Jim Lee edited this page May 26, 2020 · 6 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 setOnOff(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 pulseOn(void)

Not typically called by the user. This is used internally by the timer code to tell the blinker when to turn on the LED.

void pulseOff(void)

Again, just like above, this is used internally by the timer code to tell the blinker it's time to turn the LED off.

Blinker is derived from the squareWave class. This means that all the calls from that class are also available to the user when using the blinker class.

Clone this wiki locally