Project wireless

Dependencies:   mbed nRF24L01P

Fork of nRF24L01P_Project by Nino Der Kinderen

Revision:
3:1f92895432d2
Parent:
2:178e089b3ce9
Child:
4:25a500ef61fc
--- a/main.cpp	Thu May 07 16:39:31 2015 +0000
+++ b/main.cpp	Wed May 13 07:22:11 2015 +0000
@@ -7,42 +7,87 @@
 
 DigitalOut myled1(LED1);
 DigitalOut myled2(LED2);
+AnalogIn LM35(p15);
+AnalogIn LDR(p16);
+
+#define TRANSFER_SIZE   32
+
+char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
+
+int txDataCnt = 0;
+int rxDataCnt = 0;
+
+float AvgTemp = 0;
+float AvgLight = 0;
+float TemperatureC = 0;
+float TemperatureF = 0;    
+float a[10]; 
+
+int i = 0;
+
 
 int main() {
 
 // 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.
-#define TRANSFER_SIZE   32
+// "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
+// Only handles 4 byte transfers in the ATMega code.
 
-    char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
-    int txDataCnt = 0;
-    int rxDataCnt = 0;
-
+/*
     my_nrf24l01p.powerUp();
     
-    //Set Device
-    my_nrf24l01p.setTxAddress(0xE7E7E7E7E7,5);
     //my_nrf24l01p.setRxAddress(0xE7E7E7E7E7,5);
     my_nrf24l01p.setRfFrequency(2450);
-    my_nrf24l01p.setRfOutputPower(0);
+    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() );
+    pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency()   );
     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
-    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
-    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
-    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(0) );
+    pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate()   );
+    pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress()   );
+    pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(0)  );
 
     pc.printf( "Type keys to test transfers:\r\n  (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE );
 
     my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
 
-    my_nrf24l01p.setReceiveMode();
+ 
+    //Put device in transmitmode
+    my_nrf24l01p.setTransmitMode();             
+    
     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);     
+         
+      
+        
+         
+        wait(1);    
+/*   
         // If we've received anything over the host serial link...
         if ( pc.readable() ) {
 
@@ -79,6 +124,87 @@
 
             // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
             myled2 = !myled2;
-        }
+        }*/
     }
 }
+
+
+
+
+
+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