Control LED brightness using PmwOut command.

Dependencies:   TextLCD mbed

Committer:
bromand
Date:
Sun Jun 26 23:20:35 2011 +0000
Revision:
0:a79722dcd2a0
First revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bromand 0:a79722dcd2a0 1 //Include mbed header file which contains the definition of DigitalOut class.
bromand 0:a79722dcd2a0 2 #include "mbed.h"
bromand 0:a79722dcd2a0 3 //Include TextLCD header file which contains the definition of TextLCD class.
bromand 0:a79722dcd2a0 4 #include "TextLCD.h"
bromand 0:a79722dcd2a0 5
bromand 0:a79722dcd2a0 6 //Initialize PwmOut memebers
bromand 0:a79722dcd2a0 7 PwmOut led1(LED1);
bromand 0:a79722dcd2a0 8 PwmOut led4(LED4);
bromand 0:a79722dcd2a0 9 //Initialize TextLCD with the correct pins
bromand 0:a79722dcd2a0 10 TextLCD lcd(p24, p26, p27, p28, p29, p30);
bromand 0:a79722dcd2a0 11
bromand 0:a79722dcd2a0 12 //This function will handle the print to LCD
bromand 0:a79722dcd2a0 13 void PrintToLCD()
bromand 0:a79722dcd2a0 14 {
bromand 0:a79722dcd2a0 15 //Clear the LCD display
bromand 0:a79722dcd2a0 16 lcd.cls();
bromand 0:a79722dcd2a0 17 //Locate Row 0 Column 0 in the LCD display
bromand 0:a79722dcd2a0 18 lcd.locate(0, 0);
bromand 0:a79722dcd2a0 19 //Print my name
bromand 0:a79722dcd2a0 20 lcd.printf("DANIEL BROMAND");
bromand 0:a79722dcd2a0 21 //Locate Row 1 Column 0 in the LCD display
bromand 0:a79722dcd2a0 22 lcd.locate(0, 1);
bromand 0:a79722dcd2a0 23 //Print my name
bromand 0:a79722dcd2a0 24 lcd.printf("PwmOut Command");
bromand 0:a79722dcd2a0 25 }
bromand 0:a79722dcd2a0 26
bromand 0:a79722dcd2a0 27 //Main function
bromand 0:a79722dcd2a0 28 int main()
bromand 0:a79722dcd2a0 29 {
bromand 0:a79722dcd2a0 30 //Call PrintToLCD Command
bromand 0:a79722dcd2a0 31 PrintToLCD();
bromand 0:a79722dcd2a0 32 //Loop forever
bromand 0:a79722dcd2a0 33 while(true)
bromand 0:a79722dcd2a0 34 {
bromand 0:a79722dcd2a0 35 //Loop from 0.0 to 1.0 and in each step increment by 0.1.
bromand 0:a79722dcd2a0 36 for(float f=0.0f ; f<=1.0f ; f+=0.1f)
bromand 0:a79722dcd2a0 37 {
bromand 0:a79722dcd2a0 38 //Set led1 to f
bromand 0:a79722dcd2a0 39 led1 = f;
bromand 0:a79722dcd2a0 40 //Set led 4 to 1-f.
bromand 0:a79722dcd2a0 41 led4 = 1.0f-f;
bromand 0:a79722dcd2a0 42 wait(0.1);
bromand 0:a79722dcd2a0 43 }//End of for loop
bromand 0:a79722dcd2a0 44 for(float f=0.0f ; f<=1.0f ; f+=0.1f)
bromand 0:a79722dcd2a0 45 {
bromand 0:a79722dcd2a0 46 //Set led4 to f
bromand 0:a79722dcd2a0 47 led4 = f;
bromand 0:a79722dcd2a0 48 //Set led1 to 1-f
bromand 0:a79722dcd2a0 49 led1 = 1.0f-f;
bromand 0:a79722dcd2a0 50 wait(0.1);
bromand 0:a79722dcd2a0 51 }//End of for loop
bromand 0:a79722dcd2a0 52 }//End of while loop
bromand 0:a79722dcd2a0 53 }//End of Main function