GamePortAdapter
Dependencies: mbed-rtos mbed USBDevice USBJoystick
Revision 0:8b4f60bf3f80, committed 2017-12-07
- Comitter:
- cblackstone7
- Date:
- Thu Dec 07 21:15:37 2017 +0000
- Child:
- 1:ec3596dd0670
- Commit message:
- Initial Commit;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Dec 07 21:15:37 2017 +0000
@@ -0,0 +1,104 @@
+#include "mbed.h"
+#include "rtos.h"
+
+Serial pc(USBTX, USBRX);
+//macOS: screen /dev/tty.usbmodem{num} {baud rate}
+
+Thread analogThread;
+
+Timer y1_t;
+Timer x1_t;
+Timer y2_t;
+Timer x2_t;
+
+InterruptIn y1(p16);
+InterruptIn x1(p15);
+InterruptIn y2(p18);
+InterruptIn x2(p17);
+
+volatile int y1_pulse;
+volatile int x1_pulse;
+volatile int y2_pulse;
+volatile int x2_pulse;
+
+DigitalOut trig(p19);
+
+void start_y1() {
+ y1_t.reset();
+ y1_t.start();
+}
+
+void stop_y1() {
+ y1_t.stop();
+ y1_pulse = y1_t.read_us();
+}
+
+void start_x1() {
+ x1_t.reset();
+ x1_t.start();
+}
+
+void stop_x1() {
+ x1_t.stop();
+ x1_pulse = x1_t.read_us();
+}
+void start_y2() {
+ y2_t.reset();
+ y2_t.start();
+}
+
+void stop_y2() {
+ y2_t.stop();
+ y2_pulse = y2_t.read_us();
+}
+
+void start_x2() {
+ x2_t.reset();
+ x2_t.start();
+}
+
+void stop_x2() {
+ x2_t.stop();
+ x2_pulse = x2_t.read_us();
+}
+
+
+void analog_thread() {
+ trig = 1;
+ y1_pulse = 0;
+ x1_pulse = 0;
+ y2_pulse = 0;
+ x2_pulse = 0;
+
+ y1.rise(&start_y1);
+ y1.fall(&stop_y1);
+
+ x1.rise(&start_x1);
+ x1.fall(&stop_x1);
+
+ y2.rise(&start_y2);
+ y2.fall(&stop_y2);
+
+ x2.rise(&start_x2);
+ x2.fall(&stop_x2);
+
+ while(1) {
+ trig = 0;
+ trig = 1;
+ wait(.1);
+ }
+}
+
+int main() {
+ pc.printf("Beginning Joystick Test...\r\n");
+ pc.printf("---------------------------------\r\n");
+
+ analogThread.start(analog_thread);
+
+ while(1) {
+ pc.printf("Joystick 1 - %d, %d \r\n", x1_pulse, y1_pulse);
+ pc.printf("Joystick 2 - %d, %d \r\n", x2_pulse, y2_pulse);
+ pc.printf("\r\n");
+ wait(.5);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Dec 07 21:15:37 2017 +0000 @@ -0,0 +1,1 @@ +http://os.mbed.com/users/mbed_official/code/mbed-rtos/#5713cbbdb706
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 07 21:15:37 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302 \ No newline at end of file
