ESP32Encoder
examples
Encoder
Encoder.ino
Go to the documentation of this file.
1
#include <
ESP32Encoder.h
>
2
3
ESP32Encoder
encoder
;
4
ESP32Encoder
encoder2
;
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
17
ESP32Encoder::useInternalWeakPullResistors
=
UP
;
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
49
encoder2Paused
= !
encoder2Paused
;
50
encoder2lastToggled
= millis();
51
}
52
}
53
encoder2Paused
bool encoder2Paused
Definition:
Encoder.ino:8
setup
void setup()
Definition:
Encoder.ino:10
UP
Definition:
ESP32Encoder.h:15
ESP32Encoder::resumeCount
int64_t resumeCount()
Definition:
ESP32Encoder.cpp:210
ESP32Encoder::attachHalfQuad
void attachHalfQuad(int aPintNumber, int bPinNumber)
Definition:
ESP32Encoder.cpp:178
ESP32Encoder
Definition:
ESP32Encoder.h:19
encoder
ESP32Encoder encoder
Definition:
Encoder.ino:3
encoder2lastToggled
unsigned long encoder2lastToggled
Definition:
Encoder.ino:7
ESP32Encoder::setCount
void setCount(int64_t value)
Definition:
ESP32Encoder.cpp:189
encoder2
ESP32Encoder encoder2
Definition:
Encoder.ino:4
ESP32Encoder::pauseCount
int64_t pauseCount()
Definition:
ESP32Encoder.cpp:206
ESP32Encoder.h
ESP32Encoder::getCount
int64_t getCount()
Definition:
ESP32Encoder.cpp:197
loop
void loop()
Definition:
Encoder.ino:34
ESP32Encoder::useInternalWeakPullResistors
static enum puType useInternalWeakPullResistors
Definition:
ESP32Encoder.h:53
ESP32Encoder::clearCount
int64_t clearCount()
Definition:
ESP32Encoder.cpp:201
Generated by
1.8.13