This program is a simple version of an LED dimmer that allows the user to increase or decrease the on-board LED brightness using a keyboard.

Dependencies:   mbed

Committer:
302Instructor
Date:
Thu Jan 22 19:55:25 2015 +0000
Revision:
0:9ac9735e14c3
1/22/2015

Who changed what in which revision?

UserRevisionLine numberNew contents of line
302Instructor 0:9ac9735e14c3 1 #include "mbed.h"
302Instructor 0:9ac9735e14c3 2
302Instructor 0:9ac9735e14c3 3 Serial pc(USBTX, USBRX);
302Instructor 0:9ac9735e14c3 4 PwmOut led(LED1);
302Instructor 0:9ac9735e14c3 5
302Instructor 0:9ac9735e14c3 6 float brightness = 0.0;
302Instructor 0:9ac9735e14c3 7
302Instructor 0:9ac9735e14c3 8 int main() {
302Instructor 0:9ac9735e14c3 9 pc.printf("Press '+' to turn LED1 brightness up, '-' to turn it down \n\r");
302Instructor 0:9ac9735e14c3 10 led.period(0.02);
302Instructor 0:9ac9735e14c3 11 while(1) {
302Instructor 0:9ac9735e14c3 12 char c = pc.getc();
302Instructor 0:9ac9735e14c3 13 if ((c == '+') && (brightness > 0.0)) {
302Instructor 0:9ac9735e14c3 14 brightness -= 0.1;
302Instructor 0:9ac9735e14c3 15 led.write(brightness);
302Instructor 0:9ac9735e14c3 16 printf("%f",brightness);
302Instructor 0:9ac9735e14c3 17 printf("\n\rUP");
302Instructor 0:9ac9735e14c3 18 }
302Instructor 0:9ac9735e14c3 19 if ((c == '-') && (brightness < 0.999)) {
302Instructor 0:9ac9735e14c3 20 brightness += 0.1;
302Instructor 0:9ac9735e14c3 21 led.write(brightness);
302Instructor 0:9ac9735e14c3 22 printf("%f",brightness);
302Instructor 0:9ac9735e14c3 23 printf("\n\rDOWN");
302Instructor 0:9ac9735e14c3 24 }
302Instructor 0:9ac9735e14c3 25 }
302Instructor 0:9ac9735e14c3 26 }
302Instructor 0:9ac9735e14c3 27