-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder.h
More file actions
60 lines (48 loc) · 1.29 KB
/
encoder.h
File metadata and controls
60 lines (48 loc) · 1.29 KB
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
59
60
// Rotary Encoder
// * Pins:
// Defined in PewBox.ino
// #define ENCODER_INPUT_CLK 2
// #define ENCODER_INPUT_DT 3
// #define ENCODER_INPUT_SW 4
// * Setup functions:
// initRotaryEncoder();
// * Handlers:
//
// Pass handler function to be invoked every time
// the encoder switch is pressed or released
// readEncoderSwitch(*foobarControlSwitchMomentaryHandler);
//
// Pass handler functions to be invoked every time
// the encoder latches in each respective direction
// readEncoderRotation(
// *foobarControlClockwiseHandler,
// *foobarControlCounterclockwiseHandler
// );
#ifndef ENCODER_H
#define ENCODER_H
#include <Arduino.h>
class Encoder {
public:
Encoder(int clkPin, int dtPin, int swPin);
~Encoder();
int initRotaryEncoder();
bool toggled();
bool momentaryOn();
void readEncoderRotation(
void (*clockwiseHandler)(),
void (*counterclockwiseHandler)()
);
void readEncoderSwitch(void (*encoderSwitchMomentaryHandler)());
void readEncoderSwitchMomentary(void (*encoderSwitchMomentaryHandler)());
private:
unsigned int clk_pin;
unsigned int dt_pin;
unsigned int sw_pin;
int encoderCurrentCLK;
int encoderPreviousCLK;
int encoderCurrentSW;
int encoderPreviousSW;
bool currentlyToggled = false;
bool currentlyMomentaryOn = false;
};
#endif // ENCODER_H