Module 2 ECEN 5803 Project 1 Submitted by 1. Rahul Yamasani 2. Srivishnuj Alvakonda

Dependencies:   MMA8451Q TSI mbed

Fork of FRDM_MMA8451Q by mbed official

Committer:
sral4054
Date:
Thu Oct 12 03:24:10 2017 +0000
Revision:
8:3246b1db17ce
Parent:
5:bf5becf7469c
Module 2 ECEN 5803 Project 1; ; Submitted by; 1. Rahul Yamasani; 2. Srivishnuj Alvakonda;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 2:41db78380a6e 1 #include "mbed.h"
chris 2:41db78380a6e 2 #include "MMA8451Q.h"
sral4054 8:3246b1db17ce 3 #include "TSISensor.h"
sral4054 8:3246b1db17ce 4
sral4054 8:3246b1db17ce 5 Timer timer;
sral4054 8:3246b1db17ce 6 Timer timer2;
sral4054 8:3246b1db17ce 7 Serial pc(USBTX, USBRX);
chris 2:41db78380a6e 8
chris 2:41db78380a6e 9 #define MMA8451_I2C_ADDRESS (0x1d<<1)
sral4054 8:3246b1db17ce 10
sral4054 8:3246b1db17ce 11 int main(void)
sral4054 8:3246b1db17ce 12 {
emilmont 5:bf5becf7469c 13 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
emilmont 5:bf5becf7469c 14 PwmOut rled(LED_RED);
emilmont 5:bf5becf7469c 15 PwmOut gled(LED_GREEN);
emilmont 5:bf5becf7469c 16 PwmOut bled(LED_BLUE);
sral4054 8:3246b1db17ce 17 TSISensor tsi;
sral4054 8:3246b1db17ce 18 timer.start();
sral4054 8:3246b1db17ce 19 timer2.start();
sral4054 8:3246b1db17ce 20 double timer_read = 0.0;
sral4054 8:3246b1db17ce 21 double timer_read2 = 0.0;
sral4054 8:3246b1db17ce 22
sral4054 8:3246b1db17ce 23 int i = 0;
sral4054 8:3246b1db17ce 24 while (true)
sral4054 8:3246b1db17ce 25 {
sral4054 8:3246b1db17ce 26 timer.reset();
chris 3:f2d3e041d8f2 27 rled = 1.0 - abs(acc.getAccX());
chris 3:f2d3e041d8f2 28 gled = 1.0 - abs(acc.getAccY());
chris 3:f2d3e041d8f2 29 bled = 1.0 - abs(acc.getAccZ());
sral4054 8:3246b1db17ce 30 gled = 1.0 - tsi.readPercentage();
sral4054 8:3246b1db17ce 31 timer_read += timer.read();
chris 3:f2d3e041d8f2 32 wait(0.1);
sral4054 8:3246b1db17ce 33
sral4054 8:3246b1db17ce 34 i++;
sral4054 8:3246b1db17ce 35
sral4054 8:3246b1db17ce 36 if (i==100)
sral4054 8:3246b1db17ce 37 {
sral4054 8:3246b1db17ce 38 timer_read2 = timer2.read();
sral4054 8:3246b1db17ce 39 pc.printf("\n\rCPU Load Execution time: %f\n\r", timer_read);
sral4054 8:3246b1db17ce 40 pc.printf("Total Program Execution time: %f\n\r\n\r", timer_read2);
sral4054 8:3246b1db17ce 41
sral4054 8:3246b1db17ce 42 double processor_load = double(timer_read/timer_read2);
sral4054 8:3246b1db17ce 43 processor_load *= 100;
sral4054 8:3246b1db17ce 44 pc.printf("RESULT\n\r");
sral4054 8:3246b1db17ce 45 pc.printf("Processor load in percentage of CPU cycles %f\n\r", processor_load);
sral4054 8:3246b1db17ce 46 pc.printf("CPU available percentage is %f\n\r", 100.0 - processor_load);
sral4054 8:3246b1db17ce 47 }
sral4054 8:3246b1db17ce 48 }
sral4054 8:3246b1db17ce 49
chris 2:41db78380a6e 50 }