Example program to cycle the RGB LED on the mbed application board through all colours

Dependencies:   mbed

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 (p23);
00004 PwmOut g (p24);
00005 PwmOut b (p25);
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 }