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.
Diff: main.cpp
- Revision:
- 2:d955fe04abd9
- Parent:
- 1:8012a60a982d
--- a/main.cpp Fri Oct 22 09:10:35 2010 +0000
+++ b/main.cpp Fri Oct 22 12:23:34 2010 +0000
@@ -20,6 +20,8 @@
PwmOut led3(LED3);
PwmOut led4(LED4);
+#define PWM_MAX 0.5
+
float brightness = 0.0;
float brigh_bckp;
@@ -27,9 +29,14 @@
int Selec_bckp;
void callback() {
+ if (brightness>PWM_MAX) // limiter
+ brightness = PWM_MAX;
+
+ if (brightness<0.0) // limiter
+ brightness = 0.0;
+
if (Selec_bckp!=SelectedLED || brigh_bckp!=brightness) {
- pc.printf("*brightness%u=%f\n",SelectedLED,brightness);
-
+ pc.printf("*Led%u : %5.1f%%\n",SelectedLED,brightness*100.0/PWM_MAX);
Selec_bckp = SelectedLED;
brigh_bckp = brightness;
}
@@ -64,33 +71,31 @@
while (true) {
if (pc.readable()) {
char c = pc.getc();
- if ((c == '+') && (brightness < 0.5)) {
+
+ if ((c == '+') && (brightness < PWM_MAX)) {
brightness += 0.01;
SetBright();
- }
- if ((c == '-') && (brightness > 0.0)) {
+ } else if ((c == '-') && (brightness > 0.0)) {
brightness -= 0.01;
SetBright();
- }
- if (c == '1') {
+ } else if (c == '1') {
pc.printf("Led1 selected\n");
SelectedLED = 1;
brightness = 0.0;
- }
- if (c == '2') {
+ } else if (c == '2') {
pc.printf("Led2 selected\n");
SelectedLED = 2;
brightness = 0.0;
- }
- if (c == '3') {
+ } else if (c == '3') {
pc.printf("Led3 selected\n");
SelectedLED = 3;
brightness = 0.0;
- }
- if (c == '4') {
+ } else if (c == '4') {
pc.printf("Led4 selected\n");
SelectedLED = 4;
brightness = 0.0;
+ } else if (c == 'a') {
+ pc.printf("Author: Eray Ozturk\n");
}
}
}