SharpShooter

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Committer:
jboettcher
Date:
Thu Oct 27 23:10:15 2016 +0000
Revision:
1:8a3fa9e90572
misc;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jboettcher 1:8a3fa9e90572 1 class Nav_Switch
jboettcher 1:8a3fa9e90572 2 {
jboettcher 1:8a3fa9e90572 3 public:
jboettcher 1:8a3fa9e90572 4 Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire);
jboettcher 1:8a3fa9e90572 5 int read();
jboettcher 1:8a3fa9e90572 6 //boolean functions to test each switch
jboettcher 1:8a3fa9e90572 7 bool up();
jboettcher 1:8a3fa9e90572 8 bool down();
jboettcher 1:8a3fa9e90572 9 bool left();
jboettcher 1:8a3fa9e90572 10 bool right();
jboettcher 1:8a3fa9e90572 11 bool fire();
jboettcher 1:8a3fa9e90572 12 //automatic read on RHS
jboettcher 1:8a3fa9e90572 13 operator int ();
jboettcher 1:8a3fa9e90572 14 //index to any switch array style
jboettcher 1:8a3fa9e90572 15 bool operator[](int index) {
jboettcher 1:8a3fa9e90572 16 return _pins[index];
jboettcher 1:8a3fa9e90572 17 };
jboettcher 1:8a3fa9e90572 18 private:
jboettcher 1:8a3fa9e90572 19 BusIn _pins;
jboettcher 1:8a3fa9e90572 20
jboettcher 1:8a3fa9e90572 21 };
jboettcher 1:8a3fa9e90572 22 Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire):
jboettcher 1:8a3fa9e90572 23 _pins(up, down, left, right, fire)
jboettcher 1:8a3fa9e90572 24 {
jboettcher 1:8a3fa9e90572 25 _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise
jboettcher 1:8a3fa9e90572 26 wait(0.001); //delays just a bit for pullups to pull inputs high
jboettcher 1:8a3fa9e90572 27 }
jboettcher 1:8a3fa9e90572 28 inline bool Nav_Switch::up()
jboettcher 1:8a3fa9e90572 29 {
jboettcher 1:8a3fa9e90572 30 return !(_pins[0]);
jboettcher 1:8a3fa9e90572 31 }
jboettcher 1:8a3fa9e90572 32 inline bool Nav_Switch::down()
jboettcher 1:8a3fa9e90572 33 {
jboettcher 1:8a3fa9e90572 34 return !(_pins[1]);
jboettcher 1:8a3fa9e90572 35 }
jboettcher 1:8a3fa9e90572 36 inline bool Nav_Switch::left()
jboettcher 1:8a3fa9e90572 37 {
jboettcher 1:8a3fa9e90572 38 return !(_pins[2]);
jboettcher 1:8a3fa9e90572 39 }
jboettcher 1:8a3fa9e90572 40 inline bool Nav_Switch::right()
jboettcher 1:8a3fa9e90572 41 {
jboettcher 1:8a3fa9e90572 42 return !(_pins[3]);
jboettcher 1:8a3fa9e90572 43 }
jboettcher 1:8a3fa9e90572 44 inline bool Nav_Switch::fire()
jboettcher 1:8a3fa9e90572 45 {
jboettcher 1:8a3fa9e90572 46 return !(_pins[4]);
jboettcher 1:8a3fa9e90572 47 }
jboettcher 1:8a3fa9e90572 48 inline int Nav_Switch::read()
jboettcher 1:8a3fa9e90572 49 {
jboettcher 1:8a3fa9e90572 50 return _pins.read();
jboettcher 1:8a3fa9e90572 51 }
jboettcher 1:8a3fa9e90572 52 inline Nav_Switch::operator int ()
jboettcher 1:8a3fa9e90572 53 {
jboettcher 1:8a3fa9e90572 54 return _pins.read();
jboettcher 1:8a3fa9e90572 55 }