-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial rotary encoder commit. In beta. see issue #10
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 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,51 @@ | ||
#include "RotaryEncoder.h" | ||
namespace components | ||
{ | ||
RotaryEncoder::RotaryEncoder( uint8_t a, uint8_t b, uint8_t clicks ) | ||
: Component(), | ||
A( a, TriggerOn::Low, InputPull::Up ), | ||
B( b, TriggerOn::Low, InputPull::Up ), | ||
detents( clicks ) | ||
{ | ||
RegisterChild(A); | ||
A.onPress( [&] { | ||
if ( B.isPressed() == LOW ) | ||
{ | ||
rotation--; | ||
onRotate(-1); | ||
} | ||
else | ||
{ | ||
rotation++; | ||
onRotate(+1); | ||
} | ||
delay(5); | ||
} ); | ||
RegisterChild(B); | ||
B.onPress( [&] { | ||
delay(5); | ||
} ); | ||
} | ||
|
||
int32_t RotaryEncoder::onRotate( int8_t dr ) | ||
{ | ||
if ( dr > 0 ) | ||
{ | ||
Serial.print( 'R' ); | ||
} | ||
else | ||
{ | ||
Serial.print( 'L' ); | ||
} | ||
Serial.print( ' ' ); | ||
if ( detents ) | ||
rotation %= detents; | ||
Serial.println( rotation ); | ||
return rotation; | ||
} | ||
|
||
void RotaryEncoder::privateLoop( void ) | ||
{ | ||
|
||
} | ||
} |
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,17 @@ | ||
#include "TactileButton.h" | ||
#include "Component.h" | ||
namespace components | ||
{ | ||
class RotaryEncoder : public Component | ||
{ | ||
public: | ||
RotaryEncoder( uint8_t a, uint8_t b, uint8_t clicks = 0 ); | ||
private: | ||
int32_t rotation; | ||
int32_t onRotate( int8_t dr ); | ||
uint8_t detents; | ||
TactileButton A; | ||
TactileButton B; | ||
void privateLoop( void ); | ||
}; | ||
} |