multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
main.cpp
- Committer:
- denizguler
- Date:
- 2020-11-10
- Revision:
- 13:95d44f7855ca
- Parent:
- 12:91affff3be75
- Child:
- 14:6b20a930e1cb
File content as of revision 13:95d44f7855ca:
#include "mbed.h" #include "EthernetInterface.h" #include "network.h" #include "DebouncedInterrupt.h" #define DEBOUNCE 100 DebouncedInterrupt leftButton(p21); DebouncedInterrupt middleButton(p22); DebouncedInterrupt rightButton(p23); EthernetInterface eth; UDPSocket sock; Endpoint nist; volatile int count = 0; // interrupt service routines void pressLeft( void ) { count++; char json[] = "{\"type\": \"move\", \"dir\": \"left\"}"; sock.sendTo(nist, json, sizeof(json)); } void pressMiddle() { count++; char json[] = "{\"type\": \"move\", \"dir\": \"middle\"}"; // sock.sendTo(nist, json, sizeof(json) - 1); } void pressRight() { count++; // char json[] = "{\"type\": \"move\", \"dir\": \"right\"}"; // sock.sendTo(nist, json, sizeof(json) - 1); } int main() { initEthernet(ð, &sock, &nist); // initialize GPIO leftButton.attach(&pressLeft, IRQ_RISE, DEBOUNCE); middleButton.attach(&pressMiddle, IRQ_RISE, DEBOUNCE); rightButton.attach(&pressRight, IRQ_RISE, DEBOUNCE); while (1) { printf("count: %i\r\n", count); wait(.5); } // cleanupEthernet(ð, &sock); }