upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
RGBRingCoder Class Reference

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 =
new upm::RGBRingCoder(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;
}
usleep(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


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