Example program to sweep the RGB LED through various colours using PWM

Dependencies:   mbed

Fork of app-board-RGB by Chris Styles

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut r (D5);
00004 PwmOut g (D8);
00005 PwmOut b (D9);
00006 
00007 int main()
00008 {
00009     r.period(0.001);
00010     while(1) {
00011         for(float i = 0.0; i < 1.0 ; i += 0.001) {
00012             float p = 3 * i;
00013             r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0);
00014             g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p);
00015             b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0);  ;  
00016             wait (0.01);
00017         }
00018     }
00019 }