Hexiwear based rate of exercise coach

Dependencies:   FXOS8700 Hexi_OLED_SSD1351

Fork of Hexi_Accelero_Magneto_Example by Hexiwear

Committer:
tom_minnich
Date:
Sun Oct 02 00:06:34 2016 +0000
Revision:
4:adea7bcbd995
Parent:
3:9f60cb7455c4
REP Hexiwear OLED version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maclobdell 0:207337d58f96 1 #include "mbed.h"
GregC 2:f9c24c129575 2 #include "FXOS8700.h"
tom_minnich 4:adea7bcbd995 3 #include "Hexi_OLED_SSD1351.h"
tom_minnich 4:adea7bcbd995 4 #include "images.h"
GregC 2:f9c24c129575 5 // Check out the full featured example application for interfacing to the
GregC 2:f9c24c129575 6 // Accelerometer/Magnetometer device at the following URL
GregC 2:f9c24c129575 7 // https://developer.mbed.org/users/trm/code/fxos8700cq_example/
maclobdell 1:6da908234299 8
tom_minnich 4:adea7bcbd995 9 Timer acc_timer;
tom_minnich 4:adea7bcbd995 10 PwmOut rled(LED_RED);
tom_minnich 4:adea7bcbd995 11 PwmOut gled(LED_GREEN);
tom_minnich 4:adea7bcbd995 12 PwmOut bled(LED_BLUE);
tom_minnich 4:adea7bcbd995 13
tom_minnich 4:adea7bcbd995 14 #define AVG_ARRAY_SZ 32
tom_minnich 4:adea7bcbd995 15 //TWM added stuff
tom_minnich 4:adea7bcbd995 16 int last_image = 4;
tom_minnich 4:adea7bcbd995 17 int update_image;
tom_minnich 4:adea7bcbd995 18 float avg_array[AVG_ARRAY_SZ];
tom_minnich 4:adea7bcbd995 19 int read_from = 0;
tom_minnich 4:adea7bcbd995 20 int read;
tom_minnich 4:adea7bcbd995 21 int write_to = 0;
tom_minnich 4:adea7bcbd995 22 int items_stored_in_array = 0;
tom_minnich 4:adea7bcbd995 23 float avg;
tom_minnich 4:adea7bcbd995 24 #define ACC_DEADBAND ((float)0.2)
tom_minnich 4:adea7bcbd995 25 #define FILTER_MIN_STEPS 7
tom_minnich 4:adea7bcbd995 26 int filter_count=0;
tom_minnich 4:adea7bcbd995 27 unsigned char going_up = 0;
tom_minnich 4:adea7bcbd995 28 unsigned char going_down = 0;
tom_minnich 4:adea7bcbd995 29 //rep counting stuff
tom_minnich 4:adea7bcbd995 30 #define MAX_REP_DURATION 15000000 //tenths of a second 15,000,000 = 15 sec
tom_minnich 4:adea7bcbd995 31 #define TARGET_REP ((float)(2.0))
tom_minnich 4:adea7bcbd995 32 #define TOO_FAST 1.5
tom_minnich 4:adea7bcbd995 33 #define TOO_SLOW 2.5
tom_minnich 4:adea7bcbd995 34 float total_rep;
tom_minnich 4:adea7bcbd995 35 float below_g_rep;
tom_minnich 4:adea7bcbd995 36 float above_g_rep;
tom_minnich 4:adea7bcbd995 37 unsigned int time_reg=0;
tom_minnich 4:adea7bcbd995 38 unsigned int stop_time_reg = 0; // for calc delta time
tom_minnich 4:adea7bcbd995 39 unsigned int delta_time_reg;
tom_minnich 4:adea7bcbd995 40 unsigned int time_below_g_inst = 0;
tom_minnich 4:adea7bcbd995 41 unsigned int time_above_g_inst = 0;
tom_minnich 4:adea7bcbd995 42 unsigned int time_below_g=0; //UP green led below 1 G
tom_minnich 4:adea7bcbd995 43 unsigned int time_above_g=0; // DOWN red led above 1 G
tom_minnich 4:adea7bcbd995 44 unsigned int time_below_g_cycles=0;
tom_minnich 4:adea7bcbd995 45 unsigned int time_above_g_cycles=0;
tom_minnich 4:adea7bcbd995 46 //total_rep moving average
tom_minnich 4:adea7bcbd995 47 #define REP_AVG_ARRAY_SZ 10
tom_minnich 4:adea7bcbd995 48 //TWM added stuff
tom_minnich 4:adea7bcbd995 49 float rep_avg_array[REP_AVG_ARRAY_SZ];
tom_minnich 4:adea7bcbd995 50 int rep_read_from = 0;
tom_minnich 4:adea7bcbd995 51 int rep_read;
tom_minnich 4:adea7bcbd995 52 int rep_write_to = 0;
tom_minnich 4:adea7bcbd995 53 int rep_items_stored_in_array = 0;
tom_minnich 4:adea7bcbd995 54 float rep_avg;
tom_minnich 4:adea7bcbd995 55 static const float greenx=sqrt(3.0f)/2.0f;
tom_minnich 4:adea7bcbd995 56 static const float bluex=-sqrt(3.0f)/2.0f;
tom_minnich 4:adea7bcbd995 57
tom_minnich 4:adea7bcbd995 58 void paint_leds(void){
tom_minnich 4:adea7bcbd995 59 float led_temp;
tom_minnich 4:adea7bcbd995 60 float OLED_temp;
tom_minnich 4:adea7bcbd995 61 // 1 LED off 0 LED ON
tom_minnich 4:adea7bcbd995 62 led_temp = (TARGET_REP - rep_avg)*(float)0.5 + (float)0.5;
tom_minnich 4:adea7bcbd995 63 if (led_temp > (float)1.0) {
tom_minnich 4:adea7bcbd995 64 led_temp = 1.0;
tom_minnich 4:adea7bcbd995 65 }else if(led_temp<0){
tom_minnich 4:adea7bcbd995 66 led_temp = 0;
tom_minnich 4:adea7bcbd995 67 }
tom_minnich 4:adea7bcbd995 68 gled = led_temp;
tom_minnich 4:adea7bcbd995 69 led_temp = (float)1.0 - led_temp;
tom_minnich 4:adea7bcbd995 70 rled = led_temp;
tom_minnich 4:adea7bcbd995 71 OLED_temp = led_temp*(float)9.0;
tom_minnich 4:adea7bcbd995 72 update_image = (int) OLED_temp;
tom_minnich 4:adea7bcbd995 73 if (update_image > 8) {
tom_minnich 4:adea7bcbd995 74 update_image = 8;
tom_minnich 4:adea7bcbd995 75 }else if(update_image<0){
tom_minnich 4:adea7bcbd995 76 update_image = 0;
tom_minnich 4:adea7bcbd995 77 }
tom_minnich 4:adea7bcbd995 78 }
tom_minnich 4:adea7bcbd995 79 void average_total_reps(void){
tom_minnich 4:adea7bcbd995 80 int i;
tom_minnich 4:adea7bcbd995 81 rep_avg_array[rep_write_to++] = ((float)(time_above_g_inst+time_below_g_inst))/(float)1000.0;
tom_minnich 4:adea7bcbd995 82 if(rep_write_to >= REP_AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 83 rep_write_to = 0;
tom_minnich 4:adea7bcbd995 84 }
tom_minnich 4:adea7bcbd995 85 if(rep_items_stored_in_array < REP_AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 86 rep_items_stored_in_array++;
tom_minnich 4:adea7bcbd995 87 }else{
tom_minnich 4:adea7bcbd995 88 rep_read_from++;
tom_minnich 4:adea7bcbd995 89 if(rep_read_from >= REP_AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 90 rep_read_from = 0;
tom_minnich 4:adea7bcbd995 91 }
tom_minnich 4:adea7bcbd995 92 }
tom_minnich 4:adea7bcbd995 93
tom_minnich 4:adea7bcbd995 94 rep_avg = 0;
tom_minnich 4:adea7bcbd995 95 rep_read = rep_read_from;
tom_minnich 4:adea7bcbd995 96
tom_minnich 4:adea7bcbd995 97 for(i=0; i<rep_items_stored_in_array; i++){
tom_minnich 4:adea7bcbd995 98 rep_avg += rep_avg_array[rep_read++];
tom_minnich 4:adea7bcbd995 99 if(rep_read >= REP_AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 100 rep_read = 0;
tom_minnich 4:adea7bcbd995 101 }
tom_minnich 4:adea7bcbd995 102 }
tom_minnich 4:adea7bcbd995 103 rep_avg = rep_avg/rep_items_stored_in_array;
tom_minnich 4:adea7bcbd995 104 }
tom_minnich 4:adea7bcbd995 105
tom_minnich 4:adea7bcbd995 106 //DigitalOut led1(LED_GREEN);
GregC 2:f9c24c129575 107
GregC 2:f9c24c129575 108 // Initialize Serial port
GregC 2:f9c24c129575 109 Serial pc(USBTX, USBRX);
maclobdell 0:207337d58f96 110
maclobdell 0:207337d58f96 111 // Pin connections & address for Hexiwear
GregC 2:f9c24c129575 112 FXOS8700 accel(PTC11, PTC10);
GregC 2:f9c24c129575 113 FXOS8700 mag(PTC11, PTC10);
maclobdell 0:207337d58f96 114
maclobdell 0:207337d58f96 115 // main() runs in its own thread in the OS
maclobdell 0:207337d58f96 116 // (note the calls to Thread::wait below for delays)
maclobdell 0:207337d58f96 117 int main() {
tom_minnich 4:adea7bcbd995 118 /* Pointer for the images to be displayed */
tom_minnich 4:adea7bcbd995 119 const uint8_t *image[9];
tom_minnich 4:adea7bcbd995 120
tom_minnich 4:adea7bcbd995 121 /* Setting pointer location of the 96 by 96 pixel bitmap */
tom_minnich 4:adea7bcbd995 122 image[0] = red0_bmp;
tom_minnich 4:adea7bcbd995 123 image[1] = orn9_bmp;
tom_minnich 4:adea7bcbd995 124 image[2] = ltorn18_bmp;
tom_minnich 4:adea7bcbd995 125 image[3] = egg26_bmp;
tom_minnich 4:adea7bcbd995 126 image[4] = yel36_bmp;
tom_minnich 4:adea7bcbd995 127 image[5] = ltyel44_bmp;
tom_minnich 4:adea7bcbd995 128 image[6] = ltgrn53_bmp;
tom_minnich 4:adea7bcbd995 129 image[7] = lime71_bmp;
tom_minnich 4:adea7bcbd995 130 image[8] = grn80_bmp;
tom_minnich 4:adea7bcbd995 131
tom_minnich 4:adea7bcbd995 132
tom_minnich 4:adea7bcbd995 133 /* Instantiate the SSD1351 OLED Driver */
tom_minnich 4:adea7bcbd995 134 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
tom_minnich 4:adea7bcbd995 135
tom_minnich 4:adea7bcbd995 136 /* Turn on the backlight of the OLED Display */
tom_minnich 4:adea7bcbd995 137 oled.DimScreenON();
tom_minnich 4:adea7bcbd995 138 oled.DrawImage(image[last_image],0,0); //last_image = 4 at start
tom_minnich 4:adea7bcbd995 139
tom_minnich 4:adea7bcbd995 140 //TWM REP Hexiwear Stuff
tom_minnich 4:adea7bcbd995 141 // 1ms pwm frequency
tom_minnich 4:adea7bcbd995 142 rled.period(0.001f);
tom_minnich 4:adea7bcbd995 143 gled.period(0.001f);
tom_minnich 4:adea7bcbd995 144 bled.period(0.001f);
tom_minnich 4:adea7bcbd995 145 acc_timer.start();
maclobdell 0:207337d58f96 146
GregC 2:f9c24c129575 147 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700
GregC 2:f9c24c129575 148 accel.accel_config();
GregC 2:f9c24c129575 149 mag.mag_config();
GregC 2:f9c24c129575 150
tom_minnich 4:adea7bcbd995 151 float accel_data[3];
tom_minnich 4:adea7bcbd995 152 #ifdef USE_MAG_DATA
GregC 2:f9c24c129575 153 float mag_data[3]; float mag_rms=0.0;
tom_minnich 4:adea7bcbd995 154 #endif
GregC 2:f9c24c129575 155
GregC 3:9f60cb7455c4 156 printf("Begin Data Acquisition from FXOS8700CQ sensor....\r\n\r\n");
GregC 2:f9c24c129575 157 wait(0.5);
GregC 2:f9c24c129575 158
GregC 2:f9c24c129575 159 while (1) {
tom_minnich 4:adea7bcbd995 160 int i;
tom_minnich 4:adea7bcbd995 161 float xaccln,yaccln,zaccln;
tom_minnich 4:adea7bcbd995 162
tom_minnich 4:adea7bcbd995 163 accel.acquire_accel_data_g(accel_data);
tom_minnich 4:adea7bcbd995 164 xaccln = accel_data[0]; // using the same named variables from the old REP software
tom_minnich 4:adea7bcbd995 165 yaccln = accel_data[1];
tom_minnich 4:adea7bcbd995 166 zaccln = accel_data[2];
tom_minnich 4:adea7bcbd995 167 time_reg = acc_timer.read_us();
tom_minnich 4:adea7bcbd995 168 float norm=sqrt(xaccln*xaccln + yaccln*yaccln +zaccln*zaccln);
tom_minnich 4:adea7bcbd995 169 avg_array[write_to++] = norm;
tom_minnich 4:adea7bcbd995 170 if(write_to>= AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 171 write_to = 0;
tom_minnich 4:adea7bcbd995 172 }
tom_minnich 4:adea7bcbd995 173 if(items_stored_in_array < AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 174 items_stored_in_array++;
tom_minnich 4:adea7bcbd995 175 }else{
tom_minnich 4:adea7bcbd995 176 read_from++;
tom_minnich 4:adea7bcbd995 177 if(read_from >= AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 178 read_from = 0;
tom_minnich 4:adea7bcbd995 179 }
tom_minnich 4:adea7bcbd995 180 }
tom_minnich 4:adea7bcbd995 181
tom_minnich 4:adea7bcbd995 182 avg = 0;
tom_minnich 4:adea7bcbd995 183 read = read_from;
tom_minnich 4:adea7bcbd995 184
tom_minnich 4:adea7bcbd995 185 for(i=0; i<items_stored_in_array; i++){
tom_minnich 4:adea7bcbd995 186 avg += avg_array[read++];
tom_minnich 4:adea7bcbd995 187 if(read >= AVG_ARRAY_SZ){
tom_minnich 4:adea7bcbd995 188 read = 0;
tom_minnich 4:adea7bcbd995 189 }
tom_minnich 4:adea7bcbd995 190 }
tom_minnich 4:adea7bcbd995 191
tom_minnich 4:adea7bcbd995 192 avg = avg/items_stored_in_array;
tom_minnich 4:adea7bcbd995 193
tom_minnich 4:adea7bcbd995 194 bled = 1;
tom_minnich 4:adea7bcbd995 195 if (fabs(avg-norm) > ACC_DEADBAND){
tom_minnich 4:adea7bcbd995 196 if((avg-norm)>0){
tom_minnich 4:adea7bcbd995 197 // avg-norm a positive number
tom_minnich 4:adea7bcbd995 198 // going downward from the top of a rep
tom_minnich 4:adea7bcbd995 199 if(!going_down)
tom_minnich 4:adea7bcbd995 200 { //if there is a change in direction calc rep duration
tom_minnich 4:adea7bcbd995 201 delta_time_reg = time_reg - stop_time_reg;
tom_minnich 4:adea7bcbd995 202 stop_time_reg = time_reg; // store away the next stop time
tom_minnich 4:adea7bcbd995 203 if(delta_time_reg >MAX_REP_DURATION){
tom_minnich 4:adea7bcbd995 204 total_rep = 0.0;
tom_minnich 4:adea7bcbd995 205 below_g_rep = 0.0;
tom_minnich 4:adea7bcbd995 206 above_g_rep = 0.0;
tom_minnich 4:adea7bcbd995 207 delta_time_reg = 0;
tom_minnich 4:adea7bcbd995 208 time_below_g_inst = 0;
tom_minnich 4:adea7bcbd995 209 time_above_g_inst = 0;
tom_minnich 4:adea7bcbd995 210 time_below_g=0; //UP green led below 1 G
tom_minnich 4:adea7bcbd995 211 time_above_g=0; // DOWN red led above 1 G
tom_minnich 4:adea7bcbd995 212 time_below_g_cycles=0;
tom_minnich 4:adea7bcbd995 213 time_above_g_cycles=0;
tom_minnich 4:adea7bcbd995 214 }else{
tom_minnich 4:adea7bcbd995 215 time_above_g_inst = delta_time_reg/1000;
tom_minnich 4:adea7bcbd995 216 time_above_g += time_above_g_inst;
tom_minnich 4:adea7bcbd995 217 time_above_g_cycles++;
tom_minnich 4:adea7bcbd995 218 above_g_rep = (float)(time_above_g/time_above_g_cycles);//track in seconds
tom_minnich 4:adea7bcbd995 219 above_g_rep /= 1000;
tom_minnich 4:adea7bcbd995 220 total_rep = above_g_rep + below_g_rep;
tom_minnich 4:adea7bcbd995 221 average_total_reps();
tom_minnich 4:adea7bcbd995 222 paint_leds();
tom_minnich 4:adea7bcbd995 223 if(last_image != update_image){
tom_minnich 4:adea7bcbd995 224 last_image = update_image;
tom_minnich 4:adea7bcbd995 225 oled.DrawImage(image[last_image],0,0);
tom_minnich 4:adea7bcbd995 226 }
tom_minnich 4:adea7bcbd995 227
tom_minnich 4:adea7bcbd995 228 // bt.printf("U");
tom_minnich 4:adea7bcbd995 229 //if(bt.writeable()){
tom_minnich 4:adea7bcbd995 230 //printf("Bluetooth writeable! \r\n");
tom_minnich 4:adea7bcbd995 231 //bt.putc('U');
tom_minnich 4:adea7bcbd995 232 //printf("Back from bluetooth comm! \r\n");
tom_minnich 4:adea7bcbd995 233 //}
tom_minnich 4:adea7bcbd995 234 // bt.printf("\x1B[JREP #%d\r\n",time_above_g_cycles);
tom_minnich 4:adea7bcbd995 235 printf("\x1B[KREP #%d\r\n",time_above_g_cycles);
tom_minnich 4:adea7bcbd995 236 // bt.printf("Raising rep: %d\r\n",delta_time_reg/1000);
tom_minnich 4:adea7bcbd995 237 // bt.printf("AVG Raising rep: %1.2f \r\n",above_g_rep);
tom_minnich 4:adea7bcbd995 238 printf("\x1B[KAccumulated Average Raising Rep: %1.2f \r\n",above_g_rep);
tom_minnich 4:adea7bcbd995 239 // bt.printf("rep_avg: %1.2f \r\n",rep_avg);
tom_minnich 4:adea7bcbd995 240 }
tom_minnich 4:adea7bcbd995 241 going_down = 1;
tom_minnich 4:adea7bcbd995 242 going_up = 0;
tom_minnich 4:adea7bcbd995 243 //rled = 0;
tom_minnich 4:adea7bcbd995 244 //gled = 1;
tom_minnich 4:adea7bcbd995 245 }
tom_minnich 4:adea7bcbd995 246 }else{
tom_minnich 4:adea7bcbd995 247 //avg-norm a negative number
tom_minnich 4:adea7bcbd995 248 //accelerating upward from the bottom of a rep
tom_minnich 4:adea7bcbd995 249 if(!going_up)
tom_minnich 4:adea7bcbd995 250 { //if there is a change in direction calc rep duration
tom_minnich 4:adea7bcbd995 251 delta_time_reg = time_reg - stop_time_reg;
tom_minnich 4:adea7bcbd995 252 stop_time_reg = time_reg; // store away the next stop time
tom_minnich 4:adea7bcbd995 253 if(delta_time_reg >MAX_REP_DURATION){
tom_minnich 4:adea7bcbd995 254 total_rep = 0.0;
tom_minnich 4:adea7bcbd995 255 below_g_rep = 0.0;
tom_minnich 4:adea7bcbd995 256 above_g_rep = 0.0;
tom_minnich 4:adea7bcbd995 257 delta_time_reg = 0;
tom_minnich 4:adea7bcbd995 258 time_below_g_inst = 0;
tom_minnich 4:adea7bcbd995 259 time_above_g_inst = 0;
tom_minnich 4:adea7bcbd995 260 time_below_g=0; //UP green led below 1 G
tom_minnich 4:adea7bcbd995 261 time_above_g=0; // DOWN red led above 1 G
tom_minnich 4:adea7bcbd995 262 time_below_g_cycles=0;
tom_minnich 4:adea7bcbd995 263 time_above_g_cycles=0;
tom_minnich 4:adea7bcbd995 264 }else{
tom_minnich 4:adea7bcbd995 265 time_below_g_inst = delta_time_reg/1000;
tom_minnich 4:adea7bcbd995 266 time_below_g += time_below_g_inst; // track in mS
tom_minnich 4:adea7bcbd995 267 time_below_g_cycles++;
tom_minnich 4:adea7bcbd995 268 below_g_rep = (float)(time_below_g/time_below_g_cycles); //track in seconds
tom_minnich 4:adea7bcbd995 269 below_g_rep /= 1000;
tom_minnich 4:adea7bcbd995 270 total_rep = above_g_rep + below_g_rep;
tom_minnich 4:adea7bcbd995 271 average_total_reps();
tom_minnich 4:adea7bcbd995 272 paint_leds();
tom_minnich 4:adea7bcbd995 273 if(last_image != update_image){
tom_minnich 4:adea7bcbd995 274 last_image = update_image;
tom_minnich 4:adea7bcbd995 275 oled.DrawImage(image[last_image],0,0);
tom_minnich 4:adea7bcbd995 276 }
tom_minnich 4:adea7bcbd995 277
tom_minnich 4:adea7bcbd995 278 // bt.printf("Lowering rep: %d\r\n",delta_time_reg/1000);
tom_minnich 4:adea7bcbd995 279 // bt.printf("AVG Lowering rep: %1.2f\x1B[H",below_g_rep);
tom_minnich 4:adea7bcbd995 280
tom_minnich 4:adea7bcbd995 281 printf("\x1B[KAccumulated Average Lowering Rep: %1.2f\r\n",below_g_rep);
tom_minnich 4:adea7bcbd995 282 printf("\x1B[KRecent Activity Rep Average: %1.2f Target is 2.00\x1B[J\x1B[H",rep_avg);
tom_minnich 4:adea7bcbd995 283 }
tom_minnich 4:adea7bcbd995 284 going_down = 0;
tom_minnich 4:adea7bcbd995 285 going_up = 1;
tom_minnich 4:adea7bcbd995 286 //rled = 1;
tom_minnich 4:adea7bcbd995 287 //gled = 0;
tom_minnich 4:adea7bcbd995 288 }
tom_minnich 4:adea7bcbd995 289 }// endif direction up or down
tom_minnich 4:adea7bcbd995 290 }// endif deadband
tom_minnich 4:adea7bcbd995 291
tom_minnich 4:adea7bcbd995 292 // printf("X: %1.4f, Y: %1.4f, Z: %1.4f,avg-norm %1.4f Norm: %1.4f \r\n",
tom_minnich 4:adea7bcbd995 293 // xaccln, yaccln, zaccln,(avg-norm),
tom_minnich 4:adea7bcbd995 294 // norm);
tom_minnich 4:adea7bcbd995 295 // printf("%d\r\n",time_reg);
tom_minnich 4:adea7bcbd995 296 // TWM using thread wait below instead of this wait function!!!
tom_minnich 4:adea7bcbd995 297 // wait(0.1f);
tom_minnich 4:adea7bcbd995 298
tom_minnich 4:adea7bcbd995 299
tom_minnich 4:adea7bcbd995 300
tom_minnich 4:adea7bcbd995 301 // led1 = !led1;
tom_minnich 4:adea7bcbd995 302 // Example data printing
tom_minnich 4:adea7bcbd995 303 // accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
tom_minnich 4:adea7bcbd995 304 // printf("Accelerometer \tX-Axis %4.2f \tY-Axis %4.2f \tZ-Axis %4.2f \tRMS %4.2f\n\r",accel_data[0],accel_data[1],accel_data[2],accel_rms);
tom_minnich 4:adea7bcbd995 305 // wait(0.01);
tom_minnich 4:adea7bcbd995 306 #ifdef USE_MAG_DATA
GregC 2:f9c24c129575 307 mag.acquire_mag_data_uT(mag_data);
GregC 2:f9c24c129575 308 mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
GregC 2:f9c24c129575 309 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);
GregC 2:f9c24c129575 310 wait(0.01);
tom_minnich 4:adea7bcbd995 311 #endif
tom_minnich 4:adea7bcbd995 312 Thread::wait(100);
tom_minnich 4:adea7bcbd995 313 // Thread::wait(500);
maclobdell 0:207337d58f96 314 }
maclobdell 0:207337d58f96 315 }