wireless receiver

Dependencies:   USBDevice mbed nRF24L01P

Fork of NRF_Wireless_mouse by Ananya Iyer

Files at this revision

API Documentation at this revision

Comitter:
Ananya020
Date:
Sun Oct 11 09:48:32 2015 +0000
Parent:
2:9f401852272c
Commit message:
Receiver code for wireless mouse

Changed in this revision

Receiver.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 9f401852272c -r 725a4d2e9026 Receiver.cpp
--- a/Receiver.cpp	Mon Jun 01 05:15:30 2015 +0000
+++ b/Receiver.cpp	Sun Oct 11 09:48:32 2015 +0000
@@ -1,20 +1,20 @@
 #include "mbed.h"
 #include "nRF24L01P.h"
-
+#include "USBMouse.h"
 Serial pc(USBTX, USBRX); // tx, rx
 
 nRF24L01P my_nrf24l01p(PTD6, PTE3, PTE2, PTB8, PTB9, PTD0);    // mosi, miso, sck, csn, ce, irq
 DigitalOut GreenLED(LED2);
-
-
+USBMouse mouse;
+char count[3] = {'\0'};
 int main() {
     
-    char count[2];
+    
     char RxDataCnt;
     char temp;
 
     my_nrf24l01p.powerUp();
-    my_nrf24l01p.setRfFrequency(2410);
+    my_nrf24l01p.setRfFrequency(2510);
 
     // Display the (default) setup of the nRF24L01+ chip
     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
@@ -25,7 +25,7 @@
 
     pc.printf( "Simple 2 Byte Receiver\r\n" );
     
-    RxDataCnt = 2;
+    RxDataCnt = 3;
     my_nrf24l01p.setTransferSize( RxDataCnt );
     
     my_nrf24l01p.setReceiveMode();
@@ -40,12 +40,65 @@
             temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt );
 
 
-            pc.printf( "Cnt %d = %d %d\r\n",temp,count[0],count[1]);
+            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)
-            GreenLED = !GreenLED;
-            wait_ms(10);
+            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);
         }
     }
 }
diff -r 9f401852272c -r 725a4d2e9026 USBDevice.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Sun Oct 11 09:48:32 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/mbed_official/code/USBDevice/#2af474687369