![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: main.cpp
- Revision:
- 13:95d44f7855ca
- Parent:
- 12:91affff3be75
- Child:
- 14:6b20a930e1cb
--- a/main.cpp Tue Nov 10 03:31:37 2020 +0000 +++ b/main.cpp Tue Nov 10 05:11:41 2020 +0000 @@ -1,55 +1,51 @@ #include "mbed.h" #include "EthernetInterface.h" #include "network.h" -#include "PinDetect.h" +#include "DebouncedInterrupt.h" #define DEBOUNCE 100 -PinDetect leftButton(p21); -PinDetect middleButton(p22); -PinDetect rightButton(p23); +DebouncedInterrupt leftButton(p21); +DebouncedInterrupt middleButton(p22); +DebouncedInterrupt rightButton(p23); EthernetInterface eth; UDPSocket sock; Endpoint nist; +volatile int count = 0; + // 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 pressLeft( void ) { + count++; + char json[] = "{\"type\": \"move\", \"dir\": \"left\"}"; + sock.sendTo(nist, json, sizeof(json)); } void pressMiddle() { - //char json[] = "{\"type\": \"move\", \"dir\": \"middle\"}"; -// sock.sendTo(nist, json, sizeof(json) - 1); + count++; + 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); + count++; + // char json[] = "{\"type\": \"move\", \"dir\": \"right\"}"; + // sock.sendTo(nist, json, sizeof(json) - 1); } int main() { - initEthernet(ð, &sock, &nist); + initEthernet(ð, &sock, &nist); // initialize GPIO - leftButton.mode(PullUp); - middleButton.mode(PullUp); - rightButton.mode(PullUp); - - // Delay for initial pullup to take effect - wait(0.1); + leftButton.attach(&pressLeft, IRQ_RISE, DEBOUNCE); + middleButton.attach(&pressMiddle, IRQ_RISE, DEBOUNCE); + rightButton.attach(&pressRight, IRQ_RISE, DEBOUNCE); - leftButton.attach_deasserted(&pressLeft); - middleButton.attach_deasserted(&pressMiddle); - rightButton.attach_deasserted(&pressRight); - - leftButton.setSampleFrequency(DEBOUNCE); - middleButton.setSampleFrequency(DEBOUNCE); - rightButton.setSampleFrequency(DEBOUNCE); - - while(1) {} + while (1) { + printf("count: %i\r\n", count); + wait(.5); + } - cleanupEthernet(ð, &sock); + // cleanupEthernet(ð, &sock); }