multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: main.cpp
- Revision:
- 12:91affff3be75
- Parent:
- 11:d0a105f6743f
- Child:
- 13:95d44f7855ca
diff -r d0a105f6743f -r 91affff3be75 main.cpp --- 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(ð, &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(ð, &sock); - - while(1) {} }