Sleep Monitoring system using Hexiwear Accelerometer and Python for finding distributiion about mean data.
main.cpp@0:7b877196b84a, 2018-03-20 (annotated)
- Committer:
- nikhilchougule
- Date:
- Tue Mar 20 13:12:47 2018 +0000
- Revision:
- 0:7b877196b84a
SleepMonitoringSystem
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikhilchougule | 0:7b877196b84a | 1 | #include "mbed.h" |
nikhilchougule | 0:7b877196b84a | 2 | #include "FXOS8700.h" |
nikhilchougule | 0:7b877196b84a | 3 | // Check out the full featured example application for interfacing to |
nikhilchougule | 0:7b877196b84a | 4 | // the Accelerometer/Magnetometer device at the following URL |
nikhilchougule | 0:7b877196b84a | 5 | // https://developer.mbed.org/users/trm/code/fxos8700cq_example// |
nikhilchougule | 0:7b877196b84a | 6 | DigitalOut led1(LED_GREEN); |
nikhilchougule | 0:7b877196b84a | 7 | // Initialize Serial port |
nikhilchougule | 0:7b877196b84a | 8 | Serial pc(USBTX, USBRX); |
nikhilchougule | 0:7b877196b84a | 9 | FXOS8700 accel(PTC11, PTC10); |
nikhilchougule | 0:7b877196b84a | 10 | FXOS8700 mag(PTC11, PTC10); |
nikhilchougule | 0:7b877196b84a | 11 | // main() runs in its own thread in the OS |
nikhilchougule | 0:7b877196b84a | 12 | // (note the calls to Thread::wait below for delays) |
nikhilchougule | 0:7b877196b84a | 13 | int main() { |
nikhilchougule | 0:7b877196b84a | 14 | // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 |
nikhilchougule | 0:7b877196b84a | 15 | accel.accel_config(); |
nikhilchougule | 0:7b877196b84a | 16 | mag.mag_config(); |
nikhilchougule | 0:7b877196b84a | 17 | float accel_data[3]; float accel_rms=0.0; |
nikhilchougule | 0:7b877196b84a | 18 | float mag_data[3]; float mag_rms=0.0; |
nikhilchougule | 0:7b877196b84a | 19 | //printf("Begin Data Acquisition from FXOS8700CQ sensor....\r\n\r\n"); |
nikhilchougule | 0:7b877196b84a | 20 | wait(1.5); |
nikhilchougule | 0:7b877196b84a | 21 | while (1) { |
nikhilchougule | 0:7b877196b84a | 22 | led1 = !led1; |
nikhilchougule | 0:7b877196b84a | 23 | // Example data printing |
nikhilchougule | 0:7b877196b84a | 24 | accel.acquire_accel_data_g(accel_data); |
nikhilchougule | 0:7b877196b84a | 25 | accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3); |
nikhilchougule | 0:7b877196b84a | 26 | printf("%4.2f %4.2f %4.2f\n\r",accel_data[0],accel_data[1],accel_data[2]); |
nikhilchougule | 0:7b877196b84a | 27 | wait(0.01); |
nikhilchougule | 0:7b877196b84a | 28 | //mag.acquire_mag_data_uT(mag_data); |
nikhilchougule | 0:7b877196b84a | 29 | //mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3); |
nikhilchougule | 0:7b877196b84a | 30 | //printf("Magnetometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\n\r",mag_data[0],mag_data[1],mag_data[2],mag_rms); |
nikhilchougule | 0:7b877196b84a | 31 | //wait(0.01); |
nikhilchougule | 0:7b877196b84a | 32 | Thread::wait(500); |
nikhilchougule | 0:7b877196b84a | 33 | } |
nikhilchougule | 0:7b877196b84a | 34 | } |
nikhilchougule | 0:7b877196b84a | 35 |