LimitSwitches

Files at this revision

API Documentation at this revision

Comitter:
williequesada
Date:
Tue Jun 04 17:00:17 2019 +0000
Commit message:
pablo

Changed in this revision

LimitSwitches.cpp Show annotated file Show diff for this revision Revisions of this file
LimitSwitches.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LimitSwitches.cpp	Tue Jun 04 17:00:17 2019 +0000
@@ -0,0 +1,30 @@
+#include "LimitSwitches.h"
+#include "mbed.h"
+#include "stdio.h"
+
+SWITCHES::SWITCHES(PinName S1, PinName S2) : Switch1(S1),Switch2(S2) {
+    Switch1.rise(this,&SWITCHES::InterruptDisable);
+    Switch2.rise(this,&SWITCHES::InterruptDisable);
+}
+ 
+int SWITCHES::Read()
+{
+    if(Switch1.read()) {
+        return 1;
+    }
+    if(Switch2.read()) {
+        return 2;
+    }
+    return 0;
+}
+
+void SWITCHES::InterruptDisable()
+{
+    Switch1.disable_irq();
+    Switch2.disable_irq();
+}
+void SWITCHES::InterruptEnable()
+{
+    Switch1.enable_irq();
+    Switch2.enable_irq();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LimitSwitches.h	Tue Jun 04 17:00:17 2019 +0000
@@ -0,0 +1,21 @@
+#ifndef MBED_LIMITSWITCHES_H
+#define MBED_LIMITSWITCHES_H
+ 
+#include "mbed.h"
+ 
+class SWITCHES {
+public:
+    SWITCHES(PinName S1, PinName S2) ;
+
+    int  Read();
+    void InterruptEnable();
+    void InterruptDisable();
+  
+private:  
+    InterruptIn  Switch1;
+    InterruptIn  Switch2;
+};
+ 
+#endif
+ 
+ 
\ No newline at end of file