An example program for driving an RGB LED

Dependencies:   mbed

Fork of Renbed_RGB_Digital by Miskin Project

Committer:
MiskinPrj
Date:
Tue Apr 19 13:35:15 2016 +0000
Revision:
1:56810f863198
Parent:
0:b4aa4b3a7cee
Child:
2:c936f86e62fb

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MiskinPrj 0:b4aa4b3a7cee 1 /*********************************************************
MiskinPrj 0:b4aa4b3a7cee 2 *Renbed_RGB_Digital *
MiskinPrj 0:b4aa4b3a7cee 3 *Author: Dan Argust *
MiskinPrj 0:b4aa4b3a7cee 4 * *
MiskinPrj 0:b4aa4b3a7cee 5 *A program that controls an RGB LED *
MiskinPrj 0:b4aa4b3a7cee 6 *********************************************************/
MiskinPrj 0:b4aa4b3a7cee 7
MiskinPrj 0:b4aa4b3a7cee 8 /* include the mbed library made by mbed.org that contains
MiskinPrj 0:b4aa4b3a7cee 9 classes/functions designed to make programming mbed
MiskinPrj 0:b4aa4b3a7cee 10 microcontrollers easier */
MiskinPrj 0:b4aa4b3a7cee 11 #include "mbed.h"
MiskinPrj 0:b4aa4b3a7cee 12
MiskinPrj 0:b4aa4b3a7cee 13 /* Set up 3 pins as digital out to control the colour
MiskinPrj 0:b4aa4b3a7cee 14 cathodes of the RGB LED */
MiskinPrj 1:56810f863198 15 DigitalOut Red(P1_24);
MiskinPrj 1:56810f863198 16 DigitalOut Green(P1_26);
MiskinPrj 1:56810f863198 17 DigitalOut Blue(P0_19);
MiskinPrj 0:b4aa4b3a7cee 18
MiskinPrj 0:b4aa4b3a7cee 19 int on = 0;
MiskinPrj 0:b4aa4b3a7cee 20 int off = 1;
MiskinPrj 0:b4aa4b3a7cee 21
MiskinPrj 0:b4aa4b3a7cee 22 int main()
MiskinPrj 0:b4aa4b3a7cee 23 {
MiskinPrj 0:b4aa4b3a7cee 24 /* open a for loop with no parameters to start an infinite loop */
MiskinPrj 0:b4aa4b3a7cee 25 for(;;){
MiskinPrj 0:b4aa4b3a7cee 26 Red = off;
MiskinPrj 0:b4aa4b3a7cee 27 Blue = off;
MiskinPrj 0:b4aa4b3a7cee 28 Green = off;
MiskinPrj 0:b4aa4b3a7cee 29 wait_ms(1000);
MiskinPrj 0:b4aa4b3a7cee 30
MiskinPrj 0:b4aa4b3a7cee 31 Red = on;
MiskinPrj 0:b4aa4b3a7cee 32 wait_ms(1000);
MiskinPrj 0:b4aa4b3a7cee 33
MiskinPrj 0:b4aa4b3a7cee 34 Red = off;
MiskinPrj 0:b4aa4b3a7cee 35 Green = on;
MiskinPrj 0:b4aa4b3a7cee 36 wait_ms(1000);
MiskinPrj 0:b4aa4b3a7cee 37
MiskinPrj 0:b4aa4b3a7cee 38 Green = off;
MiskinPrj 0:b4aa4b3a7cee 39 Blue = on;
MiskinPrj 0:b4aa4b3a7cee 40 wait_ms(1000);
MiskinPrj 0:b4aa4b3a7cee 41 }
MiskinPrj 0:b4aa4b3a7cee 42 }
MiskinPrj 0:b4aa4b3a7cee 43
MiskinPrj 0:b4aa4b3a7cee 44