Skip to content

Commit 9e61772

Browse files
huadiweilaoqyPillar1989
authored andcommitted
Update README.md
1 parent 8e4de83 commit 9e61772

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,62 @@
11
# Seeed_Arduino_RotaryEncoder
2+
3+
### Introduction
4+
5+
This library support Encoder.
6+
7+
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.
58+
59+
```
60+
GroveEncoder myEncoder(2, &myCallback);
61+
```
62+

0 commit comments

Comments
 (0)