Skip to content

Commit a3482df

Browse files
committed
encoder interrupt
1 parent 08e3dfe commit a3482df

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Encoder.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,14 @@ void Encoder::init(){
128128

129129
}
130130

131+
132+
void Encoder::enableInterrupt(){
133+
// interupt intitialisation
134+
// A callback and B callback
135+
attachInterrupt(digitalPinToInterrupt(pinA), []() {
136+
encoder.handleA();
137+
}, CHANGE);
138+
attachInterrupt(digitalPinToInterrupt(pinB), []() {
139+
encoder.handleB();
140+
}, CHANGE);
141+
}

Encoder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Encoder{
2929
void handleA();
3030
// B channel
3131
void handleB();
32+
void enableInterrupt();
3233

3334
// encoder getters
3435
// shaft velocity getter

examples/angle_control/angle_control.ino

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,7 @@ void setup() {
2727
// initialise encoder hardware
2828
encoder.init();
2929

30-
// interupt intitialisation
31-
// A callback and B callback
32-
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {
33-
encoder.handleA();
34-
}, CHANGE);
35-
attachInterrupt(digitalPinToInterrupt(encoder.pinB), []() {
36-
encoder.handleB();
37-
}, CHANGE);
30+
encoder.enableInterrupt();
3831

3932
// set driver type
4033
// DriverType::unipolar

0 commit comments

Comments
 (0)