A wireless accelerometer based joypad using FRDM-KL25Z for the Gameduino based space invaders.

Dependencies:   MMA8451Q mbed nRF2401A

Fork of nRF2401A_Hello_World by Chris Dick

nRF2401A connected to the KL25Z board:

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

Files at this revision

API Documentation at this revision

Comitter:
TheChrisyd
Date:
Sun Oct 06 16:19:52 2013 +0000
Parent:
2:440c95f796ac
Child:
4:4a84fcba7bd4
Commit message:
Receive callback corrected.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
nRF2401A.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Oct 04 19:56:17 2013 +0000
+++ b/main.cpp	Sun Oct 06 16:19:52 2013 +0000
@@ -5,31 +5,28 @@
 #define TX
 #define RX
 
+Serial pc(USBTX, USBRX);
 DigitalOut  myled(LED1);
-DigitalOut  debug(LED2);
+
 #ifdef TX
 nRF2401A    rf1(p10, p11, p12, p13, p14);
 #endif
+
 #ifdef RX
 nRF2401A    rf2(p21, p22, p23, p24, p25);
-#endif
 
-Serial pc(USBTX, USBRX);
-#ifdef RX
 bool rx_recieved = false;
-nRF2401A_rx_handler_t nRF2401A_rx ()
+
+void nRF2401A_rx (void *arg) 
 {
-     //rf2.printDataPacket(pc);
-     debug = !debug;
      rx_recieved = true;
-     return;
 }
 #endif
-int main() {
-
+int main() 
+{
     wait(0.005);
-
     pc.printf("Hello nRF2401A\n\r");
+    
 #ifdef TX    
     rf1.setDataPayloadLength(4 << 3)
        .setAddress(0x0, 0x0, 0xa6, 0xa6, 0xa6, 3 << 3)
@@ -37,9 +34,14 @@
        .setDataRate(nRF2401A::BIT_RATE_250KBITS)
        .setChannel(0x02);
        
-  //  rf1.printControlPacket(pc);
+    rf1.printControlPacket(pc);
+    rf1.flushControlPacket();
+    
+    nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53};
+    uint8_t msg[] = {0x01, 0x01, 0x01, 0x01};
+    uint32_t *msg32 = (uint32_t *) msg;
+#endif
 
-#endif
 #ifdef RX   
     rf2.setDataPayloadLength(4 << 3)
        .setAddress(0x0, 0x0, 0x53, 0x53, 0x53, 3 << 3)
@@ -47,36 +49,30 @@
        .setDataRate(nRF2401A::BIT_RATE_250KBITS)
        .setChannel(0x02);
        
-  //  rf2.printControlPacket(pc);
-    
-    rf2.attachRXHandler(nRF2401A_rx(), 0);
-#endif
-#ifdef TX    
-    rf1.flushControlPacket();
-#endif
-#ifdef RX
-    rf2.flushControlPacket();
-#endif
-#ifdef TX   
-    nRF2401A::address_t rf2_addr = {0x0, 0x0, 0x53, 0x53, 0x53};
-    uint8_t msg[] = {0x01, 0x01, 0x01, 0x01};
-    uint32_t *msg32 = (uint32_t *) msg;
+    rf2.printControlPacket(pc);
+    rf2.flushControlPacket();   
+    rf2.attachRXHandler(&nRF2401A_rx, 0);
 #endif
       
-    while(1) {
+    while(1) 
+    {
+    
 #ifdef TX             
         rf1.sendMsg(rf2_addr, 3 << 3, msg, 4 << 3);
         *msg32 += 1;
 #endif
+
         myled = 1;
         wait(0.25);
+        
 #ifdef RX  
         if (rx_recieved)
         {      
             rf2.printDataPacket(pc);
             rx_recieved = false;
         }
-#endif       
+#endif 
+      
         myled = 0;
         wait(0.25);
     }
--- a/nRF2401A.lib	Fri Oct 04 19:56:17 2013 +0000
+++ b/nRF2401A.lib	Sun Oct 06 16:19:52 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/TheChrisyd/code/nRF2401A/#8c57f88ff574
+http://mbed.org/users/TheChrisyd/code/nRF2401A/#e8523ef6e472