Bryce Williams / FivePosSwitch

Fork of FivePosSwitch by Bryce Williams

Committer:
electromotivated
Date:
Sun Oct 04 19:50:26 2015 +0000
Revision:
3:dcb9eef119cf
Parent:
1:2e82709484bc
Child:
4:10c4b7cb4e8c
v1 release;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
electromotivated 1:2e82709484bc 1 #include "mbed.h"
electromotivated 1:2e82709484bc 2 #include "FivePosSwitch.h"
electromotivated 1:2e82709484bc 3
electromotivated 1:2e82709484bc 4 FivePosSwitch::FivePosSwitch(AnalogIn pin):_pin(pin){
electromotivated 1:2e82709484bc 5 }
electromotivated 1:2e82709484bc 6
electromotivated 3:dcb9eef119cf 7 ACTIVE_POSITION_t FivePosSwitch::getPosition(){
electromotivated 1:2e82709484bc 8 float ain = _pin;
electromotivated 1:2e82709484bc 9
electromotivated 1:2e82709484bc 10 if((1.0 - TOLERANCE <= ain) && (ain <= 1.0 + TOLERANCE)) return UP;
electromotivated 1:2e82709484bc 11 if((0.8 - TOLERANCE <= ain) && (ain <= 0.8 + TOLERANCE)) return CENTER;
electromotivated 1:2e82709484bc 12 if((0.6 - TOLERANCE <= ain) && (ain <= 0.6 + TOLERANCE)) return LEFT;
electromotivated 1:2e82709484bc 13 if((0.4 - TOLERANCE <= ain) && (ain <= 0.4 + TOLERANCE)) return DOWN;
electromotivated 1:2e82709484bc 14 if((0.2 - TOLERANCE <= ain) && (ain <= 0.2 + TOLERANCE)) return RIGHT;
electromotivated 1:2e82709484bc 15 else return NONE;
electromotivated 1:2e82709484bc 16 }