RGB Spectrum Fader. A nice RGB color spectrum cycling Demo

Dependencies:   mbed

Fork of frdm_rgbled by Freescale

Committer:
lasmahei
Date:
Fri May 30 14:30:43 2014 +0000
Revision:
7:a557f5584f83
Parent:
5:14891bb08b35
Child:
8:a6c27db26c21
RGB Spectrum Fader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:cf8a48b1fb23 1 #include "mbed.h"
chris 0:cf8a48b1fb23 2
Kojto 5:14891bb08b35 3 PwmOut r(LED_RED);
Kojto 5:14891bb08b35 4 PwmOut g(LED_GREEN);
lasmahei 7:a557f5584f83 5 PwmOut b(LED_BLUE);
chris 0:cf8a48b1fb23 6
lasmahei 7:a557f5584f83 7 float color,red,green,blue;
lasmahei 7:a557f5584f83 8 float colorRange = 1024;
lasmahei 7:a557f5584f83 9 short unsigned i;
lasmahei 7:a557f5584f83 10
lasmahei 7:a557f5584f83 11 int main()
lasmahei 7:a557f5584f83 12 {
lasmahei 7:a557f5584f83 13
lasmahei 7:a557f5584f83 14
lasmahei 7:a557f5584f83 15 r.period(0.01);
lasmahei 7:a557f5584f83 16 g.period(0.01);
lasmahei 7:a557f5584f83 17 b.period(0.01);
chris 1:eabc6f5b51d6 18
lasmahei 7:a557f5584f83 19 while (true)
lasmahei 7:a557f5584f83 20 {
lasmahei 7:a557f5584f83 21 for (i=0; i<=colorRange; i++)
lasmahei 7:a557f5584f83 22 {
lasmahei 7:a557f5584f83 23 color = (1/colorRange)*i;
lasmahei 7:a557f5584f83 24
lasmahei 7:a557f5584f83 25 if(color >= 0 && color <= 0.3333 ) { red = 0.3333-color; green = color; blue = 0; }
lasmahei 7:a557f5584f83 26 if(color > 0.3333 && color <= 0.6666) { red = 0; green =0.6666-color; blue = color-0.3333; }
lasmahei 7:a557f5584f83 27 if(color > 0.6666 && color <= 1) { red = color-0.6666; green = 0; blue = 1-color; }
lasmahei 7:a557f5584f83 28
lasmahei 7:a557f5584f83 29 r=1-red;
lasmahei 7:a557f5584f83 30 g=1-green;
lasmahei 7:a557f5584f83 31 b=1-blue;
lasmahei 7:a557f5584f83 32
lasmahei 7:a557f5584f83 33 wait(0.1);
chris 1:eabc6f5b51d6 34 }
chris 1:eabc6f5b51d6 35 }
chris 0:cf8a48b1fb23 36 }