![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A wireless accelerometer based joypad using FRDM-KL25Z for the Gameduino based space invaders.
Dependencies: MMA8451Q mbed nRF2401A
Fork of nRF2401A_Hello_World by
nRF2401A connected to the KL25Z board:
Diff: main.cpp
- Revision:
- 2:440c95f796ac
- Parent:
- 0:8fcb46c5fa63
- Child:
- 3:34ae527e9d41
diff -r fc964ee17649 -r 440c95f796ac main.cpp --- a/main.cpp Fri Oct 04 16:28:15 2013 +0000 +++ b/main.cpp Fri Oct 04 19:56:17 2013 +0000 @@ -6,6 +6,7 @@ #define RX DigitalOut myled(LED1); +DigitalOut debug(LED2); #ifdef TX nRF2401A rf1(p10, p11, p12, p13, p14); #endif @@ -14,7 +15,16 @@ #endif Serial pc(USBTX, USBRX); - +#ifdef RX +bool rx_recieved = false; +nRF2401A_rx_handler_t nRF2401A_rx () +{ + //rf2.printDataPacket(pc); + debug = !debug; + rx_recieved = true; + return; +} +#endif int main() { wait(0.005); @@ -27,7 +37,7 @@ .setDataRate(nRF2401A::BIT_RATE_250KBITS) .setChannel(0x02); - rf1.printControlPacket(pc); + // rf1.printControlPacket(pc); #endif #ifdef RX @@ -37,8 +47,9 @@ .setDataRate(nRF2401A::BIT_RATE_250KBITS) .setChannel(0x02); - rf2.printControlPacket(pc); + // rf2.printControlPacket(pc); + rf2.attachRXHandler(nRF2401A_rx(), 0); #endif #ifdef TX rf1.flushControlPacket(); @@ -59,9 +70,13 @@ #endif myled = 1; wait(0.25); -#ifdef RX - rf2.printDataPacket(pc); -#endif +#ifdef RX + if (rx_recieved) + { + rf2.printDataPacket(pc); + rx_recieved = false; + } +#endif myled = 0; wait(0.25); }