GamePortAdapter

Dependencies:   mbed-rtos mbed USBDevice USBJoystick

Revision:
2:c7f76dac3723
Parent:
1:ec3596dd0670
Child:
3:20f3136e49fa
--- a/main.cpp	Thu Dec 07 21:22:48 2017 +0000
+++ b/main.cpp	Mon Dec 11 22:30:59 2017 +0000
@@ -3,7 +3,7 @@
 
 Serial pc(USBTX, USBRX);
 //macOS: screen /dev/tty.usbmodem{num} {baud rate}
-//Windows:Realterm lol
+//Windows: Realterm lol
 
 Thread analogThread;
 
@@ -21,9 +21,12 @@
 volatile int x1_pulse;
 volatile int y2_pulse;
 volatile int x2_pulse;
+volatile int buts;
 
 DigitalOut trig(p19);
 
+BusIn buttons(p21, p22, p23, p24);
+
 void start_y1() {
     y1_t.reset();
     y1_t.start();
@@ -82,10 +85,13 @@
     
     x2.rise(&start_x2);
     x2.fall(&stop_x2);
+    
+    buttons.mode(PullUp);
 
     while(1) {
         trig = 0;
         trig = 1;
+        buts = ~buttons&0xF;
         wait(.1);
     }
 }
@@ -97,8 +103,8 @@
     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("Joystick 1 - %d, %d, %X \r\n", x1_pulse, y1_pulse, buts&0x3);
+        pc.printf("Joystick 2 - %d, %d, %X \r\n", x2_pulse, y2_pulse, (buts>>2)&0x3);
         pc.printf("\r\n");
         wait(.5);
     }