-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebouncer.h
58 lines (44 loc) · 1.11 KB
/
Debouncer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
____ _____ _ _
| __ )| ____| | / \
| _ \| _| | | / _ \
| |_) | |___| |___ / ___ \
|____/|_____|_____/_/ \_\
http://bela.io
C++ Real-Time Audio Programming with Bela - Lecture 14: ADSR
*/
// Debouncer.h: simple class to debounce a button
#pragma once
class Debouncer {
private:
// State machine states
enum {
kStateLow = 0,
kStateJustHigh,
kStateHigh,
kStateJustLow
};
public:
// Constructor
Debouncer();
// Constructor specifying a sample rate
Debouncer(float sampleRate, float interval);
// Set the sample rate, used for all calculations
void setup(float sampleRate, float interval);
// Return the debounced state given the raw input
bool process(bool rawInput);
// Return whether the button is currently high or low
bool currentValue();
// Return whether the button just now went high
bool risingEdge();
// Return whether the button just now went low
bool fallingEdge();
// Destructor
~Debouncer();
private:
// State variables, not accessible to the outside world
int currentState_;
int previousState_;
int counter_;
int debounceInterval_;
};