-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added polling and multiple encoder support.
Added: -polling support -multiple encoder support -a better readme
- Loading branch information
sabeechen
authored
Apr 30, 2018
1 parent
265f232
commit d303a57
Showing
6 changed files
with
209 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <RotaryEncoder.h> | ||
|
||
#define ENCODER_PIN1 13 | ||
#define ENCODER_PIN2 14 | ||
#define BUTTON_PIN 12 | ||
|
||
RotaryEncoder encoder(ENCODER_PIN1, ENCODER_PIN2, BUTTON_PIN); | ||
|
||
void buttonDown() { | ||
Serial.println("button down"); | ||
} | ||
|
||
void buttonUp() { | ||
Serial.println("button up"); | ||
} | ||
|
||
void movedClockwise() { | ||
Serial.println("moved clockwise"); | ||
} | ||
|
||
void movedCounterClockwise() { | ||
Serial.println("moved counter-clockwise"); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
encoder.setup(); | ||
encoder.setupInterrupts(); | ||
encoder.setButtonDownCallback(buttonDown); | ||
encoder.setButtonUpCallback(buttonUp); | ||
encoder.setRotateCWCallback(movedClockwise); | ||
encoder.setRotateCCWCallback(movedCounterClockwise); | ||
} | ||
|
||
void loop() { | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/encoder_without_interrupts/encoder_without_interrupts.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <RotaryEncoder.h> | ||
|
||
#define ENCODER_PIN1 13 | ||
#define ENCODER_PIN2 14 | ||
#define BUTTON_PIN 12 | ||
|
||
RotaryEncoder encoder(ENCODER_PIN1, ENCODER_PIN2, BUTTON_PIN); | ||
|
||
void buttonDown() { | ||
Serial.println("button down"); | ||
} | ||
|
||
void buttonUp() { | ||
Serial.println("button up"); | ||
} | ||
|
||
void movedClockwise() { | ||
Serial.println("moved clockwise"); | ||
} | ||
|
||
void movedCounterClockwise() { | ||
Serial.println("moved counter-clockwise"); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
encoder.setup(); | ||
encoder.setButtonDownCallback(buttonDown); | ||
encoder.setButtonUpCallback(buttonUp); | ||
encoder.setRotateCWCallback(movedClockwise); | ||
encoder.setRotateCCWCallback(movedCounterClockwise); | ||
} | ||
|
||
void loop() { | ||
encoder.loop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <RotaryEncoder.h> | ||
|
||
#define ENCODER1_PIN1 13 | ||
#define ENCODER1_PIN2 14 | ||
|
||
#define ENCODER2_PIN1 12 | ||
#define ENCODER2_PIN2 11 | ||
|
||
RotaryEncoder encoder1(ENCODER1_PIN1, ENCODER1_PIN2); | ||
RotaryEncoder encoder2(ENCODER2_PIN1, ENCODER2_PIN2); | ||
|
||
void movedClockwise() { | ||
Serial.println("moved clockwise"); | ||
} | ||
|
||
void movedCounterClockwise() { | ||
Serial.println("moved counter-clockwise"); | ||
} | ||
|
||
void encoder1Interrupt() { | ||
encoder1.loop(); | ||
} | ||
|
||
void encoder2Interrupt() { | ||
encoder2.loop(); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
encoder1.setup(); | ||
encoder1.setupInterrupts(encoder1Interrupt); | ||
encoder1.setRotateCWCallback(movedClockwise); | ||
encoder1.setRotateCCWCallback(movedCounterClockwise); | ||
|
||
encoder2.setup(); | ||
encoder2.setupInterrupts(encoder2Interrupt); | ||
encoder2.setRotateCWCallback(movedClockwise); | ||
encoder2.setRotateCCWCallback(movedCounterClockwise); | ||
} | ||
|
||
void loop() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters