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.
Dependencies: 4DGL-uLCD-SE DebounceIn LSM9DS1_Library_cal SDFileSystem TextLCD mbed-rtos mbed wave_player_appbd
Nav_Switch.h@7:a9b088f640c0, 2016-10-30 (annotated)
- Committer:
- taylornichols
- Date:
- Sun Oct 30 04:44:06 2016 +0000
- Revision:
- 7:a9b088f640c0
shield
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
taylornichols | 7:a9b088f640c0 | 1 | #include "mbed.h" |
taylornichols | 7:a9b088f640c0 | 2 | |
taylornichols | 7:a9b088f640c0 | 3 | class Nav_Switch |
taylornichols | 7:a9b088f640c0 | 4 | { |
taylornichols | 7:a9b088f640c0 | 5 | public: |
taylornichols | 7:a9b088f640c0 | 6 | Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire); |
taylornichols | 7:a9b088f640c0 | 7 | int read(); |
taylornichols | 7:a9b088f640c0 | 8 | //boolean functions to test each switch |
taylornichols | 7:a9b088f640c0 | 9 | bool up(); |
taylornichols | 7:a9b088f640c0 | 10 | bool down(); |
taylornichols | 7:a9b088f640c0 | 11 | bool left(); |
taylornichols | 7:a9b088f640c0 | 12 | bool right(); |
taylornichols | 7:a9b088f640c0 | 13 | bool fire(); |
taylornichols | 7:a9b088f640c0 | 14 | //automatic read on RHS |
taylornichols | 7:a9b088f640c0 | 15 | operator int (); |
taylornichols | 7:a9b088f640c0 | 16 | //index to any switch array style |
taylornichols | 7:a9b088f640c0 | 17 | bool operator[](int index) { |
taylornichols | 7:a9b088f640c0 | 18 | return _pins[index]; |
taylornichols | 7:a9b088f640c0 | 19 | }; |
taylornichols | 7:a9b088f640c0 | 20 | private: |
taylornichols | 7:a9b088f640c0 | 21 | BusIn _pins; |
taylornichols | 7:a9b088f640c0 | 22 | |
taylornichols | 7:a9b088f640c0 | 23 | }; |
taylornichols | 7:a9b088f640c0 | 24 | Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire): |
taylornichols | 7:a9b088f640c0 | 25 | _pins(up, down, left, right, fire) |
taylornichols | 7:a9b088f640c0 | 26 | { |
taylornichols | 7:a9b088f640c0 | 27 | _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise |
taylornichols | 7:a9b088f640c0 | 28 | wait(0.001); //delays just a bit for pullups to pull inputs high |
taylornichols | 7:a9b088f640c0 | 29 | } |
taylornichols | 7:a9b088f640c0 | 30 | inline bool Nav_Switch::up() |
taylornichols | 7:a9b088f640c0 | 31 | { |
taylornichols | 7:a9b088f640c0 | 32 | return !(_pins[0]); |
taylornichols | 7:a9b088f640c0 | 33 | } |
taylornichols | 7:a9b088f640c0 | 34 | inline bool Nav_Switch::down() |
taylornichols | 7:a9b088f640c0 | 35 | { |
taylornichols | 7:a9b088f640c0 | 36 | return !(_pins[1]); |
taylornichols | 7:a9b088f640c0 | 37 | } |
taylornichols | 7:a9b088f640c0 | 38 | inline bool Nav_Switch::left() |
taylornichols | 7:a9b088f640c0 | 39 | { |
taylornichols | 7:a9b088f640c0 | 40 | return !(_pins[2]); |
taylornichols | 7:a9b088f640c0 | 41 | } |
taylornichols | 7:a9b088f640c0 | 42 | inline bool Nav_Switch::right() |
taylornichols | 7:a9b088f640c0 | 43 | { |
taylornichols | 7:a9b088f640c0 | 44 | return !(_pins[3]); |
taylornichols | 7:a9b088f640c0 | 45 | } |
taylornichols | 7:a9b088f640c0 | 46 | inline bool Nav_Switch::fire() |
taylornichols | 7:a9b088f640c0 | 47 | { |
taylornichols | 7:a9b088f640c0 | 48 | return !(_pins[4]); |
taylornichols | 7:a9b088f640c0 | 49 | } |
taylornichols | 7:a9b088f640c0 | 50 | inline int Nav_Switch::read() |
taylornichols | 7:a9b088f640c0 | 51 | { |
taylornichols | 7:a9b088f640c0 | 52 | return _pins.read(); |
taylornichols | 7:a9b088f640c0 | 53 | } |
taylornichols | 7:a9b088f640c0 | 54 | inline Nav_Switch::operator int () |
taylornichols | 7:a9b088f640c0 | 55 | { |
taylornichols | 7:a9b088f640c0 | 56 | return _pins.read(); |
taylornichols | 7:a9b088f640c0 | 57 | } |
taylornichols | 7:a9b088f640c0 | 58 |