You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Connect the Encoder to the D2 and D3 pins of the motherboard.You can use other pins if you want.
8
+
9
+
### Usage
10
+
11
+
1.git clone this resp to your Arduino IDE'S libraries directory.
12
+
13
+
2.Run the demo "encoderTest" on examples directory.
14
+
15
+
### Software usage
16
+
17
+
- Install Seeed Arduino RotaryEncoder library to Arduino.
18
+
19
+
- Start a project.
20
+
21
+
- Create the callback function and set the Encoder pin.(just set SIGA.SIGB pin is equal to SIGA pin plus 1.)
22
+
23
+
Usage of the library, see Example encoderTest
24
+
25
+
1. Add headers
26
+
```
27
+
#include "GroveEncoder.h"
28
+
```
29
+
2. Create the callback function.The callback function gets the current Angle and the status of the button press.
30
+
Define a 'value' to determine whether the Angle value has changed.Define a 'bt_flag' to prevent the button value from being read more than once.And set 'bt flag' to 1 in the while() function.You can also get the Angle value through the getValue() function.
31
+
```
32
+
int value = 0;
33
+
int bt_flag = 0;
34
+
void myCallback(int newValue, bool flag) {
35
+
if(value != newValue)
36
+
{
37
+
value = newValue;
38
+
Serial.print(newValue, HEX);
39
+
Serial.print("\n");
40
+
}
41
+
if(flag && bt_flag)
42
+
{
43
+
Serial.println("button");
44
+
bt_flag = 0;
45
+
}
46
+
}
47
+
```
48
+
```
49
+
while(1)
50
+
{
51
+
Serial.println(myEncoder.getValue());
52
+
delay(100);
53
+
bt_flag = 1;
54
+
}
55
+
```
56
+
57
+
3. Initialize the Encoder.The parameters are the SIGA pin and the callback function name, respectively.
0 commit comments