Adrian Renner / Mbed 2 deprecated HaPo_Labor2

Dependencies:   mbed

Revision:
0:76669ad2c30b
Child:
1:0072ef0302ec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 26 09:31:01 2014 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+
+DigitalIn b1(p8);
+DigitalIn b2(p14);
+DigitalOut led[] = {(LED1), (LED2),(LED3),(LED4)};
+
+
+bool shortPress =false;
+bool longPress = false;
+
+int counterTime = 0;
+int counterBlink=4;
+
+Ticker timeTasterTest;
+Ticker timeLedTest;
+
+void tasterTest();
+void ledTest();
+
+int main()
+{
+    while(1) {
+        timeTasterTest.attach(&tasterTest,0.01);
+        timeLedTest.attach(&ledTest,0.5);
+    }
+}
+
+void ledTest()
+{
+    if(shortPress) {
+        if(counterBlink>=0) {
+            led[1]=!led[1];
+            counterBlink--;
+        } else {
+            led[1]=0;
+            counterBlink=4;
+        }
+    }
+    if(longPress) {
+        led[1]=!led[1];
+    }
+
+}
+
+void tasterTest()
+{
+    if(!b1) {
+        if(counterTime<500) {
+            longPress=false;
+            shortPress=true;
+            counterTime ++;
+        } else {
+            counterTime=0;
+            longPress=true;
+            shortPress=false;
+        }
+    } else {
+        if(longPress) {
+            counterTime=0;
+            longPress=false;
+            shortPress=false;
+        }
+    }
+}