Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Heartbeat.h
1 #pragma once
2 
3 #include <stdint.h>
4 
12 class Heartbeat {
13 public:
14  static const uint16_t NormalOnMs = 50;
15  static const uint16_t NormalOffMs = 450;
16  static const uint16_t QuickOnMs = 25;
17  static const uint16_t QuickOffMs = 125;
18  static const uint16_t QuickerOnMs = 25;
19  static const uint16_t QuickerOffMs = 25;
20  static const uint16_t SlowOnMs = 50;
21  static const uint16_t SlowOffMs = 950;
22  static const uint16_t SlowerOnMs = 50;
23  static const uint16_t SlowerOffMs = 1950;
24 
25 public:
27  enum Mode {
28  Normal=0,
31  Slow,
33  Off,
34  On,
36  };
37 
38  typedef struct {
39  Mode mode;
40  uint16_t onTime;
41  uint16_t offTime;
42  } Times;
43 
51  Heartbeat(const uint8_t pin, const bool invertedLogic=false);
52  ~Heartbeat();
53 
58  void begin();
59 
62  Mode mode();
63 
68  void setMode(Mode mode);
69 
78  void setMode(Times times);
79 
85  void setCustomMode(uint16_t onTime, uint16_t offTime);
86 
92  void update();
93 
98  void setEnabled(bool on=true);
99 
102  Times times();
103 
104 private:
105  void updatePin(bool state);
106 
107 private:
108  Mode _mode;
109  const uint8_t _pin;
110  const bool _invertedLogic;
111  bool _pinState;
112  uint32_t _lastStateFlip;
113  uint16_t _onTime;
114  uint16_t _offTime;
115  bool _enabled;
116 
117 };
118 
void setCustomMode(uint16_t onTime, uint16_t offTime)
Definition: Heartbeat.cpp:79
Mode mode()
Definition: Heartbeat.cpp:28
void update()
Definition: Heartbeat.cpp:86
Definition: Mode.h:39
void setEnabled(bool on=true)
Definition: Heartbeat.cpp:123
Heartbeat(const uint8_t pin, const bool invertedLogic=false)
Definition: Heartbeat.cpp:6
blinks every 1000ms
Definition: Heartbeat.h:31
blinks every 50ms
Definition: Heartbeat.h:30
LED constant on.
Definition: Heartbeat.h:34
void setMode(Mode mode)
Definition: Heartbeat.cpp:33
void begin()
Definition: Heartbeat.cpp:23
LED constant off.
Definition: Heartbeat.h:33
blinks every 500ms
Definition: Heartbeat.h:28
blinks every 2000ms
Definition: Heartbeat.h:32
blinks every 150ms
Definition: Heartbeat.h:29
Times times()
Definition: Heartbeat.cpp:114
Indicates custom on/off times (set with setCustomMode)
Definition: Heartbeat.h:35