Debounce_Library

Dependents:   EJ3_Cafetera EJ1

Revision:
0:16d62113f1d5
Child:
1:8db2c2a203d9
Child:
2:d1e2599de47c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/antirrebote.cpp	Thu May 03 23:32:45 2018 +0000
@@ -0,0 +1,56 @@
+#include "antirrebote.h"
+
+enum{PULS_NA, PULS_FLC1, PULS_A, PULS_FLC2};
+
+AntReb::~AntReb(){
+    }
+AntReb::AntReb(){
+    e_PULS = PULS_NA;
+    }
+
+void AntReb::setPin(DigitalIn pin)
+{
+    P_PULS =pin.read();
+}
+
+pinEstado_t AntReb::antiRebote(){
+    pinEstado_t StateOut;
+
+   switch(e_PULS){
+        default:
+        case PULS_NA:
+           StateOut = APAGADO;
+            if(P_PULS == 0) {
+                e_PULS = PULS_FLC1;
+                }
+            break;
+        case PULS_FLC1:
+            StateOut = APAGADO;
+            if(P_PULS == 0) {
+                e_PULS = PULS_A;
+                StateOut= ENCENDIDO;
+            }else if(P_PULS == 1) {
+                e_PULS = PULS_NA;
+            }
+            break;
+        case PULS_A:
+            StateOut =APAGADO;
+            if(P_PULS == 1) {
+                e_PULS = PULS_FLC2;
+            }
+            break;
+        case PULS_FLC2:
+            StateOut = APAGADO;
+            if(P_PULS == 0) {
+                e_PULS = PULS_A;
+            }else if(P_PULS == 1) {
+                e_PULS = PULS_NA;
+            
+            }
+            break;
+    }
+    return StateOut;
+}
+
+
+