Ren Buggy / RenBED_RGB

Dependencies:   mbed-renbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*********************************************************
00002 *RenBED_RGB                                              *
00003 *Author: Elijah Orr                                      *
00004 *                                                        *  
00005 *A program that cycles through the 9 different states    *
00006 *(including off) of a common anode RGB LED that are      *
00007 *available via digital pin control.                      *
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 digital out to control the colour
00016 cathodes of the RGB LED */
00017 DigitalOut Red(p18);
00018 DigitalOut Green(p20);
00019 DigitalOut Blue(p19);
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;                    /* As we are controlling colour cathodes, we must pull the pin low to turn on the colour */
00037         wait_ms(1000);
00038         Blue = 0;                   /* Colours are combined by switching multiple colour pins on at once */
00039         wait_ms(1000);
00040         Red = 1;                    /* Pull the red pin high to switch it off */
00041         wait_ms(1000);
00042         Green = 0;
00043         wait_ms(1000);
00044         Blue = 1;
00045         wait_ms(1000);
00046         Red = 0;
00047         wait_ms(1000);
00048         Red = 1;
00049         Blue = 0;
00050         wait_ms(1000);
00051         Red = 0;
00052         wait_ms(1000);
00053         Red = Blue = Green = 1;     /* Switch off all colours */
00054         wait_ms(1000);
00055     }
00056 }
00057         
00058