Space invaders with a nRF2401A wireless joypad

Dependencies:   Gameduino mbed nRF2401A

Fork of Gameduino_Invaders_game by Chris Dick

Gameduino and an nRF2401A hooked up to an mbed on an mbeduino:

/media/uploads/TheChrisyd/2014-03-08_22.53.54.jpg

Committer:
TheChrisyd
Date:
Sun Mar 09 12:27:20 2014 +0000
Revision:
5:3ede9991d8e0
Parent:
4:bb78bedae411
Update to match Library update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TheChrisyd 2:20a89dc286d5 1 #include "mbed.h"
TheChrisyd 2:20a89dc286d5 2 #include "GD.h"
TheChrisyd 2:20a89dc286d5 3 #include "shield.h"
TheChrisyd 2:20a89dc286d5 4 GDClass GD(ARD_MOSI, ARD_MISO, ARD_SCK, ARD_D9, USBTX, USBRX) ;
TheChrisyd 2:20a89dc286d5 5
TheChrisyd 2:20a89dc286d5 6 /*---------------------------------------------------------
TheChrisyd 2:20a89dc286d5 7 A Space Invaders clone for Gameduino
TheChrisyd 2:20a89dc286d5 8
TheChrisyd 2:20a89dc286d5 9 http://www.artlum.com/gameduino/gameduino.html#invaders
TheChrisyd 2:20a89dc286d5 10
TheChrisyd 2:20a89dc286d5 11 Version 0.9 alpha - Still seme things to add
TheChrisyd 2:20a89dc286d5 12 but I'm out of memory!
TheChrisyd 2:20a89dc286d5 13
TheChrisyd 2:20a89dc286d5 14 Edit "joystick.cpp" if you have a custom joystick.
TheChrisyd 2:20a89dc286d5 15 ---------------------------------------------------------*/
TheChrisyd 2:20a89dc286d5 16
TheChrisyd 2:20a89dc286d5 17 #include "game.h"
TheChrisyd 2:20a89dc286d5 18 #include "arduino.h"
TheChrisyd 2:20a89dc286d5 19
TheChrisyd 4:bb78bedae411 20 #include "nRF2401A.h"
TheChrisyd 4:bb78bedae411 21
TheChrisyd 4:bb78bedae411 22 #define WIRELESS
TheChrisyd 5:3ede9991d8e0 23 nRF2401A wireless_joypad(p10, p11, p12, p13, p14);//ce, cs, dr1, clk1, data
TheChrisyd 5:3ede9991d8e0 24 uint8_t wireless_dpad = 0;
TheChrisyd 5:3ede9991d8e0 25 uint8_t wireless_buttons = 0;
TheChrisyd 4:bb78bedae411 26 DigitalOut debug(LED1);
TheChrisyd 4:bb78bedae411 27
TheChrisyd 4:bb78bedae411 28 void nRF2401A_rx (void *arg)
TheChrisyd 4:bb78bedae411 29 {
TheChrisyd 5:3ede9991d8e0 30 wireless_dpad = wireless_joypad.readMsg_byte( 0 );
TheChrisyd 5:3ede9991d8e0 31 wireless_buttons = wireless_joypad.readMsg_byte( 1 );
TheChrisyd 4:bb78bedae411 32 debug = !debug;
TheChrisyd 4:bb78bedae411 33 }
TheChrisyd 4:bb78bedae411 34
TheChrisyd 2:20a89dc286d5 35 void setup() {
TheChrisyd 2:20a89dc286d5 36 GD.begin();
TheChrisyd 4:bb78bedae411 37 #ifdef WIRELESS
TheChrisyd 4:bb78bedae411 38 wait(0.005);
TheChrisyd 5:3ede9991d8e0 39 wireless_joypad.setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3);
TheChrisyd 4:bb78bedae411 40
TheChrisyd 4:bb78bedae411 41 wireless_joypad.flushControlPacket();
TheChrisyd 4:bb78bedae411 42 wireless_joypad.attachRXHandler(&nRF2401A_rx, 0);
TheChrisyd 4:bb78bedae411 43 #endif
TheChrisyd 2:20a89dc286d5 44 makeGraphics();
TheChrisyd 2:20a89dc286d5 45 Coprocessor::reset(samplePlaybackBuffer);
TheChrisyd 4:bb78bedae411 46 randomSeed(GD.rd(FRAME));
TheChrisyd 2:20a89dc286d5 47 resetGameSounds();
TheChrisyd 2:20a89dc286d5 48 initGame();
TheChrisyd 2:20a89dc286d5 49 }
TheChrisyd 2:20a89dc286d5 50
TheChrisyd 2:20a89dc286d5 51 void loop() {
TheChrisyd 2:20a89dc286d5 52 GD.waitvblank();
TheChrisyd 2:20a89dc286d5 53 updateGame();
TheChrisyd 2:20a89dc286d5 54 updateGameSounds();
TheChrisyd 2:20a89dc286d5 55
TheChrisyd 2:20a89dc286d5 56 // Debugging/info
TheChrisyd 2:20a89dc286d5 57 if (0) {
TheChrisyd 2:20a89dc286d5 58 joystick.dump(0,33); // Show the joystick state
TheChrisyd 2:20a89dc286d5 59 int yline = Coprocessor::yline();
TheChrisyd 2:20a89dc286d5 60 showNumber(yline,0,31);
TheChrisyd 2:20a89dc286d5 61 }
TheChrisyd 2:20a89dc286d5 62 // Screenshot when you press the select button
TheChrisyd 2:20a89dc286d5 63 if (0 and joystick.isPressed(Joystick::buttonSelect)) {
TheChrisyd 2:20a89dc286d5 64 sendScreenshot();
TheChrisyd 2:20a89dc286d5 65 }
TheChrisyd 2:20a89dc286d5 66 }
TheChrisyd 2:20a89dc286d5 67
TheChrisyd 2:20a89dc286d5 68
TheChrisyd 2:20a89dc286d5 69 int main() {
TheChrisyd 2:20a89dc286d5 70 setup();
TheChrisyd 2:20a89dc286d5 71 while (1) {
TheChrisyd 2:20a89dc286d5 72 loop();
TheChrisyd 2:20a89dc286d5 73 }
TheChrisyd 0:8a7c58553b44 74 }