Siobhan Duncan / Mbed 2 deprecated HamiltonCircleWorkshopLEDStrip

Dependencies:   PololuLedStrip mbed

Fork of LedStripRainbow by David Grayson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "PololuLedStrip.h"
00003 
00004 PololuLedStrip ledStrip(p13);
00005 
00006 #define LED_COUNT 20
00007 rgb_color colors[LED_COUNT];
00008 
00009 Timer timer;
00010 
00011 DigitalOut myled(LED1);
00012 
00013 // Converts a color from the HSV representation to RGB.
00014 rgb_color hsvToRgb(float h, float s, float v){
00015     int i = floor(h * 6);
00016     float f = h * 6 - i;
00017     float p = v * (1 - s);
00018     float q = v * (1 - f * s);
00019     float t = v * (1 - (1 - f) * s);
00020     float r = 0, g = 0, b = 0;
00021     switch(i % 6){
00022         case 0: r = v; g = t; b = p; break;
00023         case 1: r = q; g = v; b = p; break;
00024         case 2: r = p; g = v; b = t; break;
00025         case 3: r = p; g = q; b = v; break;
00026         case 4: r = t; g = p; b = v; break;
00027         case 5: r = v; g = p; b = q; break;
00028     }
00029     return (rgb_color){r * 255, g * 255, b * 255};
00030 }
00031 
00032 int main(){
00033     timer.start();
00034 
00035     myled = 1;
00036     
00037     while(1) {
00038 
00039             // Update the colors array.
00040     //        uint32_t time = timer.read_ms();   
00041         
00042             for(int i = 0; i < LED_COUNT; i++) {
00043                 //uint8_t phase = (time >> 4) - (i << 2);
00044     //            colors[i] = hsvToRgb(phase / 256.0, 1.0, 1.0);
00045                 colors[i] = (rgb_color){255, 0, 0};
00046             }
00047         
00048             // Send the colors to the LED strip.
00049             
00050             ledStrip.write(colors, LED_COUNT);
00051             wait(0.5);
00052     }
00053 }