-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bc7cc7
commit 68e0deb
Showing
8 changed files
with
320 additions
and
98 deletions.
There are no files selected for viewing
92 changes: 0 additions & 92 deletions
92
examples/Esp32RotaryEncoderBasics_old/Esp32RotaryEncoderBasics_old.ino
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
examples/Esp32RotaryEncoderTestAcceleration/Esp32RotaryEncoderTestAcceleration.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,82 @@ | ||
#include "AiEsp32RotaryEncoder.h" | ||
#include "Arduino.h" | ||
|
||
/* | ||
connecting Rotary encoder | ||
Rotary encoder side MICROCONTROLLER side | ||
------------------- --------------------------------------------------------------------- | ||
CLK (A pin) any microcontroler intput pin with interrupt -> in this example pin 32 | ||
DT (B pin) any microcontroler intput pin with interrupt -> in this example pin 21 | ||
SW (button pin) any microcontroler intput pin with interrupt -> in this example pin 25 | ||
GND - to microcontroler GND | ||
VCC microcontroler VCC (then set ROTARY_ENCODER_VCC_PIN -1) | ||
***OR in case VCC pin is not free you can cheat and connect:*** | ||
VCC any microcontroler output pin - but set also ROTARY_ENCODER_VCC_PIN 25 | ||
in this example pin 25 | ||
*/ | ||
#define ROTARY_ENCODER_A_PIN 32 | ||
#define ROTARY_ENCODER_B_PIN 21 | ||
#define ROTARY_ENCODER_BUTTON_PIN 25 | ||
#define ROTARY_ENCODER_VCC_PIN -1 /* 27 put -1 of Rotary encoder Vcc is connected directly to 3,3V; else you can use declared output pin for powering rotary encoder */ | ||
|
||
//depending on your encoder - try 1,2 or 4 to get expected behaviour | ||
//#define ROTARY_ENCODER_STEPS 1 | ||
//#define ROTARY_ENCODER_STEPS 2 | ||
#define ROTARY_ENCODER_STEPS 4 | ||
|
||
//instead of changing here, rather change numbers above | ||
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, ROTARY_ENCODER_VCC_PIN, ROTARY_ENCODER_STEPS); | ||
|
||
void rotary_onButtonClick() | ||
{ | ||
static unsigned long lastTimePressed = 0; | ||
if (millis() - lastTimePressed < 500) | ||
return; //ignore multiple press in that time milliseconds | ||
lastTimePressed = millis(); | ||
|
||
unsigned long acceletation = rotaryEncoder.getAcceleration() + 50; | ||
if (acceletation > 400) | ||
acceletation = 0; | ||
rotaryEncoder.setAcceleration(acceletation); | ||
|
||
Serial.print("new acceleration is "); | ||
Serial.println(acceletation); | ||
Serial.print("Try to set value: "); | ||
Serial.println(random(-999, 999)); | ||
Serial.println("Set as fast as you can. If it is too hard or you suceeded, press the button again."); | ||
} | ||
|
||
void rotary_loop() | ||
{ | ||
if (rotaryEncoder.encoderChanged()) | ||
{ | ||
Serial.print("Value: "); | ||
Serial.println(rotaryEncoder.readEncoder()); | ||
} | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
rotaryEncoder.begin(); | ||
|
||
rotaryEncoder.setup( | ||
[] { rotaryEncoder.readEncoder_ISR(); }, | ||
[] { rotary_onButtonClick(); }); | ||
bool circleValues = false; | ||
rotaryEncoder.setBoundaries(-1000, 1000, circleValues); //minValue, maxValue, circleValues true|false (when max go to min and vice versa) | ||
rotaryEncoder.disableAcceleration(); //acceleration is now enabled by default - disable if you dont need it | ||
Serial.println("Ready"); | ||
Serial.print("Try to set value: "); | ||
Serial.println(752); | ||
Serial.println("If it is too hard press the button."); | ||
} | ||
|
||
void loop() | ||
{ | ||
rotary_loop(); | ||
delay(50); | ||
} |
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
30 changes: 30 additions & 0 deletions
30
examples/Esp32RotaryEncoderTheShortestExample/Esp32RotaryEncoderTheShortestExample.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,30 @@ | ||
#include "AiEsp32RotaryEncoder.h" | ||
#define ROTARY_ENCODER_A_PIN 32 | ||
#define ROTARY_ENCODER_B_PIN 21 | ||
#define ROTARY_ENCODER_BUTTON_PIN 25 | ||
#define ROTARY_ENCODER_STEPS 4 | ||
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, -1, ROTARY_ENCODER_STEPS); | ||
|
||
void rotary_onButtonClick() | ||
{ | ||
Serial.println("button pressed"); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
rotaryEncoder.begin(); | ||
rotaryEncoder.setup( | ||
[] { rotaryEncoder.readEncoder_ISR(); }, | ||
[] { rotary_onButtonClick(); }); | ||
rotaryEncoder.setBoundaries(0, 1000, false); //minValue, maxValue, circleValues true|false (when max go to min and vice versa) | ||
rotaryEncoder.setAcceleration(250); | ||
} | ||
|
||
void loop() | ||
{ | ||
if (rotaryEncoder.encoderChanged()) | ||
{ | ||
Serial.println(rotaryEncoder.readEncoder()); | ||
} | ||
} |
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,54 @@ | ||
#include "AiEsp32RotaryEncoder.h" | ||
#define ROTARY_ENCODER_A_PIN 32 | ||
#define ROTARY_ENCODER_B_PIN 21 | ||
#define ROTARY_ENCODER_BUTTON_PIN 25 | ||
#define ROTARY_ENCODER_STEPS 4 | ||
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, ROTARY_ENCODER_BUTTON_PIN, -1, ROTARY_ENCODER_STEPS); | ||
|
||
/* | ||
FM radio tunner is suposed to set frequency between 88.0 MHz and 104.0 MHz by 0.1MHz steps | ||
Rotary encoder works with integers so we will map 88.0 to 166 and then divide by 10 to get 0.1 steps | ||
frequency = rotaryValue / 2; | ||
*/ | ||
|
||
float getFrequency() | ||
{ | ||
return (float)rotaryEncoder.readEncoder() / 10.0; | ||
} | ||
|
||
void rotary_onButtonClick() | ||
{ | ||
static unsigned long lastTimePressed = 0; | ||
if (millis() - lastTimePressed < 200) | ||
return; | ||
lastTimePressed = millis(); | ||
|
||
Serial.print("Radio station set to "); | ||
Serial.print(getFrequency()); | ||
Serial.println(" MHz "); | ||
} | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
rotaryEncoder.begin(); | ||
rotaryEncoder.setup( | ||
[] { rotaryEncoder.readEncoder_ISR(); }, | ||
[] { rotary_onButtonClick(); }); | ||
rotaryEncoder.setBoundaries(88 * 10, 104 * 10, true); //minValue, maxValue, circleValues true|false (when max go to min and vice versa) | ||
rotaryEncoder.setAcceleration(50); | ||
rotaryEncoder.setEncoderValue(92.1 * 10); //set default to 92.1 MHz | ||
Serial.println("FM Radio"); | ||
Serial.print("Radio station initially set to "); | ||
Serial.print(getFrequency()); | ||
Serial.println(" MHz. Tune to some other station like 103.2... and press button "); | ||
} | ||
|
||
void loop() | ||
{ | ||
if (rotaryEncoder.encoderChanged()) | ||
{ | ||
Serial.print(getFrequency(), 1); | ||
Serial.println(" MHz "); | ||
} | ||
} |
Oops, something went wrong.