SafeString  4.1.44
SafeString is a safe, robust and debuggable replacement for string processing in Arduino
PinFlasher.h
Go to the documentation of this file.
1 #ifndef _PIN_FLASHER_H_
2 #define _PIN_FLASHER_H_
3 /*
4  PinFlasher.h
5  by Matthew Ford, 2021/12/06
6  (c)2021 Forward Computing and Control Pty. Ltd.
7  NSW, Australia www.forward.com.au
8  This code may be freely used for both private and commerical use.
9  Provide this copyright is maintained.
10 */
11 #include <Arduino.h>
12 #include "millisDelay.h"
19 extern const int PIN_ON;
23 extern const int PIN_OFF;
24 
25 
49 class PinFlasher: protected millisDelay {
50  public:
60  PinFlasher(int pin = -1, bool invert = false);
61 
62  ~PinFlasher(); // sets pin back to input
63 
68  void update();
69 
78  void setPin(int pin);
79 
89  void setOnOff(unsigned long onOff_ms);
90 
91 
100  void setOnAndOff(unsigned long on_ms, unsigned long off_ms);
101 
115  bool invertOutput();
116 
117  protected:
121  virtual void setOutput();
122  int io_pin; // initially -1, not set
123  bool io_pin_on;//initially false/ off;
124  bool outputInverted; // initially false, not inverted, i.e. off is LOW, on is HIGH
125 
126  private:
127  unsigned long on_len_ms; // initially 0, off
128  unsigned long off_len_ms; // initially 0, off
129  bool pinModeSet; // initially false, pinMode(io_pin, OUTPUT) is deferred to the
130  // first setOutput() call so the constructor does not touch hardware during
131  // static initialization of global PinFlasher objects
132 };
133 
134 #endif
const int PIN_ON
Flashes the io_pin.
const int PIN_OFF
PIN_OFF is a 'magic' number that turns the output OFF when setOnOff(PIN_OFF) called.
The PinFlasher class inherits from millisDelay to provide non-blocking repeating on/off toggle of the...
Definition: PinFlasher.h:49
bool io_pin_on
Definition: PinFlasher.h:123
virtual void setOutput()
set the output based on io_pin, io_pin_on and outputInverted
bool outputInverted
Definition: PinFlasher.h:124
PinFlasher(int pin=-1, bool invert=false)
Constructor.
bool invertOutput()
Normally pin output is LOW for off, HIGH for on.
void setPin(int pin)
Set the output pin to flash.
void update()
check if output should be changed.
void setOnAndOff(unsigned long on_ms, unsigned long off_ms)
Set the On and Off separately.
void setOnOff(unsigned long onOff_ms)
Set the On and Off length, the period is twice this setting.
millisDelay** implements a non-blocking, repeatable delay, see the detailed description.
Definition: millisDelay.h:36