Jay Balar / Mbed 2 deprecated 4180_Project_3

Dependencies:   4DGL-uLCD-SE Physac-MBED PinDetect SDFileSystem mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Nav_Switch.h Source File

Nav_Switch.h

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