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

Dependencies:   mbed

Fork of serial-test by Kentarou Shimatani

Committer:
titanium
Date:
Sun Apr 01 04:33:50 2018 +0000
Revision:
1:60549a38c8e0
PC --> serial --> PWM --> led brightness

Who changed what in which revision?

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