upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

API for the SparkFun* RGB RingCoder. More...

Detailed Description

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).

rgbringcoder.jpg
// There are a lot of pins to hook up. These pins are valid for the
// Edison board, but may need to be adjusted for other platforms.
// In order:
// enable - 4
// latch - 10
// clear - 11
// clock - 2
// data - 9
// switch - 7
// red pwm - 3
// green pwm - 5
// blue pwm - 6
// encA - 12
// encB - 13
upm::RGBRingCoder ringCoder(4, 10, 11, 2, 9, 7, 12, 13, 3, 5, 6);
uint16_t spin = 0x0001;
bool oldState = false;
int oldPos = 0;
// Lets go green
ringCoder.setRGBLED(0.99, 0.01, 0.99);
while (shouldRun) {
// you spin me round...
if (spin == 0)
spin = 0x0001;
ringCoder.setRingLEDS(spin);
spin <<= 1;
// check button state
bool bstate = ringCoder.getButtonState();
if (bstate != oldState) {
cout << "Button state changed from " << oldState << " to " << bstate << endl;
oldState = bstate;
}
// check encoder position
int epos = ringCoder.getEncoderPosition();
if (epos != oldPos) {
cout << "Encoder position changed from " << oldPos << " to " << epos << endl;
oldPos = epos;
}
upm_delay_us(100000);
}

Public Member Functions

 RGBRingCoder (int en, int latch, int clear, int clk, int dat, int sw, int encA, int encB, int red, int green, int blue)
 
 ~RGBRingCoder ()
 
void setRingLEDS (uint16_t bits)
 
bool getButtonState ()
 
int getEncoderPosition ()
 
void clearEncoderPosition ()
 
void setRGBLED (float r, float g, float b)
 

Constructor & Destructor Documentation

RGBRingCoder ( int  en,
int  latch,
int  clear,
int  clk,
int  dat,
int  sw,
int  encA,
int  encB,
int  red,
int  green,
int  blue 
)

RGBRingCoder constructor

Parameters
enEnables GPIO
latchLatch GPIO
clearClears GPIO
clkClock GPIO
datData out GPIO
swPush button switch GPIO
encAEncoder A GPIO
encBEncoder B GPIO
redRGB red LED PWM
greenRGB green LED PWM
blueRGB blue LED PWM

RGBRingCoder destructor

Here is the call graph for this function:

Member Function Documentation

bool getButtonState ( )

Returns the state of the button

Returns
True if the button is pressed, false otherwise
void clearEncoderPosition ( )
inline

Sets the encoder counter to 0

Here is the call graph for this function:

void setRGBLED ( float  r,
float  g,
float  b 
)

Sets the intensity of the red, green, and blue LEDs. Values can be between 0.0 and 1.0. Lower is brighter, higher is dimmer.

Parameters
rRed value; valid values are 0.0-1.0
gGreen value; valid values are 0.0-1.0
bBlue value; valid values are 0.0-1.0

Here is the caller graph for this function:


The documentation for this class was generated from the following files: