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.
SpeedCalculate.cpp
00001 #include "SpeedCalculate.h" 00002 #include "mbed.h" 00003 #include "Data.h" 00004 #include <time.h> 00005 #include <string> 00006 00007 00008 extern Serial pc; 00009 00010 //c++ variables 00011 Timer t; //time at which sensor is broken 00012 float timeDiff; //time between 2 sensors 00013 float speed; //array of speeds 00014 00015 00016 //Speed Calculations 00017 //it takes the distance and number of sensor and gives the speed (m/s) 00018 void SpeedCalculate::calculate(float distance, int noOfSensors) 00019 { 00020 Data data; 00021 00022 int count = 0; 00023 00024 //array of sensors 00025 DigitalIn sensor[18] = {p5, p6, p7, p8, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24}; 00026 00027 while(true){ 00028 int i=0; 00029 t.start(); 00030 data.counter(count); 00031 while( i < noOfSensors) //loops round until all the sensors have been used 00032 { 00033 if (i == 0){ 00034 data.logSpeed(0,0,0); 00035 } 00036 while(!sensor[i]) 00037 { 00038 if(sensor[i + 1]) { //checks if there is an error in the first sensor 00039 i++; 00040 } 00041 if(sensor[i + 2]) { //checks if there is an error in the second sensor after 00042 i = i + 2; 00043 } 00044 } 00045 timeDiff = t.read(); //gets current time 00046 t.reset(); 00047 pc.printf("%f\n%f\n", i, timeDiff); 00048 if ( i > 0) { //to ensure it is not the first one 00049 speed = 60*(distance / timeDiff); 00050 pc.printf("%f\n", speed); 00051 data.logSpeed(&i, &timeDiff, &speed); //logs data 00052 } 00053 i++; 00054 } 00055 t.stop(); 00056 count++; 00057 } 00058 }
Generated on Sat Jul 23 2022 19:08:16 by
1.7.2