Ren Buggy / RenBED_RGB_PWM

Dependencies:   mbed-renbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*********************************************************
00002 *RenBED_RGB_PWM                                          *
00003 *Author: Elijah Orr                                      *
00004 *                                                        *
00005 *A program that changes the colour of an RGB LED by      *
00006 *changing the duty cycle of PWM outputs to the colour    *
00007 *cathodes of the LED.                                    *  
00008 *********************************************************/
00009 
00010 /* include the mbed library made by mbed.org that contains 
00011 classes/functions designed to make programming mbed 
00012 microcontrollers easier */
00013 #include "mbed.h"
00014 
00015 /* Set up 3 pins as PWM out to control the colour
00016 cathodes of the RGB LED */
00017 PwmOut Red(PWM5);
00018 PwmOut Green(PWM7);
00019 PwmOut Blue(PWM6);
00020 
00021 /* the main function is where a program will begin to execute. */
00022 
00023 /****************************************************************
00024 * Function: main()                                              *
00025 *                                                               *
00026 * Sequences an RBG LED connected to the RenBED                  *
00027 *                                                               *
00028 * Inputs: none                                                  *
00029 *                                                               *
00030 * Returns: none                                                 *
00031 ****************************************************************/
00032 int main()
00033 {
00034     /* open a for loop with no parameters to start an infinite loop */
00035     for(;;){
00036         Red = 0.7;                  /* Duty cycle on red pin set to 70% so red is on 30% of the time */
00037         Green = 0.4;
00038         wait_ms(3000);              /* wait for 3000 ms (3 seconds) */
00039         Red = 1;                    /* Duty cycle set to 100% to turn red off */
00040         Blue = 0;                   /* Duty cycle set to 0% to turn blue fully on */  
00041         wait_ms(3000);
00042         Green = 1;
00043         wait_ms(3000);
00044         Red = Green = Blue = 1;
00045         wait_ms(3000);
00046         Blue = 0;
00047         wait_ms(3000);
00048     }
00049 }
00050         
00051