Cheerlights client using WiFiDIPCortex and WS2801 RGB LED strip
Dependencies: Adafruit_WS2801 HTTPClient cc3000_hostdriver_mbedsocket mbed
Diff: main.cpp
- Revision:
- 1:40027344b249
- Parent:
- 0:98d83f5b309f
- Child:
- 3:7410e3231e7a
--- a/main.cpp Tue Feb 11 21:30:21 2014 +0000 +++ b/main.cpp Wed Feb 12 22:18:52 2014 +0000 @@ -85,8 +85,11 @@ // DigitalIn SCButton(P1_31); -PinName dataPin(P1_28); // Yellow wire on Adafruit Pixels -PinName clockPin(P0_7); // Green wire on Adafruit Pixels +// For Bit-Banging SPI use Pins 40 and 39 +PinName dataPin(p40); // PIN 40 - Yellow wire on Adafruit Pixels +PinName clockPin(p39); // PIN 39 - Green wire on Adafruit Pixels + +// For hardware SPI use Pin 16 for Data and pin 13 for Clk /* cc3000 module declaration specific for user's board. Check also init() */ #if (MY_BOARD == WIGO) @@ -117,7 +120,7 @@ uint32_t lastColour = 0; // Set the first variable to the number of rows, the second to number of pixels. 32 = 32 pixels in a row -Adafruit_WS2801 strip = Adafruit_WS2801(1,32, dataPin, clockPin); +Adafruit_WS2801 strip = Adafruit_WS2801(32, dataPin, clockPin); // Setup the colour table and mappings #define NUM_COLOURS 12 @@ -125,16 +128,16 @@ char name[12]; uint32_t value; } colTable[NUM_COLOURS] = { - { "red", 0xFF0000 }, + { "red", 0xff0000 }, { "green", 0x008000 }, - { "blue", 0x0000FF }, - { "cyan", 0x00FFFF }, - { "white", 0xFFFFFF }, - { "warmwhite", 0xFDF5E6 }, + { "blue", 0x0000ff }, + { "cyan", 0x00ffff }, + { "white", 0xffffff }, + { "warmwhite", 0xfdf5e6 }, { "purple", 0x800080 }, - { "magenta", 0xFF00FF }, - { "yellow", 0xFFFF00 }, - { "orange", 0xFFA500 }, + { "magenta", 0xff00ff }, + { "yellow", 0xffff00 }, + { "orange", 0xffa500 }, { "pink", 0xff69b4 }, { "oldlace", 0xfd5e56 } }; @@ -207,10 +210,15 @@ for( int i=0; i < NUM_COLOURS; i++ ) { if( strncmp( colTable[i].name, colStr, strlen(colTable[i].name) ) == 0 ) { - for (int n=0; n < strip.numPixels(); n++) { - strip.setPixelColor(n, colTable[i].value); - strip.show(); - wait_ms(50); + if( colTable[i].value != lastColour ) { + for (int n=0; n < strip.numPixels(); n++) { + strip.setPixelColor(n, colTable[i].value); + strip.show(); + wait_ms(100); + } + lastColour = colTable[i].value; + } else { + uart.printf("Same as previous colour\r\n"); } return; } @@ -228,6 +236,8 @@ //GET data uart.printf("\r\nTrying to fetch page...\r\n"); int ret = http.get("http://api.thingspeak.com/channels/1417/field/1/last.txt", str, 128); + // Just a local test url, saves having to tweet the cheerlights colour every time +// int ret = http.get("http://192.168.1.3/last.txt", str, 128); if (!ret) { uart.printf("Page fetched successfully - read %d characters\r\n", strlen(str)); uart.printf("Result: %s\r\n", str); @@ -256,6 +266,8 @@ LPC_SYSCON->SYSAHBCLKCTRL |= (0x1 << 26); uart.baud(SERIAL_BAUD_RATE); + + strip.updatePins(); // Switch to Hardware SPI strip.begin();