m b / Mbed 2 deprecated 4180Lab1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Nav_Switch.h Source File

Nav_Switch.h

00001 BusOut mbedleds(LED1,LED2,LED3,LED4);
00002 //BusOut/In is faster than multiple DigitalOut/Ins
00003  
00004 class Nav_Switch
00005 {
00006 public:
00007     Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire);
00008     int read();
00009 //boolean functions to test each switch
00010     bool up();
00011     bool down();
00012     bool left();
00013     bool right();
00014     bool fire();
00015 //automatic read on RHS
00016     operator int ();
00017 //index to any switch array style
00018     bool operator[](int index) {
00019         return _pins[index];
00020     };
00021 private:
00022     BusIn _pins;
00023  
00024 };
00025 Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire):
00026     _pins(up, down, left, right, fire)
00027 {
00028     _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise
00029     wait(0.001); //delays just a bit for pullups to pull inputs high
00030 }
00031 inline bool Nav_Switch::up()
00032 {
00033     return !(_pins[0]);
00034 }
00035 inline bool Nav_Switch::down()
00036 {
00037     return !(_pins[1]);
00038 }
00039 inline bool Nav_Switch::left()
00040 {
00041     return !(_pins[2]);
00042 }
00043 inline bool Nav_Switch::right()
00044 {
00045     return !(_pins[3]);
00046 }
00047 inline bool Nav_Switch::fire()
00048 {
00049     return !(_pins[4]);
00050 }
00051 inline int Nav_Switch::read()
00052 {
00053     return _pins.read();
00054 }
00055 inline Nav_Switch::operator int ()
00056 {
00057     return _pins.read();
00058 }