![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
02/07/15
Dependencies: mbed
Diff: Calculate.cpp
- Revision:
- 52:d21fc7266b66
- Parent:
- 51:210353276e06
- Child:
- 53:10f4f519ba69
--- a/Calculate.cpp Wed Jul 15 15:39:10 2015 +0000 +++ b/Calculate.cpp Thu Jul 16 14:01:24 2015 +0000 @@ -4,27 +4,30 @@ #include <iostream> #include "Distance.h" -void printArray(double array[3], int timesArray[3]); +void printArray(double array[20], int timesArray[20]); void data(int sensor_number, int time, double speed); //mbed pins extern Serial pc; //defines the communication between MBed and pc int NoOfPins = 3; //for how many sensors there are -DigitalIn sensor[3] = {p5,p6,p7} ; //array of sensors. +DigitalIn sensor[20] = {p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23,p24} ; //array of sensors. //c++ variables time_t sensor_time ; //time at which sensor is broken int timeDiff; //time between 2 sensors - not used right now float speed; - int times[3]; //array the size of #pins - double speeds[3]; //array of speeds + int times[20]; //array the size of #pins + double speeds[20]; //array of speeds + + + int calculate(double distance) { pc.printf("new program \n"); //alert user of initialisation int i = 0; - while( i < 3) + while( i < NoOfPins) { while(!sensor[i]) { @@ -46,19 +49,18 @@ i++; } pc.printf(" \n Calculate completed \n"); //alert to let user know it completed - // printArray(times); printArray(speeds, times); } -void printArray(double array[3], int timesArray[3]) +void printArray(double array[20], int timesArray[20]) { - for (int i = 0; i < 3 ; i++) //printing module for array + for (int i = 0; i < NoOfPins ; i++) //printing module for array { pc.printf(" Sensor : %d Time %d Speed %f \n", i,times[i],speeds[i]); // pc.printf(" %d : %d \t", i,times[i]); } - for (int i = 0; i < 3 ; i++) //printing to Datalog + for (int i = 0; i < NoOfPins ; i++) //printing to Datalog { data( i,times[i],speeds[i]); }