RGB Spectrum Fader. A nice RGB color spectrum cycling Demo
Fork of frdm_rgbled by
main.cpp@9:b0a76345f37c, 2014-11-19 (annotated)
- Committer:
- lasmahei
- Date:
- Wed Nov 19 14:34:11 2014 +0000
- Revision:
- 9:b0a76345f37c
- Parent:
- 8:a6c27db26c21
Added Bit resolution setting and improved overall brightness
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 | 9:b0a76345f37c | 8 | unsigned int colorRes = 10; // Bit |
lasmahei | 9:b0a76345f37c | 9 | float colorRange = 1; |
lasmahei | 9:b0a76345f37c | 10 | unsigned int colorInt; |
lasmahei | 9:b0a76345f37c | 11 | unsigned int i; |
lasmahei | 7:a557f5584f83 | 12 | |
lasmahei | 7:a557f5584f83 | 13 | int main() |
lasmahei | 7:a557f5584f83 | 14 | { |
lasmahei | 9:b0a76345f37c | 15 | for(i=1; i<=colorRes; i++) colorRange = colorRange*2; |
lasmahei | 9:b0a76345f37c | 16 | |
lasmahei | 9:b0a76345f37c | 17 | r.period_ms(10); |
lasmahei | 9:b0a76345f37c | 18 | g.period_ms(10); |
lasmahei | 9:b0a76345f37c | 19 | b.period_ms(10); |
chris | 1:eabc6f5b51d6 | 20 | |
lasmahei | 7:a557f5584f83 | 21 | while (true) |
lasmahei | 7:a557f5584f83 | 22 | { |
lasmahei | 9:b0a76345f37c | 23 | for (colorInt=0; colorInt <= colorRange; colorInt++) |
lasmahei | 9:b0a76345f37c | 24 | { |
lasmahei | 9:b0a76345f37c | 25 | color = (1/colorRange)*colorInt; |
lasmahei | 9:b0a76345f37c | 26 | if(colorInt >= 0 && colorInt <= colorRange/3 ) { red = 1-(color*3); green = color*3; blue = 0; } |
lasmahei | 9:b0a76345f37c | 27 | if(colorInt > colorRange/3 && colorInt <= 2*colorRange/3) { red = 0; green = 2-(color*3); blue = (color*3)-1; } |
lasmahei | 9:b0a76345f37c | 28 | if(colorInt > 2*colorRange/3 && colorInt <= colorRange) { red = (color*3)-2; green = 0; blue = (1-color)*3; } |
lasmahei | 7:a557f5584f83 | 29 | r=1-red; |
lasmahei | 7:a557f5584f83 | 30 | g=1-green; |
lasmahei | 7:a557f5584f83 | 31 | b=1-blue; |
lasmahei | 9:b0a76345f37c | 32 | wait_ms(100); |
chris | 1:eabc6f5b51d6 | 33 | } |
chris | 1:eabc6f5b51d6 | 34 | } |
chris | 0:cf8a48b1fb23 | 35 | } |