RGB Spectrum Fader. A nice RGB color spectrum cycling Demo
Fork of frdm_rgbled by
main.cpp@8:a6c27db26c21, 2014-05-30 (annotated)
- Committer:
- lasmahei
- Date:
- Fri May 30 14:34:49 2014 +0000
- Revision:
- 8:a6c27db26c21
- Parent:
- 7:a557f5584f83
- Child:
- 9:b0a76345f37c
RGB Spectrum Fader. A nice slow RGB Fader cycling all colors
Who changed what in which revision?
User | Revision | Line number | New 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 | r.period(0.01); |
lasmahei | 7:a557f5584f83 | 15 | g.period(0.01); |
lasmahei | 7:a557f5584f83 | 16 | b.period(0.01); |
chris | 1:eabc6f5b51d6 | 17 | |
lasmahei | 7:a557f5584f83 | 18 | while (true) |
lasmahei | 7:a557f5584f83 | 19 | { |
lasmahei | 7:a557f5584f83 | 20 | for (i=0; i<=colorRange; i++) |
lasmahei | 7:a557f5584f83 | 21 | { |
lasmahei | 7:a557f5584f83 | 22 | color = (1/colorRange)*i; |
lasmahei | 7:a557f5584f83 | 23 | |
lasmahei | 7:a557f5584f83 | 24 | if(color >= 0 && color <= 0.3333 ) { red = 0.3333-color; green = color; blue = 0; } |
lasmahei | 7:a557f5584f83 | 25 | if(color > 0.3333 && color <= 0.6666) { red = 0; green =0.6666-color; blue = color-0.3333; } |
lasmahei | 7:a557f5584f83 | 26 | if(color > 0.6666 && color <= 1) { red = color-0.6666; green = 0; blue = 1-color; } |
lasmahei | 7:a557f5584f83 | 27 | |
lasmahei | 7:a557f5584f83 | 28 | r=1-red; |
lasmahei | 7:a557f5584f83 | 29 | g=1-green; |
lasmahei | 7:a557f5584f83 | 30 | b=1-blue; |
lasmahei | 7:a557f5584f83 | 31 | |
lasmahei | 7:a557f5584f83 | 32 | wait(0.1); |
chris | 1:eabc6f5b51d6 | 33 | } |
chris | 1:eabc6f5b51d6 | 34 | } |
chris | 0:cf8a48b1fb23 | 35 | } |