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:
- 3:c048b13bc1d0
- Parent:
- 2:d4fab8f3f21f
- Child:
- 4:612095337fb0
--- a/main.cpp Wed Oct 22 07:01:00 2014 +0000
+++ b/main.cpp Wed Nov 05 07:40:17 2014 +0000
@@ -20,37 +20,63 @@
// Die Start-Taste ein 3.mal betätigen:
// Alle LEDs aus.
-volatile unsigned int event=0;
+int ledsEin();
+int ledsBlinkTimer();
+int ledsAus();
+int ledsSwitchTimer();
+int stopTimer();
+
+int(*action[5])()= {ledsSwitchTimer, stopTimer, ledsEin, ledsBlinkTimer, ledsAus };
+
+volatile int event = -1;
volatile int led=0;
void switchled();
void blinkled();
-void ledsSwitchTimer()
-{
- tick.attach(&switchled, 0.2);
-}
-
-void ledsBlinkTimer()
-{
- tick.attach(&blinkled, 0.2);
-}
-
-void stopTimer()
+int stopTimer()
{
led1 = 0;
led2 = 0;
led3 = 0;
led4 = 0;
tick.detach();
+ event++;
+ (action[event])();
+
+ return 0;
}
-void ledsEin()
+int ledsBlinkTimer()
+{
+ tick.attach(&blinkled, 0.2);
+ return 0;
+}
+
+int ledsEin()
{
led1 = 1;
led2 = 1;
led3 = 1;
led4 = 1;
+ return 0;
+}
+
+int ledsAus()
+{
+ tick.detach();
+ event = -1;
+ led1 = 0;
+ led2 = 0;
+ led3 = 0;
+ led4 = 0;
+ return 0;
+}
+
+int ledsSwitchTimer()
+{
+ tick.attach(&switchled, 0.2);
+ return 0;
}
void ledsTogglen()
@@ -94,42 +120,12 @@
ledsTogglen();
}
-void doEvent()
-{
- switch(event)
- {
- case 0:
- led1 = 0;
- led2 = 0;
- led3 = 0;
- led4 = 0;
- break;
- case 1:
- led = 0;
- ledsSwitchTimer();
- break;
- case 2:
- stopTimer();
- ledsTogglen();
- break;
- case 3:
- ledsBlinkTimer();
- break;
- case 4:
- stopTimer();
- event = 0;
- break;
- default:
- break;
- }
-}
-
int main()
{
while(1) {
if (button.rising()) {
event++;
- doEvent();
+ (action[event])();
}
}
}