forked from TheKikGen/kikpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotary.h
49 lines (39 loc) · 907 Bytes
/
Rotary.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
/*
* Rotary encoder library for Arduino.
*/
#ifndef Rotary_h
#define Rotary_h
#include "Arduino.h"
// Enable this to emit codes twice per step.
// #define HALF_STEP
class Rotary
{
uint8_t _state;
uint8_t _pin1;
uint8_t _pin2;
#ifdef _R_HALF_STEP
static const uint8_t _ttable[6][4];
#else
static const uint8_t _ttable[7][4];
#endif
public:
enum encoderStatusValues {
noDir = 0x00, // No complete step yet.
dirCw = 0x10, // Clockwise step.
dirCCw = 0x20 // Counter-clockwise step.
};
enum encodeStateTableValues {
start,
#ifdef _R_HALF_STEP
// Use the half-step state table (emits a code at 00 and 11)
ccwBegin, cwBegin, startM, cwBeginM, ccwBeginM
#else
// Use the full-step state table (emits a code at 00 only)
cwFinal, cwBegin, cwNext, ccwBegin, ccwFinal, ccwNext
#endif
};
Rotary();
void begin(uint8_t, uint8_t);
uint8_t read();
};
#endif