Xbee comms for sensor box
Dependencies: MMA8451Q mbed nRF24L01P
Fork of Sensor_Box by
Revision 7:03334e89478d, committed 2015-07-09
- Comitter:
- jaehughes
- Date:
- Thu Jul 09 15:56:58 2015 +0000
- Parent:
- 6:fb76109304df
- Commit message:
- Latest;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r fb76109304df -r 03334e89478d main.cpp --- a/main.cpp Wed Jul 01 22:13:56 2015 +0000 +++ b/main.cpp Thu Jul 09 15:56:58 2015 +0000 @@ -4,7 +4,6 @@ #include <vector> #include <math.h> -#define MMA8451_I2C_ADDRESS (0x1d<<1) #define TRANSFER_SIZE 24 #define ARRAY_LENGTH 20 @@ -51,7 +50,10 @@ pir_data.pop_back(); noise_data.pop_back(); - printf("%f\n", light_data); + printf("%f\n\r", light); + printf("%f\n\r", temp); + printf("%f\n\r", pir); + printf("%f\n\r", noise); } void average() @@ -60,10 +62,10 @@ int temp_sum = 0; int noise_sum = 0; float light_avg, temp_avg, noise_avg, light_var, temp_var, noise_var; - float light_residuals =0; - float temp_residuals = 0 ; - float noise_residuals = 0; - + float light_residuals =0; + float temp_residuals = 0 ; + float noise_residuals = 0; + for (int i = 0; i < ARRAY_LENGTH; i++) { light_sum += light_data[i]; temp_sum += temp_data[i]; @@ -72,17 +74,17 @@ light_avg = light_sum / (float)ARRAY_LENGTH; temp_avg = temp_sum / (float)ARRAY_LENGTH; noise_avg = noise_sum / (float)ARRAY_LENGTH; - + /* Compute variance and standard deviation */ for (int i = 0; i < ARRAY_LENGTH; i++) { - light_residuals += pow((light_data[i] - light_avg), 2); - temp_residuals += pow((temp_data[i] - temp_avg), 2); - noise_residuals += pow((noise_data[i] - noise_avg), 2); + light_residuals += pow((light_data[i] - light_avg), 2); + temp_residuals += pow((temp_data[i] - temp_avg), 2); + noise_residuals += pow((noise_data[i] - noise_avg), 2); } light_var = light_residuals/(float)ARRAY_LENGTH; temp_var = temp_residuals/(float)ARRAY_LENGTH; noise_var = noise_residuals/(float)ARRAY_LENGTH; - + printf("Light Average = %.2f\n", light_avg); printf("Temp Average = %.2f\n", temp_avg); printf("Noise Average = %.2f\n", noise_avg); @@ -93,7 +95,7 @@ int main() { - MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); + // MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); light_data.assign (ARRAY_LENGTH,0); temp_data.assign (ARRAY_LENGTH,0); @@ -120,11 +122,11 @@ my_nrf24l01p.setReceiveMode(); my_nrf24l01p.enable(); - printf("MMA8451 ID: %d\n", acc.getWhoAmI()); + // printf("MMA8451 ID: %d\n", acc.getWhoAmI()); while (1) { getdata(); - average(); + //average(); // txDataCnt = sprintf(txData, " %1.3f %1.3f %1.3f\n", x,y,z); //my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); myled1 = !myled1;