A project to enable the Grove Encoder v1.2 hardware to work simply on Arduino. You can find information about the Grove Encoder here. The library included by the manufacturer didn't run on my Arduino101, so I wrote this new one from scratch.
- Arduino101/Genuino101
- Grove Shield and a cable
- Grove Rotary Encoder v1.2
- Put the Grove Kit Shield in the Arduino101
- Plug one side of the cable into the D7 port on the Grove Shield
- Plug the other side of the cable into the Grove Rotary Encoder v1.2
- You're done! Power it on and start programming.
Download the ZIP and install using the Arduino IDE. Alternative installation instructions may be found here.
The GroveEncoder library makes it possible to read the value off of an encoder. When the knob is turned clockwise, the value will increment. When the knob is turned counterclockwise, the number will decrement. This value is a 32 bit signed integer.
You can use this library via polling, or attach an interrupt handler if you're an advanced user. Please see the examples directory.
Simply create a GroveEncoder object and pass NULL as the second parameter.
#include <GroveEncoder.h>
void loop() {
GroveEncoder myEncoder(7, NULL);
while (1)
{
int value = myEncoder.getValue();
// getValue returns the number currently on the encoder.
Serial.print(value, HEX);
}
}
Create a GroveEncoder object and pass it a pin as well as a callback.
#include <GroveEncoder.h>
void myCallback(int newValue) {
Serial.print(newValue, HEX);
Serial.print("\n");
}
void loop() {
// Create a GroveEncoder
GroveEncoder myEncoder(7, &myCallback);
while (1)
{
// do something else
}
}
- Currently you can only use one GroveEncoder per platform.
- This has only been tested on Arduino101. However, I haven't done anything specifically to prevent this from working on other Arduino versions.
See LICENSE.