Example program for the Seeed Studio Grove RGB Chainable LED's.

Dependencies:   Chainable_RGB_LED mbed

Fork of be_colorful by Yihui Xiong

Revision:
2:4dae2f80828e
Parent:
1:10700868060f
--- a/main.cpp	Wed Oct 16 05:39:07 2013 +0000
+++ b/main.cpp	Wed Mar 11 22:27:35 2015 +0000
@@ -1,72 +1,25 @@
 #include "mbed.h"
 #include "ChainableLED.h"
 
-//#define DEBUG
-
-#ifdef DEBUG
-
-#include "USBSerial.h"
-#define LOG(args...)        pc.printf(args)
-USBSerial pc;
-
-#else
-
-#define LOG(args...)
-
-#endif  // DEBUG
-
+#define NUM_LED 3
 
 // ChainableLED(clk, data, number_of_leds)
-ChainableLED color_led(P1_14, P1_13, 1);
-AnalogIn thermistor(P0_12);
+ChainableLED color_led(D6, D7, NUM_LED);
 
-float get_temperature()
-{
-    unsigned int a, beta = 3975;
-    float temperature, resistance;
-    
-    a = thermistor.read_u16();
-    
-    /* Calculate the resistance of the thermistor from analog votage read. */
-    resistance = (float) 10000.0 * ((65536.0 / a) - 1);
-    
-    /* Convert the resistance to temperature using Steinhart's Hart equation */
-    temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15; 
-    
-    return temperature;
-}
-
-int temperature2color(float t)
+int main()
 {
-    float low  = 26;
-    float high = 30;
-    int   min = 0;
-    int   max = 255;
-    int   color;
-    
-    if (t < low) {
-        color = min;
-    } else if (t > high) {
-        color = max;
-    } else {
-        color = min + (max - min) * ((t - min) / (max - min));
-    }
-    
-    return color;
-}
-    
+    uint8_t index = 0;
+    while(1) {
+        // generate random RGB values for LED's
+        uint8_t R = rand();
+        uint8_t G = rand();
+        uint8_t B = rand();
+        // print message to terminal
+        printf("index = %d, R=%x,G=%x,B=%x,",index,R,G,B);
 
-int main() {
-  
-    while(1) {
-        float t = get_temperature();
-        uint8_t color = temperature2color(t);
-        
-        LOG("Temperature: %f\r\n", t);
-        LOG("Color: %d\r\n", color);
-        
         // ChainableLED.setColorRGB(index_of_led, red, green, blue)
-        color_led.setColorRGB(0, color, 0xFF - color, 0);
+        color_led.setColorRGB(index++, R, G, B);    // increase brightness cascade down chain of LED's
+        index = ((index+1) % NUM_LED);              // cycle through LED's
         wait(0.05);
     }
 }