Nino Der Kinderen / Mbed 2 deprecated nRF24L01P_ProjectSensor

Dependencies:   mbed nRF24L01P

Fork of nRF24L01P_Project by Michiel Van Endert

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "nRF24L01P.h"
00003 
00004 Serial pc(USBTX, USBRX); // tx, rx
00005 
00006 nRF24L01P my_nrf24l01p(p5, p6, p7, p8, p9, p10);    // mosi, miso, sck, csn, ce, irq
00007 
00008 DigitalOut myled1(LED1);
00009 DigitalOut myled2(LED2);
00010 AnalogIn LM35(p20);
00011 AnalogIn LDR(p19);
00012 
00013 #define TRANSFER_SIZE   6
00014 
00015 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
00016 
00017 int txDataCnt = 6;
00018 int rxDataCnt = 0;
00019 
00020 float Light = 0;
00021 float TemperatureC = 0;
00022 char a[6]; //temp
00023 char b[6];//licht
00024 float i = 0;//temp
00025 float j = 0;//licht
00026 
00027 int main() {
00028 
00029 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
00030 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
00031 // Only handles 4 byte transfers in the ATMega code.
00032     my_nrf24l01p.powerUp();
00033     my_nrf24l01p.setTxAddress(0xE7E7E7E7E7,5);
00034     my_nrf24l01p.setRfFrequency(2450);
00035     my_nrf24l01p.setRfOutputPower(0);    
00036     
00037     
00038     // Display the (default) setup of the nRF24L01+ chip
00039     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency()   );
00040     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
00041     pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate()   );
00042     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress()   );
00043     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(0)  );
00044 
00045     pc.printf( "Type keys to test transfers:\r\n  (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
00046 
00047     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
00048 
00049     //Put device in receivemode
00050     my_nrf24l01p.setReceiveMode();             
00051     my_nrf24l01p.enable();
00052 
00053 
00054     while (1) {
00055         wait(0.2); 
00056         i = 0;
00057         j = 0;
00058         txDataCnt = 6;
00059         
00060         for (int t = 0; t < 100; t++)
00061         {
00062             i = i + LM35.read();     
00063         }
00064         for (int y = 0; y < 100; y++)
00065         {
00066             j = j + LDR.read();     
00067         }
00068         pc.printf("Temperatuur in %4.1f graden C \n\r", i * 3.3);    
00069         pc.printf("Lichtsterkte in %4.1f procent \n\r", j);     
00070            
00071         sprintf(a, "%f", i * 3.3); //float to char
00072         sprintf(b, "%f", j); //float to char
00073         /*
00074         pc.printf("a %f \n\r", a);       
00075         pc.printf("a1 %c \n\r", a[0]);
00076         pc.printf("a2 %c \n\r", a[1]);
00077         pc.printf("a3 %c \n\r", a[2]);
00078         pc.printf("a4 %c \n\r", a[3]);
00079         pc.printf("a5 %c \n\r", a[4]);                               
00080         */
00081         
00082         
00083         for(int x = 0; x <=5; x++)
00084         {
00085         txData[x] = a[x];
00086         /*pc.printf("txData[0] %c \n\r", txData[0]);
00087         pc.printf("txData[1] %c \n\r", txData[1]);
00088         pc.printf("txData[2] %c \n\r", txData[2]);
00089         pc.printf("txData[3] %c \n\r", txData[3]);
00090         pc.printf("txData[4] %c \n\r", txData[4]); */   
00091         }
00092         txData[5] = 'T';
00093         // Toggle LED1 debug(Temperatuur)
00094         myled1 = !myled1;
00095         my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
00096         pc.printf("Ik heb mijn temperatuur verzonden\r\n");
00097         wait(0.3); 
00098         for(int x = 0; x <=5; x++)
00099         {
00100             txData[x] = b[x];
00101         /*pc.printf("txData[0] %c \n\r", txData[0]);
00102         pc.printf("txData[1] %c \n\r", txData[1]);
00103         pc.printf("txData[2] %c \n\r", txData[2]);
00104         pc.printf("txData[3] %c \n\r", txData[3]);
00105         pc.printf("txData[4] %c \n\r", txData[4]); */   
00106         }
00107         txData[5] = 'L';
00108         my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
00109         pc.printf("Ik heb mijn lichtwaarde verzonden\r\n");
00110         // Toggle LED2 debug(lichtwaarde)
00111         myled2 = !myled2;
00112     }
00113 }
00114