Felix Pachay / Mbed 2 deprecated Tutoria_Pachay

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Serial pc(PA_2, PA_3,115200); //tx, rx
00003 PwmOut led(PA_0);
00004 float brightness=0.0;
00005 
00006 int main()
00007 {
00008     pc.printf("control of LED dimmer by host terminal\n\r");
00009     pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r");
00010     while (1) {
00011         char c = pc.getc();
00012         wait(0.001);
00013         if((c == 'u') && (brightness < 1)) {
00014             brightness += 0.1;
00015             motor= brightness;
00016         }
00017         if(( c == 'd') && (brightness > 0)) {
00018             brightness -= 0.1;
00019             motor = brightness;
00020         }
00021 
00022         pc.printf("%c %1.3f \n \r",c,brightness);
00023 
00024     }
00025 }
00026