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.
Revision 0:efdae9d24ee1, committed 2015-07-22
- Comitter:
- ADAMSTRUTT
- Date:
- Wed Jul 22 13:12:14 2015 +0000
- Child:
- 1:b8f9693ae04f
- Child:
- 2:4dd54b3934a5
- Commit message:
- Start of new PTC_speed
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Calculate.cpp Wed Jul 22 13:12:14 2015 +0000
@@ -0,0 +1,74 @@
+//#include "mbed.h"
+//#include <time.h>
+//#include <string>
+//#include <iostream>
+//#include "Distance.h"
+//
+//void printArray(double array[20], int timesArray[20], int NoOfPins);
+//void data(int sensor_number, int time, double speed);
+//
+// //mbed pins
+//extern Serial pc;
+//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
+//float speed;
+//int times[20]; //array the size of #pins
+//double speeds[20]; //array of speeds
+//
+//
+////Speed Calculations
+//int calculate(double distance, int noOfPins)
+//{
+//
+// pc.printf("new program \n"); //alert user of initialisation
+//
+// int i = 0, i1 = 0;
+//
+// while( i < noOfPins)
+// {
+// while(!sensor[i])
+// {
+// if(sensor[i + 1]) { //checks if there is an error in the first sensor
+// sensor_time = time(NULL);
+// pc.printf ("Error with sensor: %d", i);
+// i++;
+// }
+// if(sensor[i + 2]) { //checks if there is an error in the second sensor after
+// sensor_time = time(NULL);
+// pc.printf ("Error with sensors: %d, %d", i,i1 = i + 1);
+// i = i + 2;
+// }
+// }
+// sensor_time = time(NULL); //gets current time
+// pc.printf("\n sensor %d : %d \t", i, sensor_time);
+// times[i] = sensor_time; //adds sensor times to array for logging.
+// if ( i > 0) { //to ensure it is not the first one
+// timeDiff = difftime(times[i], times[i-1]); //calculates the time difference
+// pc.printf(" timediff: %d s \t", timeDiff);
+// speed = distance / timeDiff;
+// pc.printf(" speed : %f m/s ", speed);
+// speeds[i] = speed;
+// }
+// i++;
+// }
+// pc.printf(" \n Calculate completed \n"); //alert to let user know it completed
+// printArray(speeds, times, noOfPins);
+//
+//}
+//
+//void printArray(double array[23], int timesArray[23], int noOfPins)
+// {
+// 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 < noOfPins ; i++) //printing to Datalog
+// {
+// data( i,times[i],speeds[i]);
+// }
+//
+// }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Calculate.h Wed Jul 22 13:12:14 2015 +0000 @@ -0,0 +1,7 @@ +//#ifndef CALCULATE_H +//#define CALCULATE_H +// +//int calculate(double distance, int noOfPins); +//void printArray(double array[3], int timesArray[3],int noOfPins); +// +////#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/UserInput.cpp Wed Jul 22 13:12:14 2015 +0000
@@ -0,0 +1,83 @@
+#include "mbed.h"
+#include "stdio.h"
+#include <string>
+
+extern Serial pc;
+extern Serial mbed2;
+
+LocalFileSystem local("local");
+
+char company [100], pipe [100];
+//noOfSensor: is the number of sensors of the former
+//distance: is the distance between the sensors in 'mm'
+//S: straiting
+//B: bending
+int noOfSensorS, distanceS, noOfSensorB;
+
+
+void inputNoOfPins(){
+ FILE *pFile = fopen ("/local/details.txt" , "r");
+ if (pFile == NULL){
+ pc.printf("Error opening file");
+ }else {
+ if ( fgets (company, 100 , pFile) != NULL ){
+ pc.printf ("%s\n", company);
+ }
+ if ( fgets (pipe, 100 , pFile) != NULL ){
+ pc.printf ("%s\n", pipe);
+ fclose (pFile);
+ }
+ }
+}
+
+int UI_NumberOfSensorsB(){
+
+ FILE *p1File = fopen ("/local/details.txt" , "r");
+ if (p1File == NULL){
+ pc.printf("Error opening file");
+ }else {
+ pc.printf ("%d\n", noOfSensorB = fgetc (p1File));
+ fclose (p1File);
+ }
+}
+
+int UI_DistanceB(){
+
+ int distanceB;
+
+ pc.printf("UI_DistanceB");
+ FILE *p2File = fopen ("/local/details.txt" , "r");
+ if (p2File == NULL){
+ pc.printf("Error opening file");
+ }else {
+ for(int i = 0; i < 3; i++){
+ pc.printf("inside");
+ distanceB = atoi (fgets (p2File).c_str());
+ }
+ distanceB = atoi (fgets (p2File));
+ pc.printf ("%i\n", distanceB);
+ fclose (p2File);
+ }
+}
+
+int UI_NumberOfSensorsS(){
+
+ FILE *p3File = fopen ("/local/details.txt" , "r");
+ if (p3File == NULL){
+ pc.printf("Error opening file");
+ }else {
+ pc.printf ("%d\n", noOfSensorB = fgetc (p3File));
+ fclose (p3File);
+ }
+}
+
+int UI_DistanceS(){
+
+ FILE *p4File = fopen ("/local/details.txt" , "r");
+ if (p4File == NULL){
+ pc.printf("Error opening file");
+ }else {
+ pc.printf ("%d\n", distanceS= fgetc (p4File));
+ fclose (p4File);
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UserInput.h Wed Jul 22 13:12:14 2015 +0000 @@ -0,0 +1,11 @@ +#ifndef USERINPUT.H +#define USERINPUT.H + + +void inputNoOfPins(); +int UI_NumberOfSensorsB(); +int UI_DistanceB(); +int UI_NumberOfSensorsS(); +int UI_DistanceS(); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Jul 22 13:12:14 2015 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+//#include "Calculate.h"
+//#include "Distance.h"
+//#include "Data.h"
+#include "UserInput.h"
+//#include "Counter.h
+
+Serial pc(USBTX, USBRX); // tx, rx
+Serial mbed2(p9,p10); //tx, rx
+
+int main(){
+ UI_DistanceB();
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 22 13:12:14 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92 \ No newline at end of file