LimitSwitches
Revision 0:da84ba1b33be, committed 2019-06-04
- Comitter:
- williequesada
- Date:
- Tue Jun 04 16:04:02 2019 +0000
- Commit message:
- compartir a 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 |
diff -r 000000000000 -r da84ba1b33be LimitSwitches.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LimitSwitches.cpp Tue Jun 04 16:04:02 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(); +}
diff -r 000000000000 -r da84ba1b33be LimitSwitches.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LimitSwitches.h Tue Jun 04 16:04:02 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