RGB RingCoder is a breakout board, a circular LED containing 16 LEDs arranged in a ring, and a rotary encoder. The encoder contains an RGB LED as well as a push button function.
The device requires 11 pins, 3 of which must be PWM-capable (for the RGB LEDs).
upm::RGBRingCoder ringCoder(4, 10, 11, 2, 9, 7, 12, 13, 3, 5, 6);
uint16_t spin = 0x0001;
bool oldState = false;
int oldPos = 0;
ringCoder.setRGBLED(0.99, 0.01, 0.99);
while (shouldRun) {
if (spin == 0)
spin = 0x0001;
ringCoder.setRingLEDS(spin);
spin <<= 1;
bool bstate = ringCoder.getButtonState();
if (bstate != oldState) {
cout << "Button state changed from " << oldState << " to " << bstate << endl;
oldState = bstate;
}
int epos = ringCoder.getEncoderPosition();
if (epos != oldPos) {
cout << "Encoder position changed from " << oldPos << " to " << epos << endl;
oldPos = epos;
}
upm_delay_us(100000);
}