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
System Block Diagram
RGBLED.h@0:6da5625a6946, 2011-12-29 (annotated)
- Committer:
- isonno
- Date:
- Thu Dec 29 01:59:53 2011 +0000
- Revision:
- 0:6da5625a6946
- Child:
- 3:0ac64c4ca40f
Contest submission version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
isonno |
0:6da5625a6946 | 1 | // |
isonno |
0:6da5625a6946 | 2 | // RGBLED - Control the RGB LED on the Sparkfun display breakout board |
isonno |
0:6da5625a6946 | 3 | /// |
isonno |
0:6da5625a6946 | 4 | |
isonno |
0:6da5625a6946 | 5 | #ifndef __RGBLED__ |
isonno |
0:6da5625a6946 | 6 | #define __RGBLED__ |
isonno |
0:6da5625a6946 | 7 | |
isonno |
0:6da5625a6946 | 8 | const float kLEDPWMTable[8] = { 0, 0.01, 0.02, 0.046, 0.1, 0.215, 0.464, 1.0 }; |
isonno |
0:6da5625a6946 | 9 | |
isonno |
0:6da5625a6946 | 10 | class RGBLED |
isonno |
0:6da5625a6946 | 11 | { |
isonno |
0:6da5625a6946 | 12 | public: |
isonno |
0:6da5625a6946 | 13 | RGBLED( PinName r, PinName g, PinName b ) |
isonno |
0:6da5625a6946 | 14 | : fRedPWM( r ), fGrnPWM( g ), fBluPWM( b ) |
isonno |
0:6da5625a6946 | 15 | { |
isonno |
0:6da5625a6946 | 16 | fRedPWM = 1.0; |
isonno |
0:6da5625a6946 | 17 | fGrnPWM = 1.0; |
isonno |
0:6da5625a6946 | 18 | fBluPWM = 1.0; |
isonno |
0:6da5625a6946 | 19 | fRGBValue = 0; |
isonno |
0:6da5625a6946 | 20 | } |
isonno |
0:6da5625a6946 | 21 | |
isonno |
0:6da5625a6946 | 22 | // We use the same "777" RGB values the CuriLights use |
isonno |
0:6da5625a6946 | 23 | void Set( int rgb ) |
isonno |
0:6da5625a6946 | 24 | { |
isonno |
0:6da5625a6946 | 25 | if (rgb == fRGBValue) |
isonno |
0:6da5625a6946 | 26 | return; // No change |
isonno |
0:6da5625a6946 | 27 | |
isonno |
0:6da5625a6946 | 28 | fRGBValue = rgb; |
isonno |
0:6da5625a6946 | 29 | |
isonno |
0:6da5625a6946 | 30 | int red = rgb / 100; |
isonno |
0:6da5625a6946 | 31 | int grn = rgb % 100 / 10; |
isonno |
0:6da5625a6946 | 32 | int blu = rgb % 10; |
isonno |
0:6da5625a6946 | 33 | |
isonno |
0:6da5625a6946 | 34 | fRedPWM = 1.0 - kLEDPWMTable[red]; |
isonno |
0:6da5625a6946 | 35 | fGrnPWM = 1.0 - kLEDPWMTable[grn]; |
isonno |
0:6da5625a6946 | 36 | fBluPWM = 1.0 - kLEDPWMTable[blu]; |
isonno |
0:6da5625a6946 | 37 | |
isonno |
0:6da5625a6946 | 38 | printf("RGB: %d, %f %f %f\r\n", rgb, 1.0 - kLEDPWMTable[red], 1.0 - kLEDPWMTable[grn], 1.0 - kLEDPWMTable[blu] ); |
isonno |
0:6da5625a6946 | 39 | } |
isonno |
0:6da5625a6946 | 40 | |
isonno |
0:6da5625a6946 | 41 | private: |
isonno |
0:6da5625a6946 | 42 | PwmOut fRedPWM, fGrnPWM, fBluPWM; |
isonno |
0:6da5625a6946 | 43 | int fRGBValue; |
isonno |
0:6da5625a6946 | 44 | }; |
isonno |
0:6da5625a6946 | 45 | |
isonno |
0:6da5625a6946 | 46 | #endif |
isonno |
0:6da5625a6946 | 47 |