Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- diffstorm
- Date:
- 2010-10-21
- Revision:
- 0:655158a7c194
- Child:
- 1:8012a60a982d
File content as of revision 0:655158a7c194:
#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
Ticker flipper;
PwmOut led1(LED1);
PwmOut led2(LED2);
PwmOut led3(LED3);
PwmOut led4(LED4);
float brightness = 0.0;
float brigh_bckp;
int SelectedLED = 1;
int Selec_bckp;
void flip() {
if (Selec_bckp!=SelectedLED || brigh_bckp!=brightness) {
pc.printf("*brightness%u=%f\n",SelectedLED,brightness);
Selec_bckp = SelectedLED;
brigh_bckp = brightness;
}
}
void SetBright() {
switch (SelectedLED) {
case 1:
led1 = brightness;
break;
case 2:
led2 = brightness;
break;
case 3:
led3 = brightness;
break;
case 4:
led4 = brightness;
break;
default:
SelectedLED = 1;
}
}
int main() {
pc.printf("Press '+/-' to change selected LED's brightness\n");
pc.printf("Use '1'-'4' keys to change selected LED\n");
flipper.attach(&flip, 1.0); // call flip() in interval 0.2 sec
while (true) {
if (pc.readable()) {
char c = pc.getc();
if ((c == '+') && (brightness < 0.5)) {
brightness += 0.01;
SetBright();
}
if ((c == '-') && (brightness > 0.0)) {
brightness -= 0.01;
SetBright();
}
if (c == '1') {
pc.printf("Led1 selected\n");
SelectedLED = 1;
brightness = 0.0;
}
if (c == '2') {
pc.printf("Led2 selected\n");
SelectedLED = 2;
brightness = 0.0;
}
if (c == '3') {
pc.printf("Led3 selected\n");
SelectedLED = 3;
brightness = 0.0;
}
if (c == '4') {
pc.printf("Led4 selected\n");
SelectedLED = 4;
brightness = 0.0;
}
}
}
}