This is the first rev of HW3 for IDD

Dependencies:   MMA8451Q USBDevice mbed nRF24L01P

Revision:
1:b58cf7dd20d7
Parent:
0:d89cdf3d29f8
Child:
2:c3b748d86642
--- a/main.cpp	Mon Sep 29 08:45:58 2014 +0000
+++ b/main.cpp	Mon Sep 29 09:15:37 2014 +0000
@@ -4,9 +4,8 @@
 #include "mbed.h"
 #include "nRF24L01P.h"                              // nordic library
 
-
 #define DEBUG 0
-#define BASE 0
+#define BASE 1
 
 
 #include "USBMouseKeyboard.h"                       // for the sword - mouse/keyboard combo
@@ -58,8 +57,8 @@
 float x_b, y_b;                                           // acc bias
 
 // Debug
-DigitalOut greenLED(LED_GREEN);
-DigitalOut redLED(LED_RED);
+//DigitalOut greenLED(LED_GREEN);
+//DigitalOut redLED(LED_RED);
 
 
 AnalogIn ATTACK(A0);
@@ -160,7 +159,7 @@
                 int8_t dx = rxData[0];
                 int8_t dy = rxData[1];
                 
-              
+                
                 bool mode_stat = (rxData[2] >> 7) & 1;
                 bool joy_but = (rxData[2] >> 6) & 1;
                 bool sel_stat = (rxData[2] >> 5) & 1;
@@ -169,7 +168,9 @@
                 bool key_s = (rxData[2] >> 2) & 1;
                 bool key_d = (rxData[2] >> 1) & 1;
                 bool key_a = (rxData[2] >> 0) & 1;
-                
+
+                bool roll = (rxData[3] >> 0) & 1;
+
                 #if(BASE == 1)
                     MK.move(-dx, dy); 
 
@@ -206,8 +207,10 @@
                         MK.putc('1'+mode_count);
                         mode_count = (mode_count+1)%3;
                     }
-                    
-                    
+                    if(roll)
+                    {
+                        //MK.putc('r');
+                    }                    
                 #endif
 
 
@@ -221,9 +224,8 @@
 
                 // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
                 if (rxData[0] == 65 && rxData[1] == 66 && rxData[2] == 67){
-                    redLED = !redLED;
+//                    redLED = !redLED;
                 }
-
             }
         }
 
@@ -236,6 +238,9 @@
             int YJOYVAL = YJOY.read_u16();
             int JOYSELVAL = (int) JOYSEL;
             
+
+            bool roll = ((XJOYVAL > 65000) || (XJOYVAL < 500) ||  (YJOYVAL > 65000) || (YJOYVAL < 500)) ? true: 0;
+
             bool mode_stat = (SELECTVAL > 45000) ? true: 0;
             bool joy_but = JOYSEL == 0? true: 0;
             bool sel_stat = (SELECTVAL > 10000 && SELECTVAL < 45000) ? true: 0;
@@ -250,7 +255,7 @@
             
             pc.printf("F1: %d \t F2: %d \t X: %d \t Y: %d \t SEL: %d \r\n", ATTACKVAL, SELECTVAL, XJOYVAL, YJOYVAL, JOYSELVAL);
       
-            greenLED = JOYSEL;
+//            greenLED = JOYSEL;
 
             // Let serial read catch up on base station/PC side
             wait_us(150);
@@ -282,7 +287,7 @@
             swordData[0] = lowX;
             swordData[1] = lowY; 
             swordData[2] = char(key_stat); 
-            swordData[3] = char((sensor1ON << 7)|key_stat); 
+            swordData[3] = char(roll); 
             
             // Send the transmitbuffer via the nRF24L01+
             nordic.write( NRF24L01P_PIPE_P0, swordData, TRANSFER_SIZE );
@@ -299,7 +304,7 @@
                 #if DEBUG == 1
                     // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
                     pc.printf("x: %f \t y: %f \r\n", mouse_x,mouse_y);
-                    greenLED = !greenLED;
+//                    greenLED = !greenLED;
 
                     // Display the receive buffer contents via the host serial link
                     for ( int i = 0; i < TRANSFER_SIZE; i++ ) {
@@ -309,7 +314,7 @@
 
                     // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
                     if (rxData[0] == 65 && rxData[1] == 100 && rxData[2] == 100){
-                        redLED = !redLED;
+//                        redLED = !redLED;
                         }
                 #endif
 
@@ -319,8 +324,8 @@
                 isBladeSymphony = (rxData[0] >> 0) & 1;
                 motorON = (rxData[0] >> 1) & 1;                 // Motor ON when sword contact made
                 
-                greenLED = !isBladeSymphony;                    // LEDs active low
-                redLED = !motorON;
+//                greenLED = !isBladeSymphony;                    // LEDs active low
+//                redLED = !motorON;
                 
             }
         }