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

Committer:
isonno
Date:
Mon Feb 11 05:04:18 2013 +0000
Revision:
4:cfef06d8bb96
Parent:
3:0ac64c4ca40f
Minor changes to add backlight routines.  Not hooked up yet, shouldn't affect build operation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
isonno 0:6da5625a6946 1 //
isonno 0:6da5625a6946 2 // Tools for talking to the CuriLight string
isonno 0:6da5625a6946 3 //
isonno 0:6da5625a6946 4
isonno 0:6da5625a6946 5 #ifndef __LIGHTSTRING__
isonno 0:6da5625a6946 6 #define __LIGHTSTRING__
isonno 0:6da5625a6946 7
isonno 0:6da5625a6946 8 #ifndef MBED_H
isonno 0:6da5625a6946 9 #include "mbed.h"
isonno 0:6da5625a6946 10 #endif
isonno 0:6da5625a6946 11
isonno 0:6da5625a6946 12 #ifndef __LIGHTSNOOP__
isonno 0:6da5625a6946 13 #include "LightSnoop.h"
isonno 0:6da5625a6946 14 #endif
isonno 0:6da5625a6946 15
isonno 0:6da5625a6946 16 #include <vector>
isonno 0:6da5625a6946 17
isonno 0:6da5625a6946 18 class LightString
isonno 0:6da5625a6946 19 {
isonno 0:6da5625a6946 20 public:
isonno 0:6da5625a6946 21
isonno 0:6da5625a6946 22 // Note: We rely on the default serial configuration of 9600 8N1,
isonno 0:6da5625a6946 23 // this matches the CuriLights serial parameters.
isonno 3:0ac64c4ca40f 24 LightString( PinName pin, int numLights );
isonno 0:6da5625a6946 25
isonno 0:6da5625a6946 26 // This sends an initialization to the string and configures it.
isonno 0:6da5625a6946 27 // If numLights is non-zero, the length of the light string is reset
isonno 0:6da5625a6946 28 void InitLights( int numLights = 0 );
isonno 0:6da5625a6946 29
isonno 0:6da5625a6946 30 int GetNumLights() const { return fNumLights; }
isonno 0:6da5625a6946 31
isonno 0:6da5625a6946 32 // The light code uses a "decimal RGB" notation, where
isonno 0:6da5625a6946 33 // the color is specified as a three digit number, with each
isonno 0:6da5625a6946 34 // digit from 0..7. The first (hundreds) digit specifies
isonno 0:6da5625a6946 35 // red, the second (tens) digit specifies green, and
isonno 0:6da5625a6946 36 // the last (ones) blue. So, for example, "700" specifies
isonno 0:6da5625a6946 37 // red, and "755" is pink.
isonno 0:6da5625a6946 38
isonno 0:6da5625a6946 39 void SetAllLights( int color );
isonno 0:6da5625a6946 40
isonno 0:6da5625a6946 41 // Set a single light (id == the Nth light in the string, starting from zero)
isonno 0:6da5625a6946 42 void SetOneColor( int color, uint8_t id );
isonno 0:6da5625a6946 43
isonno 0:6da5625a6946 44 // Set each light to the value in the corresponding array.
isonno 0:6da5625a6946 45 void SetColors( const vector<int>& colorList );
isonno 0:6da5625a6946 46
isonno 0:6da5625a6946 47 void Off() { SetAllLights( 0 ); }
isonno 0:6da5625a6946 48
isonno 0:6da5625a6946 49 void Red() { SetAllLights( 700 ); }
isonno 0:6da5625a6946 50
isonno 0:6da5625a6946 51 void Green() { SetAllLights( 70 ); }
isonno 0:6da5625a6946 52
isonno 0:6da5625a6946 53 void Blue() { SetAllLights( 7 ); }
isonno 0:6da5625a6946 54
isonno 0:6da5625a6946 55 void Ouch() { SetAllLights( 777 ); }
isonno 0:6da5625a6946 56
isonno 3:0ac64c4ca40f 57 LightSnoop * Snoop() { return &fSnoop; }
isonno 0:6da5625a6946 58
isonno 3:0ac64c4ca40f 59 void FlushOutput() { HandleOutgoingData(); };
isonno 0:6da5625a6946 60
isonno 4:cfef06d8bb96 61 void Debug();
isonno 4:cfef06d8bb96 62
isonno 0:6da5625a6946 63 private:
isonno 0:6da5625a6946 64 void sendCommand1( uint8_t ch );
isonno 0:6da5625a6946 65 void sendCommand2( uint8_t ch1, uint8_t ch2 );
isonno 0:6da5625a6946 66 void sendCommand3( uint8_t ch1, uint8_t ch2, uint8_t ch3 );
isonno 0:6da5625a6946 67
isonno 3:0ac64c4ca40f 68 void HandleIncomingData();
isonno 3:0ac64c4ca40f 69 void HandleOutgoingData();
isonno 0:6da5625a6946 70
isonno 0:6da5625a6946 71 // Note the top red bit is stripped off to fit in the byte, other
isonno 0:6da5625a6946 72 // code must manually add it back to the top bit if the light ID
isonno 0:6da5625a6946 73 uint8_t colorByte( uint8_t r, uint8_t g, uint8_t b )
isonno 0:6da5625a6946 74 { return ((r & 3) << 6) | (g << 3) | b; }
isonno 0:6da5625a6946 75
isonno 0:6da5625a6946 76 uint8_t colorByte( int rgb, uint8_t& redBit )
isonno 0:6da5625a6946 77 { redBit = ((rgb / 100) >> 2) << 7;
isonno 0:6da5625a6946 78 return colorByte( rgb/100, (rgb % 100) / 10, rgb % 10 );
isonno 0:6da5625a6946 79 }
isonno 0:6da5625a6946 80
isonno 0:6da5625a6946 81 /* uint8_t color( unsigned char * rgb, uint8_t& redBit )
isonno 0:6da5625a6946 82 {
isonno 0:6da5625a6946 83 redBit = ((rgb[0] - '0') >> 2) << 7;
isonno 0:6da5625a6946 84 return color( rgb[0] - '0', rgb[1] - '0', rgb[2] - '0' );
isonno 0:6da5625a6946 85 }
isonno 0:6da5625a6946 86 */
isonno 3:0ac64c4ca40f 87 Serial fLightsPort;
isonno 0:6da5625a6946 88 Serial fUSBPort;
isonno 0:6da5625a6946 89 int fNumLights;
isonno 0:6da5625a6946 90 LightSnoop fSnoop;
isonno 3:0ac64c4ca40f 91 uint8_t fBuffer[384];
isonno 3:0ac64c4ca40f 92 int fBufferInPos;
isonno 3:0ac64c4ca40f 93 int fBufferOutPos;
isonno 0:6da5625a6946 94 };
isonno 0:6da5625a6946 95 #endif