multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Files at this revision

API Documentation at this revision

Comitter:
vsoltan
Date:
Tue Nov 10 03:31:37 2020 +0000
Parent:
11:d0a105f6743f
Child:
13:95d44f7855ca
Commit message:
added ISRs, although still running into issues

Changed in this revision

PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Tue Nov 10 03:31:37 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/AjK/code/PinDetect/#cb3afc45028b
--- a/main.cpp	Tue Nov 10 02:32:49 2020 +0000
+++ b/main.cpp	Tue Nov 10 03:31:37 2020 +0000
@@ -1,21 +1,55 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "network.h"
+#include "PinDetect.h"
+
+#define DEBOUNCE 100
+
+PinDetect leftButton(p21);
+PinDetect middleButton(p22);
+PinDetect rightButton(p23);
+
+EthernetInterface eth; 
+UDPSocket sock; 
+Endpoint nist; 
+
+// interrupt service routines 
+void pressLeft() {
+    printf("EYYYY BALL DO YOU WANNA GO BALLROOM\n");
+    //char json[] = "{\"type\": \"move\", \"dir\": \"left\"}"; 
+//    sock.sendTo(nist, json, sizeof(json) - 1);
+}
+
+void pressMiddle() {
+    //char json[] = "{\"type\": \"move\", \"dir\": \"middle\"}"; 
+//    sock.sendTo(nist, json, sizeof(json) - 1);
+}
+
+void pressRight() {
+    //char json[] = "{\"type\": \"move\", \"dir\": \"right\"}"; 
+//    sock.sendTo(nist, json, sizeof(json) - 1);
+}
  
 int main() {
-    EthernetInterface eth; 
-    UDPSocket sock; 
-    Endpoint nist; 
-    
     initEthernet(&eth, &sock, &nist); 
     
-    char out_buffer[] = "{\"type\": \"connected\", \"body\": \"hey deniz\"}";
-    sock.sendTo(nist, out_buffer, sizeof(out_buffer) - 1);
-
-    char in_buffer[4];
-    int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));
+    // initialize GPIO
+    leftButton.mode(PullUp);
+    middleButton.mode(PullUp);
+    rightButton.mode(PullUp);
+    
+    // Delay for initial pullup to take effect
+    wait(0.1); 
+    
+    leftButton.attach_deasserted(&pressLeft); 
+    middleButton.attach_deasserted(&pressMiddle);
+    rightButton.attach_deasserted(&pressRight);
+    
+    leftButton.setSampleFrequency(DEBOUNCE); 
+    middleButton.setSampleFrequency(DEBOUNCE); 
+    rightButton.setSampleFrequency(DEBOUNCE); 
+    
+    while(1) {}
 
     cleanupEthernet(&eth, &sock);
-
-    while(1) {}
 }