multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
main.cpp@12:91affff3be75, 2020-11-10 (annotated)
- Committer:
- vsoltan
- Date:
- Tue Nov 10 03:31:37 2020 +0000
- Revision:
- 12:91affff3be75
- Parent:
- 11:d0a105f6743f
- Child:
- 13:95d44f7855ca
added ISRs, although still running into issues
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 1:8e1d4987eb90 | 1 | #include "mbed.h" |
donatien | 1:8e1d4987eb90 | 2 | #include "EthernetInterface.h" |
vsoltan | 11:d0a105f6743f | 3 | #include "network.h" |
vsoltan | 12:91affff3be75 | 4 | #include "PinDetect.h" |
vsoltan | 12:91affff3be75 | 5 | |
vsoltan | 12:91affff3be75 | 6 | #define DEBOUNCE 100 |
vsoltan | 12:91affff3be75 | 7 | |
vsoltan | 12:91affff3be75 | 8 | PinDetect leftButton(p21); |
vsoltan | 12:91affff3be75 | 9 | PinDetect middleButton(p22); |
vsoltan | 12:91affff3be75 | 10 | PinDetect rightButton(p23); |
vsoltan | 12:91affff3be75 | 11 | |
vsoltan | 12:91affff3be75 | 12 | EthernetInterface eth; |
vsoltan | 12:91affff3be75 | 13 | UDPSocket sock; |
vsoltan | 12:91affff3be75 | 14 | Endpoint nist; |
vsoltan | 12:91affff3be75 | 15 | |
vsoltan | 12:91affff3be75 | 16 | // interrupt service routines |
vsoltan | 12:91affff3be75 | 17 | void pressLeft() { |
vsoltan | 12:91affff3be75 | 18 | printf("EYYYY BALL DO YOU WANNA GO BALLROOM\n"); |
vsoltan | 12:91affff3be75 | 19 | //char json[] = "{\"type\": \"move\", \"dir\": \"left\"}"; |
vsoltan | 12:91affff3be75 | 20 | // sock.sendTo(nist, json, sizeof(json) - 1); |
vsoltan | 12:91affff3be75 | 21 | } |
vsoltan | 12:91affff3be75 | 22 | |
vsoltan | 12:91affff3be75 | 23 | void pressMiddle() { |
vsoltan | 12:91affff3be75 | 24 | //char json[] = "{\"type\": \"move\", \"dir\": \"middle\"}"; |
vsoltan | 12:91affff3be75 | 25 | // sock.sendTo(nist, json, sizeof(json) - 1); |
vsoltan | 12:91affff3be75 | 26 | } |
vsoltan | 12:91affff3be75 | 27 | |
vsoltan | 12:91affff3be75 | 28 | void pressRight() { |
vsoltan | 12:91affff3be75 | 29 | //char json[] = "{\"type\": \"move\", \"dir\": \"right\"}"; |
vsoltan | 12:91affff3be75 | 30 | // sock.sendTo(nist, json, sizeof(json) - 1); |
vsoltan | 12:91affff3be75 | 31 | } |
emilmont | 6:25aad2d88749 | 32 | |
emilmont | 6:25aad2d88749 | 33 | int main() { |
vsoltan | 11:d0a105f6743f | 34 | initEthernet(ð, &sock, &nist); |
emilmont | 7:dedf5dde9798 | 35 | |
vsoltan | 12:91affff3be75 | 36 | // initialize GPIO |
vsoltan | 12:91affff3be75 | 37 | leftButton.mode(PullUp); |
vsoltan | 12:91affff3be75 | 38 | middleButton.mode(PullUp); |
vsoltan | 12:91affff3be75 | 39 | rightButton.mode(PullUp); |
vsoltan | 12:91affff3be75 | 40 | |
vsoltan | 12:91affff3be75 | 41 | // Delay for initial pullup to take effect |
vsoltan | 12:91affff3be75 | 42 | wait(0.1); |
vsoltan | 12:91affff3be75 | 43 | |
vsoltan | 12:91affff3be75 | 44 | leftButton.attach_deasserted(&pressLeft); |
vsoltan | 12:91affff3be75 | 45 | middleButton.attach_deasserted(&pressMiddle); |
vsoltan | 12:91affff3be75 | 46 | rightButton.attach_deasserted(&pressRight); |
vsoltan | 12:91affff3be75 | 47 | |
vsoltan | 12:91affff3be75 | 48 | leftButton.setSampleFrequency(DEBOUNCE); |
vsoltan | 12:91affff3be75 | 49 | middleButton.setSampleFrequency(DEBOUNCE); |
vsoltan | 12:91affff3be75 | 50 | rightButton.setSampleFrequency(DEBOUNCE); |
vsoltan | 12:91affff3be75 | 51 | |
vsoltan | 12:91affff3be75 | 52 | while(1) {} |
vsoltan | 11:d0a105f6743f | 53 | |
vsoltan | 11:d0a105f6743f | 54 | cleanupEthernet(ð, &sock); |
donatien | 1:8e1d4987eb90 | 55 | } |