Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of FivePosSwitch by
Diff: FivePosSwitch.cpp
- Revision:
- 1:2e82709484bc
- Child:
- 3:dcb9eef119cf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/FivePosSwitch.cpp Sun Oct 04 19:18:10 2015 +0000
@@ -0,0 +1,16 @@
+#include "mbed.h"
+#include "FivePosSwitch.h"
+
+FivePosSwitch::FivePosSwitch(AnalogIn pin):_pin(pin){
+}
+
+ACTIVE_POSITION FivePosSwitch::getPosition(){
+ float ain = _pin;
+
+ if((1.0 - TOLERANCE <= ain) && (ain <= 1.0 + TOLERANCE)) return UP;
+ if((0.8 - TOLERANCE <= ain) && (ain <= 0.8 + TOLERANCE)) return CENTER;
+ if((0.6 - TOLERANCE <= ain) && (ain <= 0.6 + TOLERANCE)) return LEFT;
+ if((0.4 - TOLERANCE <= ain) && (ain <= 0.4 + TOLERANCE)) return DOWN;
+ if((0.2 - TOLERANCE <= ain) && (ain <= 0.2 + TOLERANCE)) return RIGHT;
+ else return NONE;
+}
\ No newline at end of file
