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: mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem X_NUCLEO_53L0A1 HC_SR04_Ultrasonic_Library
nav_switch.h
00001 #include "mbed.h" 00002 00003 class Nav_Switch 00004 { 00005 public: 00006 Nav_Switch(PinName up,PinName down,PinName left,PinName right,PinName fire); 00007 int read(); 00008 //boolean functions to test each switch 00009 bool up(); 00010 bool down(); 00011 bool left(); 00012 bool right(); 00013 bool fire(); 00014 //automatic read on RHS 00015 operator int (); 00016 //index to any switch array style 00017 bool operator[](int index) { 00018 return _pins[index]; 00019 }; 00020 private: 00021 BusIn _pins; 00022 00023 }; 00024 Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire): 00025 _pins(up, down, left, right, fire) 00026 { 00027 _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise 00028 wait(0.001); //delays just a bit for pullups to pull inputs high 00029 } 00030 inline bool Nav_Switch::up() 00031 { 00032 return !(_pins[0]); 00033 } 00034 inline bool Nav_Switch::down() 00035 { 00036 return !(_pins[1]); 00037 } 00038 inline bool Nav_Switch::left() 00039 { 00040 return !(_pins[2]); 00041 } 00042 inline bool Nav_Switch::right() 00043 { 00044 return !(_pins[3]); 00045 } 00046 inline bool Nav_Switch::fire() 00047 { 00048 return !(_pins[4]); 00049 } 00050 inline int Nav_Switch::read() 00051 { 00052 return _pins.read(); 00053 } 00054 inline Nav_Switch::operator int () 00055 { 00056 return _pins.read(); 00057 }
Generated on Wed Jul 13 2022 11:06:00 by
1.7.2