joystick

Dependents:   4180Lab4SimonSays 4180Lab4SimonSays

Committer:
elirobelo
Date:
Thu Mar 09 21:53:29 2017 +0000
Revision:
0:964a3e713fe6
simon says;

Who changed what in which revision?

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