serial-led PC --> serial --> pwm --> led1

Dependencies:   mbed

Fork of serial-test by Kentarou Shimatani

Committer:
peccu
Date:
Fri Jun 17 12:35:05 2011 +0000
Revision:
0:b1ba78fdcc98

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peccu 0:b1ba78fdcc98 1 #include "mbed.h"
peccu 0:b1ba78fdcc98 2
peccu 0:b1ba78fdcc98 3 Serial pc(USBTX, USBRX); // tx, rx
peccu 0:b1ba78fdcc98 4 AnalogIn myinput(p20);
peccu 0:b1ba78fdcc98 5 PwmOut led(LED1);
peccu 0:b1ba78fdcc98 6
peccu 0:b1ba78fdcc98 7 float brightness = 0.0;
peccu 0:b1ba78fdcc98 8
peccu 0:b1ba78fdcc98 9 int main() {
peccu 0:b1ba78fdcc98 10 pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\r\n");
peccu 0:b1ba78fdcc98 11
peccu 0:b1ba78fdcc98 12 while(1) {
peccu 0:b1ba78fdcc98 13 pc.printf("Hello World! : %f\r\n",(float)myinput);
peccu 0:b1ba78fdcc98 14 char c = pc.getc();
peccu 0:b1ba78fdcc98 15 if((c == 'u') && (brightness < 0.5)) {
peccu 0:b1ba78fdcc98 16 brightness += 0.01;
peccu 0:b1ba78fdcc98 17 led = brightness;
peccu 0:b1ba78fdcc98 18 }
peccu 0:b1ba78fdcc98 19 if((c == 'd') && (brightness > 0.0)) {
peccu 0:b1ba78fdcc98 20 brightness -= 0.01;
peccu 0:b1ba78fdcc98 21 led = brightness;
peccu 0:b1ba78fdcc98 22 }
peccu 0:b1ba78fdcc98 23
peccu 0:b1ba78fdcc98 24 }
peccu 0:b1ba78fdcc98 25 }