ESP32Encoder
Encoder.ino
Go to the documentation of this file.
1 #include <ESP32Encoder.h>
2 
5 
6 // timer and flag for example, not needed for encoders
7 unsigned long encoder2lastToggled;
8 bool encoder2Paused = false;
9 
10 void setup(){
11 
12  Serial.begin(115200);
13  // Enable the weak pull down resistors
14 
15  //ESP32Encoder::useInternalWeakPullResistors=DOWN;
16  // Enable the weak pull up resistors
18 
19  // use pin 19 and 18 for the first encoder
20  encoder.attachHalfQuad(19, 18);
21  // use pin 17 and 16 for the second encoder
22  encoder2.attachHalfQuad(17, 16);
23 
24  // set starting count value after attaching
25  encoder.setCount(37);
26 
27  // clear the encoder's raw count and set the tracked count to zero
28  encoder2.clearCount();
29  Serial.println("Encoder Start = " + String((int32_t)encoder.getCount()));
30  // set the lastToggle
31  encoder2lastToggled = millis();
32 }
33 
34 void loop(){
35  // Loop and read the count
36  Serial.println("Encoder count = " + String((int32_t)encoder.getCount()) + " " + String((int32_t)encoder2.getCount()));
37  delay(100);
38 
39  // every 5 seconds toggle encoder 2
40  if (millis() - encoder2lastToggled >= 5000) {
41  if(encoder2Paused) {
42  Serial.println("Resuming Encoder 2");
43  encoder2.resumeCount();
44  } else {
45  Serial.println("Paused Encoder 2");
46  encoder2.pauseCount();
47  }
48 
50  encoder2lastToggled = millis();
51  }
52 }
53 
bool encoder2Paused
Definition: Encoder.ino:8
void setup()
Definition: Encoder.ino:10
int64_t resumeCount()
void attachHalfQuad(int aPintNumber, int bPinNumber)
ESP32Encoder encoder
Definition: Encoder.ino:3
unsigned long encoder2lastToggled
Definition: Encoder.ino:7
void setCount(int64_t value)
ESP32Encoder encoder2
Definition: Encoder.ino:4
int64_t pauseCount()
int64_t getCount()
void loop()
Definition: Encoder.ino:34
static enum puType useInternalWeakPullResistors
Definition: ESP32Encoder.h:53
int64_t clearCount()