Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MotionSensor mbed
Fork of Assignment2_ver5 by
motion.cpp
00001 //#include "rtos.h" 00002 #include "Hardware.h" 00003 #include "FXOS8700Q.h" 00004 #include "PaceHeart.h" 00005 00006 FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); 00007 00008 //PaceHeart* Pacing = new PaceHeart; 00009 00010 /* Constants and Declares */ 00011 int numCount; 00012 int const MAX_NUM_COUNTS = 3; 00013 int const TIMING_PERIOD = 20; // Sensor polling interval 00014 00015 uint8_t motion_exceeded_threshold = 0; 00016 00017 void initialize_motion () { 00018 acc.enable(); 00019 } 00020 00021 bool isMotionThresholdExceeded () { 00022 return motion_exceeded_threshold; 00023 } 00024 00025 void resetMotionDetection () { 00026 motion_exceeded_threshold = 0; 00027 } 00028 00029 /**** Function: a_count 00030 * return: void 00031 * parameters: none 00032 * A function called if motion detection interrupt flag is set. Maintains 00033 * a global counter and sets a timer to keep track of number of flags within 00034 * timing limit. 00035 */ 00036 void a_count(void) { 00037 /* step 1 increment the counter */ 00038 numCount++; 00039 00040 00041 if (numCount >= MAX_NUM_COUNTS) { 00042 //rled = !rled; // toggle LEDs to show acceleration threshold reached 00043 //gled = !gled; // toggle LEDS to show acceleration threshold reached 00044 00045 motion_exceeded_threshold = 1; 00046 } 00047 } 00048 00049 void motion_thread (PaceHeart &Pacing) { 00050 while(true) { 00051 00052 float xAcc, yAcc, zAcc; 00053 acc.getX(&xAcc); 00054 acc.getY(&yAcc); 00055 acc.getZ(&zAcc); 00056 float magtd = xAcc*xAcc + yAcc*yAcc + zAcc*zAcc; 00057 00058 if (magtd > 1.0f) { // Greater than (1.5G of Accel.)^2 00059 a_count(); // increment acceleration event counter 00060 Pacing.set_dir(1); 00061 Pacing.set_p_vPaceWidth(Pacing.get_p_vPaceWidth()+0.1); 00062 Pacing.set_p_vPaceAmp(Pacing.get_p_vPaceAmp()+500); 00063 00064 } 00065 00066 wait(TIMING_PERIOD); 00067 } 00068 }
Generated on Wed Jul 13 2022 18:58:56 by
1.7.2
