Skip to content

squareWave

Jim Lee edited this page May 26, 2020 · 2 revisions

squareWave

Abstract:

Another thing one runs into, just about everywhere while coding, are square waves. A blinking light, square waves. A light dimmer, square waves. A motor controller, square waves. An RC servo position signal, square waves. Basically, something that goes from state A to state B and back, over and over being controlled by timers. In this class we use states true and false. The time alloted for true is set by the pulse() method and the total time of the cycle is set by the period() method. When the cycle starts, pulseOn() is called. When the pulse ends pulseOff() method is called. The design is that the user bases their class on this squareWave class, then overrides the pulseOn() and pulseOff() methods to do whatever needs to be done at those times for the new class.

Constructor.

squareWave(void);

The standard constructor, no parameters. The pulse and period times must be set later once this object is constructed.

squareWave(float periodMs,float pulseMs, bool blocking=false);

Constructor wit pass in parameters. This

periodMs : The cycle time of the routine. "On" time plus "off" time.

pulseMs : How long, in milliseconds, will the true value be held?

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