Newer
Older
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
#include "RotaryEncoder.h"
const int pinA = 4;
const int pinB = 5;
const int ID = 0;
RotaryEncoder re(pinA, pinB, ID);
void ICACHE_RAM_ATTR ISR() {
re.tick();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
re.initInterrupts(ISR);
re.setEventHandler(cb);
delay(500);
Serial.println("\n\nESP8266 Rotary Encoder Test:");
}
void loop() {
re.check();
}
void cb(RotaryEncoder* rotaryEncoder, uint8_t eventType, int position) {
/*
* Rotary Encoder event handler that triggers WallVis behaviours
*/
String idString = String(rotaryEncoder->getId());
Serial.println("Encoder ID: " + idString + " Event Type: " + String(eventType) + " Position: " + String(position));
switch(eventType) {
case RotaryEncoder::kEventStableUpdate:
//Do something
break;
case RotaryEncoder::kEventUnstableUpdate:
//Do something else
break;
}
}