SafeString  4.1.40
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:
57  PinFlasher(int pin = -1, bool invert = false);
58 
59  ~PinFlasher(); // sets pin back to input
60 
65  void update();
66 
75  void setPin(int pin);
76 
86  void setOnOff(unsigned long onOff_ms);
87 
88 
97  void setOnAndOff(unsigned long on_ms, unsigned long off_ms);
98 
112  bool invertOutput();
113 
114  protected:
118  virtual void setOutput();
119  int io_pin; // initially -1, not set
120  bool io_pin_on;//initially false/ off;
121  bool outputInverted; // initially false, not inverted, i.e. off is LOW, on is HIGH
122 
123  private:
124  unsigned long on_len_ms; // initially 0, off
125  unsigned long off_len_ms; // initially 0, off
126 };
127 
128 #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:120
virtual void setOutput()
set the output based on io_pin, io_pin_on and outputInverted
bool outputInverted
Definition: PinFlasher.h:121
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:35