#ifndef __TIMED_PIN__H__ #define __TIMED_PIN__H__ #include enum TPinModes { TPM_OFF, // permanent on TPM_ON, // permanent off TPM_BLINK, // blink TPM_TIMED_ON, // timed on, then off permanently TPM_TIMED_OFF // timed off, then on permanently }; class TimedPin { private: uint8_t PinId; /// pin number (assignment on board) TPinModes TPinMode; /// current working mode bool PinState; /// current state of pin bool PinInvert; /// pin configuration (normal:on=HIGH, inverted:on=LOW) uint32_t RefTime; /// time of start or state change uint32_t OnTime; /// on time duration uint32_t OffTime; /// off time duration uint16_t CycleCnt; /// count of cycles at blink (0=non stop) void PinOn(); /// set pin to "on" (internal function) void PinOff(); /// set pin to "off" (internal function) public: TimedPin(); TimedPin(uint8_t pin, bool inverted = false); void begin(); void update(); void Blink(uint32_t t_on, uint32_t t_off, uint16_t cycles = 0); void Blink(uint32_t t) { Blink(t, t); } void BlinkCycles(uint32_t t_on, uint32_t t_off, uint16_t cycles) { Blink(t_on, t_off, cycles); }; void Off(); void OffTimed(uint32_t t); void On(); void OnTimed(uint32_t t); void Set(bool val) { if (val) On(); else Off(); }; }; #endif