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: 4DGL-uLCD-SE PinDetect mbed
Diff: joystick.cpp
- Revision:
- 0:56c7173428ac
diff -r 000000000000 -r 56c7173428ac joystick.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/joystick.cpp Tue Nov 22 16:42:02 2022 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "joystick.h"
+
+
+Nav_Switch::Nav_Switch (PinName up,PinName down,PinName left,PinName right,PinName fire):
+ _pins(up, down, left, right, fire)
+{
+ _pins.mode(PullUp); //needed if pullups not on board or a bare nav switch is used - delete otherwise
+ wait(0.001); //delays just a bit for pullups to pull inputs high
+}
+
+bool Nav_Switch::up()
+{
+ return !(_pins[0]);
+}
+bool Nav_Switch::down()
+{
+ return !(_pins[1]);
+}
+bool Nav_Switch::left()
+{
+ return !(_pins[2]);
+}
+bool Nav_Switch::right()
+{
+ return !(_pins[3]);
+}
+bool Nav_Switch::fire()
+{
+ return !(_pins[4]);
+}
+int Nav_Switch::read()
+{
+ return _pins.read();
+}
+Nav_Switch::operator int ()
+{
+ return _pins.read();
+}
\ No newline at end of file