serial dimmer demo using serial interface based on :https://mbed.org/handbook/SerialPC example with minor modifications

Dependencies:   mbed

Committer:
felipeM
Date:
Sat Oct 05 19:30:05 2013 +0000
Revision:
0:623f6e1e1e89
serial controlled dimmer demo; taken from (with minor modifications) ; https://mbed.org/handbook/SerialPC

Who changed what in which revision?

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