Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
AbstractDebouncedButton.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include "AbstractButton.h"
5 
12 public:
13  static const uint8_t DefaultThreshold = 5;
14  static const uint8_t DefaultButtonDelay = 5;
15  static const uint16_t DefaultHeldMs = 800;
16  static const uint16_t DefaultButtonRepeatInitialMs = 700;
17  static const uint16_t DefaultButtonRepeatMs = 350;
18 
19 public:
23 
34  void begin(uint8_t threshold=DefaultThreshold, uint8_t delay=DefaultButtonDelay);
35 
40  virtual void update() = 0;
41 
55  bool pushed(bool peek=false);
56 
65  uint32_t tapped(bool peek=false);
66 
74  bool held(uint16_t ms=DefaultHeldMs);
75 
82  bool repeat(uint16_t initialMs=DefaultButtonRepeatInitialMs, uint16_t repeatMs=DefaultButtonRepeatMs);
83 
88  void setState(bool newState);
89 
90 protected:
91  uint8_t _threshold;
92  uint8_t _delay;
93  uint32_t _lastUpdate;
94  uint8_t _counter;
95  bool _state;
96  uint32_t _lastStateChange;
97  bool _pushed;
98  uint16_t _repeatCount;
99  uint32_t _lastRepeat;
100  uint32_t _lastOnDuration;
101 
102 };
103 
104 
bool held(uint16_t ms=DefaultHeldMs)
virtual void update()=0
bool repeat(uint16_t initialMs=DefaultButtonRepeatInitialMs, uint16_t repeatMs=DefaultButtonRepeatMs)
virtual void begin()
uint32_t tapped(bool peek=false)