mouse

Dependencies:   MMA8451Q TSI mbed nRF24L01P

Committer:
monish
Date:
Wed Jun 29 05:33:44 2016 +0000
Revision:
0:d303f96c89d0
usb mouse;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
monish 0:d303f96c89d0 1 #include "mbed.h"
monish 0:d303f96c89d0 2 #include "nRF24L01P.h"
monish 0:d303f96c89d0 3 #include "MMA8451Q.h"
monish 0:d303f96c89d0 4 //#include "TSISensor.h"
monish 0:d303f96c89d0 5 #define addr (0x1D<<1)
monish 0:d303f96c89d0 6
monish 0:d303f96c89d0 7 Serial pc(USBTX, USBRX); // tx, rx
monish 0:d303f96c89d0 8 MMA8451Q acc(PTE25, PTE24, addr); //accelerometer
monish 0:d303f96c89d0 9 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq
monish 0:d303f96c89d0 10 //TSISensor tsi;
monish 0:d303f96c89d0 11
monish 0:d303f96c89d0 12 int main()
monish 0:d303f96c89d0 13 {
monish 0:d303f96c89d0 14 float x=0;
monish 0:d303f96c89d0 15 float y=0;
monish 0:d303f96c89d0 16 int x1,y1;
monish 0:d303f96c89d0 17 //float z=0;
monish 0:d303f96c89d0 18 //float sensor=0;
monish 0:d303f96c89d0 19 char buff[2]; // make it 4
monish 0:d303f96c89d0 20 char TxDataCnt;
monish 0:d303f96c89d0 21 char temp;
monish 0:d303f96c89d0 22
monish 0:d303f96c89d0 23 //set tx and rx address for pipe0: 5 bytes long; different for every pipe
monish 0:d303f96c89d0 24 long long TxAddress_PIPE0 = 0xE7E7E7E7E7;
monish 0:d303f96c89d0 25 long long RxAddress_PIPE0 = 0xE7E7E7E7E7;
monish 0:d303f96c89d0 26
monish 0:d303f96c89d0 27 my_nrf24l01p.powerUp();
monish 0:d303f96c89d0 28 my_nrf24l01p.setRfFrequency(2425);
monish 0:d303f96c89d0 29
monish 0:d303f96c89d0 30 //setting tx and rx address
monish 0:d303f96c89d0 31 my_nrf24l01p.setTxAddress(TxAddress_PIPE0);
monish 0:d303f96c89d0 32
monish 0:d303f96c89d0 33 //set rx address with default width and pipe number
monish 0:d303f96c89d0 34 my_nrf24l01p.setRxAddress(RxAddress_PIPE0, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0);
monish 0:d303f96c89d0 35
monish 0:d303f96c89d0 36 // Display the (default) setup of the nRF24L01+ chip
monish 0:d303f96c89d0 37 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
monish 0:d303f96c89d0 38 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
monish 0:d303f96c89d0 39 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
monish 0:d303f96c89d0 40 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
monish 0:d303f96c89d0 41 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
monish 0:d303f96c89d0 42 pc.printf( "Wireless Sensor Network - Mouse Transmitter\r\n" );
monish 0:d303f96c89d0 43
monish 0:d303f96c89d0 44 TxDataCnt = 10; //make it 4
monish 0:d303f96c89d0 45 my_nrf24l01p.setTransferSize(TxDataCnt);
monish 0:d303f96c89d0 46
monish 0:d303f96c89d0 47 my_nrf24l01p.enable();
monish 0:d303f96c89d0 48
monish 0:d303f96c89d0 49
monish 0:d303f96c89d0 50 while (1) {
monish 0:d303f96c89d0 51
monish 0:d303f96c89d0 52
monish 0:d303f96c89d0 53 x=acc.getAccX(); //X-axis value
monish 0:d303f96c89d0 54 y=acc.getAccY(); //Y-axis value
monish 0:d303f96c89d0 55 //z=acc.getAccZ(); //Z-axis value
monish 0:d303f96c89d0 56 x1=x*30;
monish 0:d303f96c89d0 57 y1=y*30;
monish 0:d303f96c89d0 58 //z1=z*5;
monish 0:d303f96c89d0 59
monish 0:d303f96c89d0 60 //sensor=tsi.readPercentage();
monish 0:d303f96c89d0 61 //s=sensor*100;
monish 0:d303f96c89d0 62
monish 0:d303f96c89d0 63 pc.printf("\r\n x = %f y = %f ",x,y);
monish 0:d303f96c89d0 64 pc.printf("\r\n x1 = %d y1 = %d",x1,y1);
monish 0:d303f96c89d0 65
monish 0:d303f96c89d0 66
monish 0:d303f96c89d0 67
monish 0:d303f96c89d0 68 buff[0] = x1;
monish 0:d303f96c89d0 69 buff[1] = y1;
monish 0:d303f96c89d0 70 //buff[2] = z1;
monish 0:d303f96c89d0 71 //buff[3] = s;
monish 0:d303f96c89d0 72
monish 0:d303f96c89d0 73 temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,buff, TxDataCnt );
monish 0:d303f96c89d0 74 pc.printf("\r\n%d byte x= %d y= %d",temp,buff[0],buff[1]); // add buff[2 & 3]
monish 0:d303f96c89d0 75
monish 0:d303f96c89d0 76 //wait_ms(1);
monish 0:d303f96c89d0 77 }
monish 0:d303f96c89d0 78 }