-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmplexCallbacks.ino
More file actions
48 lines (38 loc) · 1.24 KB
/
Copy pathmplexCallbacks.ino
File metadata and controls
48 lines (38 loc) · 1.24 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
#include "Arduino.h"
#include "EncoderTool.h"
#if defined(ESP32)
# define LED_BUILTIN 2
#endif
using namespace EncoderTool;
constexpr unsigned encoderCount = 8; // number of attached (daisy chain shift regesters for more than 8)
constexpr unsigned QH_A = 2; // output pin QH of shift register A
constexpr unsigned QH_B = 3; // output pin QH of shift register B
constexpr unsigned pinLD = 4; // load pin for all shift registers)
constexpr unsigned pinCLK = 5; // clock pin for all shift registers
// 74165 datasheet: http://www.ti.com/product/SN74HC165
EncPlex74165 encoders(encoderCount, pinLD, pinCLK, QH_A, QH_B);
void onFirstEncoder(int value, int delta)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
void onAnyEncoder(uint_fast8_t channel, int value, int delta)
{
Serial.print("Encoder: ");
Serial.print(channel);
Serial.print(" value: ");
Serial.print(value);
Serial.print(" delta: ");
Serial.print(delta);
Serial.println();
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
encoders.begin(CountMode::quarterInv);
encoders[0].attachCallback(onFirstEncoder); // standard callback
encoders.attachCallback(onAnyEncoder);
}
void loop()
{
encoders.tick();
}