mouse transmitter

Dependencies:   MMA8451Q TSI USBDevice mbed nRF24L01P

Fork of kl25Z_nRF_TX by Ganesh Gore

Files at this revision

API Documentation at this revision

Comitter:
aji052
Date:
Sun Oct 11 10:17:20 2015 +0000
Parent:
1:2c6781177599
Commit message:
blah

Changed in this revision

Transmitter.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 2c6781177599 -r 36a1ad8ff689 Transmitter.cpp
--- a/Transmitter.cpp	Sun Oct 11 09:39:54 2015 +0000
+++ b/Transmitter.cpp	Sun Oct 11 10:17:20 2015 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 #include "nRF24L01P.h"
-//#include "USBMouse.h"
+#include "USBMouse.h"
 #include "TSISensor.h"
 #include "MMA8451Q.h"
 #define MMA8451_I2C_ADDRESS (0x1d<<1) 
@@ -11,21 +11,24 @@
 
  
  TSISensor tsi;
-//USBMouse mouse;
+USBMouse mouse;
 float value;
 int xaxis, yaxis, zaxis;
 
 int main()
-{
-    char count[3];
+{   
+    char count[4];
     char TxDataCnt;
+    
+    char RxDataCnt;
     char temp;
 
-
+    
     my_nrf24l01p.powerUp();
     my_nrf24l01p.setRfFrequency(2510);
       
-
+   if(count[3]==0)
+   {
     // Display the (default) setup of the nRF24L01+ chip
     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
@@ -35,7 +38,7 @@
 
     pc.printf( "Simple Transmitter (0 - 9 Counter) \r\n");
 
-    TxDataCnt = 3;
+    TxDataCnt = 4;
     my_nrf24l01p.setTransferSize(TxDataCnt);
 
     my_nrf24l01p.enable();
@@ -49,13 +52,114 @@
         // Send the Transmit buffer via the nRF24L01+
         temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt );
 
-        pc.printf( "Sending %d - %d %d %d\r\n",temp,count[0],count[1],count[2]);
+        pc.printf( "Sending %d - %d %d %d\r\n",temp,count[0],count[1],count[2],count[3]);
 
         // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
         
             
-        
+        if ( count[0] >=280 || count[1] >= 280 )
+        {count[3]++;
+         break;}
         
         
     }
+    
+    
+    
+    }
+    
+    
+    if( count[3]==1)
+    {
+        // Display the (default) setup of the nRF24L01+ chip
+    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
+    pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
+    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
+    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
+    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
+
+    pc.printf( "Simple 2 Byte Receiver\r\n" );
+    
+    RxDataCnt = 3;
+    my_nrf24l01p.setTransferSize( RxDataCnt );
+    
+    my_nrf24l01p.setReceiveMode();
+    my_nrf24l01p.enable();
+
+    while (1) {
+
+        // If we've received anything in the nRF24L01+...
+        if ( my_nrf24l01p.readable() ) {
+
+            // ...read the data into the receive buffer
+            temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt );
+
+
+            pc.printf( "%d %d %d\r\n",count[0],count[1],count[2]);
+
+int xaxis = int(count[0]);
+int yaxis = int(count[1]);
+int value = int(count[2]);
+
+
+            // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
+            if( xaxis >=0 && xaxis <=50 )
+    mouse.move(0,-3);
+    
+    if( xaxis >=150 && xaxis <=200 )
+    mouse.move(0,3);
+    
+    if( xaxis >50 && xaxis <=80 )
+    mouse.move(0,-1);
+    
+    if( xaxis >=120 && xaxis <150 )
+    mouse.move(0,1);
+    
+    
+    
+    if( yaxis >50 && yaxis <=80 )
+    mouse.move(1,0);
+    
+    if( yaxis >=120 && yaxis <150 )
+    mouse.move(-1,0);
+    
+    if( yaxis >=0 && yaxis <=50 )
+    mouse.move(3,0);
+    
+    if( yaxis >=150 && yaxis <=200 )
+    mouse.move(-3,0);
+    
+    if( xaxis >=0 && xaxis <=80 && yaxis >=0 && yaxis <=80 )
+    mouse.move(2,-2);
+    
+    if( xaxis >=120 && xaxis <=200 && yaxis >=0 && yaxis <=80 )
+    mouse.move(2,2);
+    
+    if( xaxis >=0 && xaxis <=80 && yaxis >=120 && yaxis <=200 )
+    mouse.move(-2,-2);
+    
+    if( xaxis >=120 && xaxis <=200 && yaxis >=120 && yaxis <=200)
+    mouse.move(-2,2);
+    
+    if(value>50)
+    {mouse.press(MOUSE_LEFT);
+     wait(0.1);
+     mouse.release(MOUSE_LEFT);
+    }
+    
+    if(value<50 && value>0)
+    {mouse.press(MOUSE_RIGHT);
+     wait(0.1);
+     mouse.release(MOUSE_RIGHT);
+    }
+    else
+     mouse.move(0,0);
+     
+     if ( xaxis >=280 || yaxis >= 280 )
+        {count[3]=0;
+         break;}
+        }
+    }
+    }
+    
 }