LED Demo for Tech Con 2014

Dependencies:   EthernetInterface PololuLedStripx mbed-rtos mbed nanoservice_client_1_12_X

Fork of LPC1768_LWM2M_Client by MBED_DEMOS

Revision:
2:4166c3e5b321
Parent:
1:09a525977925
Child:
3:e3aa908cbb51
--- a/main.cpp	Sat Sep 27 21:53:28 2014 +0000
+++ b/main.cpp	Sat Sep 27 23:58:43 2014 +0000
@@ -5,6 +5,12 @@
 // Include resources
 #include "light.h"
 
+#include "PololuLedStrip.h"
+PololuLedStrip ledStrip(P0_4);
+#define LED_COUNT 60
+//#define LED_COUNT 120
+rgb_color colors[LED_COUNT];
+
 Serial pc(USBTX, USBRX); // tx, rx
 
 // ****************************************************************************
@@ -95,8 +101,8 @@
     memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s));
 
     // Static resources
-    nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0,  (uint8_t*) "Sensinode", sizeof("Sensinode")-1);
-    nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0,  (uint8_t*) "NSDL-C mbed device", sizeof("NSDL-C mbed device")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("dev/mfg")-1, (uint8_t*) "dev/mfg", 0, 0,  (uint8_t*) "ARMDEMO", sizeof("ARMDEMO")-1);
+    nsdl_create_static_resource(resource_ptr, sizeof("dev/mdl")-1, (uint8_t*) "dev/mdl", 0, 0,  (uint8_t*) "LED-STRIP", sizeof("LED-STRIP")-1);
 
     // Dynamic resources
     create_light_resource(resource_ptr);
@@ -114,11 +120,47 @@
     return 1;
 }
 
+void set_led_color(char *color_string)
+{
+static uint8_t red, green, blue, index ;
+int color_int ;
+int num ;
+
+    //pc.printf("set_led_color: %s\r\n", color_string);
+    // convert string to uint8 tuple
+    num = sscanf(color_string, "%X", &color_int);
+    //pc.printf("color_int: %d %x\r\n", num, color_int);
+    
+    index = color_int & 255;
+    blue = color_int >> 8 & 255;
+    green = color_int >> 16 & 255;
+    red = color_int >> 24 & 255;
+    
+    //pc.printf("index: %x\r\n", index);
+    //pc.printf("red: %x\r\n", red);
+    //pc.printf("green: %x\r\n", green);
+    //pc.printf("blue: %x\r\n", blue);
+    
+    if(index > 0 and index <= LED_COUNT)
+    {
+        colors[index-1] = (rgb_color) {red,green,blue} ;
+        ledStrip.write(colors, LED_COUNT);
+    }
+    else if(index == 0)
+    {
+        for(int i = 0; i < LED_COUNT; i++)
+            colors[i] = (rgb_color) {red,green,blue} ;
+        ledStrip.write(colors, LED_COUNT);
+    }    
+}
+
+
 // ****************************************************************************
 // Program entry point
 
 int main()
 {
+
     NSDL_DEBUG("mbed NanoService Example App 0.1\n");
     
     // Initialize Ethernet interface first