Nino Der Kinderen
/
nRF24L01P_ProjectSensor
se
Fork of nRF24L01P_Project by
Diff: main.cpp
- Revision:
- 4:25a500ef61fc
- Parent:
- 3:1f92895432d2
- Child:
- 5:87f98ed1ee9a
--- a/main.cpp Wed May 13 07:22:11 2015 +0000 +++ b/main.cpp Mon May 18 16:27:46 2015 +0000 @@ -7,23 +7,22 @@ DigitalOut myled1(LED1); DigitalOut myled2(LED2); -AnalogIn LM35(p15); -AnalogIn LDR(p16); +AnalogIn LM35(p20); +AnalogIn LDR(p19); -#define TRANSFER_SIZE 32 +#define TRANSFER_SIZE 5 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; -int txDataCnt = 0; +int txDataCnt = 5; int rxDataCnt = 0; -float AvgTemp = 0; -float AvgLight = 0; +float Light = 0; float TemperatureC = 0; -float TemperatureF = 0; -float a[10]; +char a[5]; -int i = 0; +float i = 0; +float j = 0; int main() { @@ -31,11 +30,8 @@ // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) // Only handles 4 byte transfers in the ATMega code. - -/* my_nrf24l01p.powerUp(); - - //my_nrf24l01p.setRxAddress(0xE7E7E7E7E7,5); + my_nrf24l01p.setTxAddress(0xE7E7E7E7E7,5); my_nrf24l01p.setRfFrequency(2450); my_nrf24l01p.setRfOutputPower(0); @@ -43,7 +39,7 @@ //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); @@ -51,6 +47,7 @@ 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() ); @@ -63,54 +60,67 @@ my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); - //Put device in transmitmode - my_nrf24l01p.setTransmitMode(); - + my_nrf24l01p.setReceiveMode(); my_nrf24l01p.enable(); -*/ - void ReadAvgTemp(void); - void ReadAvgLight(void); + while (1) { - - ReadAvgTemp(); - ReadAvgLight(); - TemperatureC = (AvgTemp * 3.685503686 * 100); - TemperatureF = (9.0 * TemperatureC) / 5.0 + 32.0; - pc.printf(" Temperature "); - pc.printf("%.2f C %.2f F",AvgTemp, AvgTemp); - pc.printf(" Lichtintensiteit "); - pc.printf("%.2f ", AvgLight); - - + i = 0; + j = 0; - + 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... - if ( pc.readable() ) { + + // If we've received anything over the host serial link. - // ...add it to the transmit buffer - txData[txDataCnt++] = pc.getc(); - - //pc.printf("lengte txData: %d \n\r", sizeof(txData)); - //pc.printf("txData count: %d \n\r", txDataCnt); + // ...add it to the transmit buffer + sprintf(a, "%f", i * 3.3); + 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[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]); + + } + + - // If the transmit buffer is full - if ( txDataCnt >= sizeof(txData) ) { - //pc.printf("eerste if \n\r"); - // Send the transmitbuffer via the nRF24L01+ - my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); + //pc.printf("lengte txData: %d \n\r", sizeof(txData)); + //pc.printf("txData count: %d \n\r", txDataCnt); - txDataCnt = 0; - } + // If the transmit buffer is full + //if ( txDataCnt >= sizeof(txData) ) { + //pc.printf("eerste if \n\r"); + // Send the transmitbuffer via the nRF24L01+ + 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; - } + // Toggle LED1 (to help debug Host -> nRF24L01+ communication) + myled1 = !myled1; - // If we've received anything in the nRF24L01+... + + /*// 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 @@ -127,84 +137,4 @@ }*/ } } - - - - - -void ReadAvgTemp() -{ - for(i=0; i<10; i++) - { - a[i] = LM35.read(); - wait(.02); - } - - for(i=0; i<10; i++) - { - AvgTemp = AvgTemp+(a[i]/10); - } -} - -void ReadAvgLight() -{ - for(i=0;i<10;i++) - { - a[i] = LDR.read(); - wait(.02); - } - - for(i=0;i<10;i++) - { - AvgLight = AvgLight+(a[i]/10); - } -} - - - - - -/* -void SetAdresses () -{ - //Note that Pipes 0 & 1 have 3, 4 or 5 byte addresses, while Pipes 2..5 only use the lowest byte (bits 7..0) of the address provided here, - //and use 2, 3 or 4 bytes from Pipe 1's address. The width parameter is ignored for Pipes 2..5. - - my_nrf24l01p.setRxAddress(0xE7E7E7E7E7, 5, 0); //Set Device void setRxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, - // int pipe = NRF24L01P_PIPE_P0 - // ) - my_nrf24l01p.setRxAddress(0xB3B4B5B6F1, 10, 1); //Set Device void setRxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, - // int pipe = NRF24L01P_PIPE_P0 - // ) - - my_nrf24l01p.setRxAddress(0xB3B4B5B6CD, 10, 2); //Set Device void setRxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, - // int pipe = NRF24L01P_PIPE_P0 - // ) - - my_nrf24l01p.setRxAddress(0xB3B4B5B6A3, 10, 3); //Set Device void setRxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, - // int pipe = NRF24L01P_PIPE_P0 - // ) - - my_nrf24l01p.setRxAddress(0xB3B4B5B60F, 10, 4); //Set Device void setRxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, - // int pipe = NRF24L01P_PIPE_P0 - // ) - - my_nrf24l01p.setRxAddress(0xB3B4B5B605, 10, 5); //Set Device void setRxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH, - // int pipe = NRF24L01P_PIPE_P0 - // ) - - - - //Note that the address width is shared with the Receive pipes, so a change to that address width affect transmissions. - - my_nrf24l01p.setTxAddress(0xE7E7E7E7E7,5); //void setTxAddress ( unsigned long long address = DEFAULT_NRF24L01P_ADDRESS, - // int width = DEFAULT_NRF24L01P_ADDRESS_WIDTH - // ) -} -*/ \ No newline at end of file + \ No newline at end of file