Source code for the Curilights Controller. See http://www.saccade.com/writing/projects/CuriController/ for details.

Dependencies:   FatFileSystem mbed

This is the source code for the Curilights controller. This lets you interactively control a string of Curilights. It provides a simple click-wheel user interface for changing colors, brightness and behavior. It responds to movement and lighting.

Finished Controller

/media/uploads/isonno/nxp3872_controllerclose.jpg

System Block Diagram

/media/uploads/isonno/blockdiagram.png

RGBLED.h

Committer:
isonno
Date:
2013-02-11
Revision:
4:cfef06d8bb96
Parent:
3:0ac64c4ca40f

File content as of revision 4:cfef06d8bb96:

//
// RGBLED - Control the RGB LED on the Sparkfun display breakout board
///

#ifndef __RGBLED__
#define __RGBLED__

const float kLEDPWMTable[8] = { 0, 0.01, 0.02, 0.046, 0.1, 0.215, 0.464, 1.0 };

class RGBLED
{
public:
    RGBLED( PinName r, PinName g, PinName b )
        : fRedPWM( r ), fGrnPWM( g ), fBluPWM( b )
    {
        fRedPWM = 1.0;
        fGrnPWM = 1.0;
        fBluPWM = 1.0;
        fRGBValue = 0;
    }
    
    // We use the same "777" RGB values the CuriLights use
    void Set( int rgb )
    {
        if (rgb == fRGBValue)
            return;         // No change
            
        fRGBValue = rgb;
        
        int red = rgb / 100;
        int grn = rgb % 100 / 10;
        int blu = rgb % 10;
                
        fRedPWM = 1.0 - kLEDPWMTable[red];
        fGrnPWM = 1.0 - kLEDPWMTable[grn];
        fBluPWM = 1.0 - kLEDPWMTable[blu];
        
//        printf("RGB: %d, %f %f %f\r\n", rgb, 1.0 - kLEDPWMTable[red], 1.0 - kLEDPWMTable[grn], 1.0 - kLEDPWMTable[blu] );
    }
    
private:
    PwmOut fRedPWM, fGrnPWM, fBluPWM;
    int fRGBValue;
};

// Defined in main for now.
extern RGBLED gDebugLED;

#endif