SafeString
4.1.27
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
|
The PinFlasher class inherits from millisDelay to provide non-blocking repeating on/off toggle of the specified pin, see the detailed description. More...
#include <PinFlasher.h>
Inherits millisDelay.
Public Member Functions | |
PinFlasher (int pin=-1, bool invert=false) | |
Constructor. More... | |
~PinFlasher () | |
void | update () |
check if output should be changed. More... | |
void | setPin (int pin) |
Set the output pin to flash. More... | |
void | setOnOff (unsigned long onOff_ms) |
Set the On and Off length, the period is twice this setting. More... | |
bool | invertOutput () |
Normally pin output is LOW for off, HIGH for on. More... | |
Protected Member Functions | |
virtual void | setOutput () |
set the output based on io_pin, io_pin_on and outputInverted More... | |
Protected Member Functions inherited from millisDelay | |
millisDelay () | |
void | start (unsigned long delay) |
Start a delay of this many milliseconds. More... | |
void | stop () |
Stop the delay justFinished() will now never return true until after start(),restart() or repeat() called again. More... | |
void | repeat () |
repeat() Do same delay again but allow for a possible delay in calling justFinished() More... | |
void | restart () |
restart() Start the same delay again starting from now Note: use repeat() when justFinished() returns true, if you want a regular repeating delay More... | |
void | finish () |
Force delay to end now. More... | |
bool | justFinished () |
Has the delay ended/expired or has finish() been called? justFinished() returns true just once when delay first exceeded or the first time it is called after finish() called. More... | |
bool | isRunning () |
Is the delay running, i.e. More... | |
unsigned long | getStartTime () |
Returns the last time this delay was started, in ms, by calling start(), repeat() or restart() Returns 0 if it has never been started. More... | |
unsigned long | remaining () |
How many ms remaining until delay finishes Returns 0 if finished or stopped. More... | |
unsigned long | delay () |
The delay set in start. More... | |
Protected Attributes | |
int | io_pin |
bool | io_pin_on |
bool | outputInverted |
The PinFlasher class inherits from millisDelay to provide non-blocking repeating on/off toggle of the specified pin, see the detailed description.
To use PinFlasher, create a global instance for each pin you want to flash e.g.
PinFlasher ledFlasher(13);
if the led is turned ON with a HIGH output or set the optional invert argument true i.e.
PinFlasher ledFlasher(13,true);
if the led is turned ON with a LOW output
Then add to the loop() code the statement
ledFlasher.update();
You can then control the led state and flash rate with
ledFlasher.setOnOff(1000);
to flash the led on for 1sec (1000ms) and off for 1sec (1000ms) or
ledFlasher.setOnOff(PIN_ON);
turn the led hard ON or
ledFlasher.setOnOff(PIN_OFF);
to turn the led hard OFF
When you created the pinFlasher you specified the output level for logical ON so PIN_ON will turn the led on and PIN_OFF will turn it off.
Definition at line 49 of file PinFlasher.h.
PinFlasher::PinFlasher | ( | int | pin = -1 , |
bool | invert = false |
||
) |
Constructor.
if pin >= 0 it is initally set to output and OFF
pin | – the pin number to flash, default -1 (not set) |
invert | – true to make pin LOW for on, false (default) to make pin HIGH for on. |
PinFlasher::~PinFlasher | ( | ) |
bool PinFlasher::invertOutput | ( | ) |
Normally pin output is LOW for off, HIGH for on.
This inverts the current setting for on/off
void PinFlasher::setOnOff | ( | unsigned long | onOff_ms | ) |
Set the On and Off length, the period is twice this setting.
This call does nothing if the on/off length is the same as the existing setting.
This simplifies the calling logic.
onOff_ms | – ms for on and also for off, i.e. half the period, duty cycle 50% PIN_OFF (0) turns off the output PIN_ON (-1) turns the output on other values turn the output on for that length of time and then off for the same time |
|
protectedvirtual |
set the output based on io_pin, io_pin_on and outputInverted
void PinFlasher::setPin | ( | int | pin | ) |
Set the output pin to flash.
Call setOnOff( ) to start flashing, after calling setPin()
Multiple calls to this method with the same pinNo are ignored and do not interfere with flashing
If pinNo changes, stop any current flashing, set pin to output and OFF
else ignore this call
pin | – the pin number to flash |
void PinFlasher::update | ( | ) |
check if output should be changed.
update() should be called often, atleast every loop()
|
protected |
Definition at line 108 of file PinFlasher.h.
|
protected |
Definition at line 109 of file PinFlasher.h.
|
protected |
Definition at line 110 of file PinFlasher.h.