An example program that drives an RGB LED using PWM outputs

Dependencies:   mbed

Fork of Renbed_RGB_PWM by Miskin Project

Revision:
0:2e9f6df87dde
Child:
1:a8629ebf85a5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Apr 19 14:43:19 2016 +0000
@@ -0,0 +1,63 @@
+/*********************************************************
+*Renbed_RGB_PWM                                      *
+*Author: Dan Argust                                      *
+*                                                        *  
+*A program that controls an RGB LED                      *
+*********************************************************/
+
+/* include the mbed library made by mbed.org that contains 
+classes/functions designed to make programming mbed 
+microcontrollers easier */
+#include "mbed.h"
+
+/* Set up 3 pins as pwm out to control the colour
+cathodes of the RGB LED */
+PwmOut Red(P1_24);
+PwmOut Green(P1_26);
+PwmOut Blue(P0_19);
+
+int main()
+{
+    Red = Blue = Green = 0;
+    float increment = 0.1;
+    
+    for(;;)
+    {
+        for(int i=0;i<10;i++)
+        {
+            Green = Green + increment;
+            wait(increment);
+        }
+        for(int i=0;i<10;i++)
+        {
+            Red = Red + increment;
+            wait(increment);
+        }
+        for(int i=0;i<10;i++)
+        {
+            Green = Green - increment;
+            wait(increment);
+        }
+        for(int i=0;i<10;i++)
+        {
+            Blue = Blue + increment;
+            wait(increment);
+        }
+        for(int i=0;i<10;i++)
+        {
+            Red = Red - increment;
+            wait(increment);
+        }
+        for(int i=0;i<10;i++)
+        {
+            Green = Green + increment;
+            wait(increment);
+        }
+        for(int i=0;i<10;i++)
+        {
+            Blue = Blue - increment;
+            Green = Green - increment;
+            wait(increment);
+        }
+    }
+}
\ No newline at end of file