An example program that drives an RGB LED using PWM outputs

Dependencies:   mbed

Fork of Renbed_RGB_PWM by Miskin Project

Files at this revision

API Documentation at this revision

Comitter:
MiskinPrj
Date:
Tue Apr 19 14:43:19 2016 +0000
Child:
1:a8629ebf85a5
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Apr 19 14:43:19 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f
\ No newline at end of file