Nino Der Kinderen
/
nRF24L01P_ProjectSensor
se
Fork of nRF24L01P_Project by
Diff: main.cpp
- Revision:
- 5:87f98ed1ee9a
- Parent:
- 4:25a500ef61fc
--- a/main.cpp Mon May 18 16:27:46 2015 +0000 +++ b/main.cpp Tue May 19 17:25:21 2015 +0000 @@ -10,20 +10,19 @@ AnalogIn LM35(p20); AnalogIn LDR(p19); -#define TRANSFER_SIZE 5 +#define TRANSFER_SIZE 6 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; -int txDataCnt = 5; +int txDataCnt = 6; int rxDataCnt = 0; float Light = 0; float TemperatureC = 0; -char a[5]; - -float i = 0; -float j = 0; - +char a[6]; //temp +char b[6];//licht +float i = 0;//temp +float j = 0;//licht int main() { @@ -35,19 +34,6 @@ my_nrf24l01p.setRfFrequency(2450); my_nrf24l01p.setRfOutputPower(0); - - //my_nrf24l01p.enableAutoRetransmit(1000, 5); //enableAutoRetransmit ( int delay, int count); - // delay the delay between restransmits, in uS (250uS..4000uS) - // count number of retransmits before generating an error (1..15) - /* - //Enable autoAcknowledge - my_nrf24l01p.enableAutoAcknowledge(0); - my_nrf24l01p.enableAutoAcknowledge(1); - my_nrf24l01p.enableAutoAcknowledge(2); - my_nrf24l01p.enableAutoAcknowledge(3); - my_nrf24l01p.enableAutoAcknowledge(4); - my_nrf24l01p.enableAutoAcknowledge(5); - */ // Display the (default) setup of the nRF24L01+ chip pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); @@ -60,81 +46,69 @@ my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); - //Put device in transmitmode + //Put device in receivemode my_nrf24l01p.setReceiveMode(); my_nrf24l01p.enable(); while (1) { + wait(0.2); i = 0; j = 0; + txDataCnt = 6; for (int t = 0; t < 100; t++) { i = i + LM35.read(); } - - pc.printf("Temperatuur in %4.1f graden C \n\r", i * 3.3); - wait(1); - - // If we've received anything over the host serial link. - - // ...add it to the transmit buffer - sprintf(a, "%f", i * 3.3); + for (int y = 0; y < 100; y++) + { + j = j + LDR.read(); + } + pc.printf("Temperatuur in %4.1f graden C \n\r", i * 3.3); + pc.printf("Lichtsterkte in %4.1f procent \n\r", j); + + sprintf(a, "%f", i * 3.3); //float to char + sprintf(b, "%f", j); //float to char + /* pc.printf("a %f \n\r", a); pc.printf("a1 %c \n\r", a[0]); pc.printf("a2 %c \n\r", a[1]); pc.printf("a3 %c \n\r", a[2]); pc.printf("a4 %c \n\r", a[3]); pc.printf("a5 %c \n\r", a[4]); - + */ for(int x = 0; x <=5; x++) { txData[x] = a[x]; - - pc.printf("txData[0] %c \n\r", txData[0]); + /*pc.printf("txData[0] %c \n\r", txData[0]); pc.printf("txData[1] %c \n\r", txData[1]); pc.printf("txData[2] %c \n\r", txData[2]); pc.printf("txData[3] %c \n\r", txData[3]); - pc.printf("txData[4] %c \n\r", txData[4]); - + pc.printf("txData[4] %c \n\r", txData[4]); */ } - - - - //pc.printf("lengte txData: %d \n\r", sizeof(txData)); - //pc.printf("txData count: %d \n\r", txDataCnt); - - // If the transmit buffer is full - //if ( txDataCnt >= sizeof(txData) ) { - //pc.printf("eerste if \n\r"); - // Send the transmitbuffer via the nRF24L01+ + txData[5] = 'T'; + // Toggle LED1 debug(Temperatuur) + myled1 = !myled1; my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); - pc.printf("Ik heb verzonden"); - txDataCnt = 5; - //} - - // Toggle LED1 (to help debug Host -> nRF24L01+ communication) - myled1 = !myled1; - - - /*// If we've received anything in the nRF24L01+... - if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) { - //pc.printf("tweede if \n\r"); - // ...read the data into the receive buffer - rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); - - // Display the receive buffer contents via the host serial link - for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { - - pc.putc( rxData[i] ); - } - - // Toggle LED2 (to help debug nRF24L01+ -> Host communication) - myled2 = !myled2; - }*/ + pc.printf("Ik heb mijn temperatuur verzonden\r\n"); + wait(0.3); + for(int x = 0; x <=5; x++) + { + txData[x] = b[x]; + /*pc.printf("txData[0] %c \n\r", txData[0]); + pc.printf("txData[1] %c \n\r", txData[1]); + pc.printf("txData[2] %c \n\r", txData[2]); + pc.printf("txData[3] %c \n\r", txData[3]); + pc.printf("txData[4] %c \n\r", txData[4]); */ + } + txData[5] = 'L'; + my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); + pc.printf("Ik heb mijn lichtwaarde verzonden\r\n"); + // Toggle LED2 debug(lichtwaarde) + myled2 = !myled2; } } \ No newline at end of file