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
FivePosSwitch.cpp@5:413df8008ce3, 2015-10-08 (annotated)
- Committer:
- electromotivated
- Date:
- Thu Oct 08 23:54:31 2015 +0000
- Revision:
- 5:413df8008ce3
- Parent:
- 4:10c4b7cb4e8c
enum DOWN (=4) definition had compile conflicts with cmath.h, which apparently has a #define something 4. This would cause problems when using the DOWN tag. Just made values negative to hopefully avoid the evil #define errors;
Who changed what in which revision?
| User | Revision | Line number | New 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 | 4:10c4b7cb4e8c | 7 | ACTIVE_POSITION 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 | } |
