Adrian Renner / Mbed 2 deprecated HaPo_Labor2

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
addyi
Date:
Thu Nov 27 13:54:47 2014 +0000
Parent:
2:14b38579386c
Commit message:
Fertig fuer beide seiten

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Nov 26 10:28:31 2014 +0000
+++ b/main.cpp	Thu Nov 27 13:54:47 2014 +0000
@@ -1,5 +1,7 @@
 #include "mbed.h"
 
+#define anz 6
+
 DigitalIn b1(p8);
 DigitalIn b2(p14);
 DigitalOut led[] = {(LED1), (LED2),(LED3),(LED4)};
@@ -7,21 +9,23 @@
 
 bool shortPress =false;
 bool longPress = false;
+bool isRight=true;
 
 int counterTime = 0;
-int counterBlink=6;
+int counterBlink=anz;
 
 Ticker timeTasterTest;
 Ticker timeLedTest;
 
 void tasterTest();
 void ledTest();
+void reset();
 
 int main()
 {
     timeTasterTest.attach(&tasterTest,0.01);
     timeLedTest.attach(&ledTest,0.5);
-    
+
     while(1) {
 
 
@@ -32,25 +36,41 @@
 {
     if(shortPress) {
         if(counterBlink>=0) {
-            led[3]=!led[3];
+            if(!isRight) {
+                led[3]=!led[3];
+            } else {
+                led[0]=!led[0];
+            }
             counterBlink--;
         } else {
-            led[3]=0;
-            counterBlink=6;
-            shortPress=false;
+            reset();
         }
     }
     if(longPress) {
-        led[3]=!led[3];
+        if(!isRight) {
+            led[3]=!led[3];
+        } else {
+            led[0]=!led[0];
+        }
     }
 
-    
+
 
 }
 
 void tasterTest()
 {
-    if(!b1) {
+    if(!b1 != !b2) {
+        if(!b1&&isRight) {
+            isRight=false;
+            reset();
+        }
+
+        if (!b2&&!isRight) {
+            isRight=true;
+            reset();
+        }
+
         if(counterTime<500) {
             longPress=false;
             shortPress=true;
@@ -62,9 +82,21 @@
         }
     } else {
         if(longPress) {
-            counterTime=0;
-            longPress=false;
-            shortPress=false;
+            reset();
         }
     }
 }
+
+void reset()
+{
+    counterTime=0;
+    longPress=false;
+    shortPress=false;
+
+    led[3]=0;
+    led[0]=0;
+    counterBlink=anz;
+}
+
+
+