An example program that drives an RGB LED using PWM outputs

Dependencies:   mbed

Fork of Renbed_RGB_PWM by Miskin Project

main.cpp

Committer:
MiskinPrj
Date:
2016-04-20
Revision:
1:a8629ebf85a5
Parent:
0:2e9f6df87dde

File content as of revision 1:a8629ebf85a5:

/*********************************************************
*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);
        }
    }
}