https://github.com/seeed-studio/seeed_arduino_rotaryencoder
This RotaryEncoder Library gives an example to control the Grove Encoder and create the callback function.
https://github.com/seeed-studio/seeed_arduino_rotaryencoder
arduino arduino-library grove rotaryencoder
Last synced: 5 months ago
JSON representation
This RotaryEncoder Library gives an example to control the Grove Encoder and create the callback function.
- Host: GitHub
- URL: https://github.com/seeed-studio/seeed_arduino_rotaryencoder
- Owner: Seeed-Studio
- License: other
- Created: 2019-11-28T10:30:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-08T08:16:33.000Z (over 1 year ago)
- Last Synced: 2025-04-07T11:23:33.289Z (over 1 year ago)
- Topics: arduino, arduino-library, grove, rotaryencoder
- Language: C++
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 13
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Seeed_Arduino_RotaryEncoder [](https://travis-ci.com/Seeed-Studio/Seeed_Arduino_RotaryEncoder)
### Introduction
This library support Encoder.
Connect the Encoder to the D2 and D3 pins of the motherboard.You can use other pins if you want.
### Usage
1.git clone this resp to your Arduino IDE'S libraries directory.
2.Run the demo "encoderTest" on examples directory.
### Software usage
- Install Seeed Arduino RotaryEncoder library to Arduino.
- Start a project.
- Create the callback function and set the Encoder pin.(just set SIGA.SIGB pin is equal to SIGA pin plus 1.)
Usage of the library, see Example encoderTest
1. Add headers
```
#include "GroveEncoder.h"
```
2. Create the callback function.The callback function gets the current Angle and the status of the button press.
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.
```
int value = 0;
int bt_flag = 0;
void myCallback(int newValue, bool flag) {
if(value != newValue)
{
value = newValue;
Serial.print(newValue, HEX);
Serial.print("\n");
}
if(flag && bt_flag)
{
Serial.println("button");
bt_flag = 0;
}
}
```
```
while(1)
{
Serial.println(myEncoder.getValue());
delay(100);
bt_flag = 1;
}
```
3. Initialize the Encoder.The parameters are the SIGA pin and the callback function name, respectively.
```
GroveEncoder myEncoder(2, &myCallback);
```