02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Committer:
aidanPJG
Date:
Thu Jul 16 14:22:47 2015 +0000
Revision:
54:9322b1b76e13
Parent:
50:d794595c6868
Child:
56:bf08d9e50ccc
Got UserInput class working. It now uses 2 separate methods. It is compatible with calculate method as well.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aidanPJG 48:e9578f56534a 1 #include "mbed.h"
aidanPJG 54:9322b1b76e13 2 #include <utility>
aidanPJG 48:e9578f56534a 3
aidanPJG 48:e9578f56534a 4 extern Serial pc;
aidanPJG 48:e9578f56534a 5 int sensorNumber;
aidanPJG 49:889751dd0395 6 double sensorDistance;
aidanPJG 48:e9578f56534a 7
aidanPJG 54:9322b1b76e13 8 int inputNoOfPins(){
aidanPJG 48:e9578f56534a 9 pc.printf("Ready to Read.\n");
aidanPJG 48:e9578f56534a 10 pc.printf("Enter the number of sensors\n");
aidanPJG 48:e9578f56534a 11 while (1){
aidanPJG 48:e9578f56534a 12 if (pc.readable())
aidanPJG 48:e9578f56534a 13 {
aidanPJG 48:e9578f56534a 14 pc.scanf("%d", &sensorNumber);
aidanPJG 54:9322b1b76e13 15 break;
aidanPJG 54:9322b1b76e13 16 }
aidanPJG 54:9322b1b76e13 17 }
aidanPJG 54:9322b1b76e13 18 pc.printf("sensorNumber : %d \t " ,sensorNumber );
aidanPJG 54:9322b1b76e13 19 return(sensorNumber);
aidanPJG 54:9322b1b76e13 20 }
aidanPJG 54:9322b1b76e13 21
aidanPJG 54:9322b1b76e13 22 double inputDistance(){
aidanPJG 54:9322b1b76e13 23 pc.printf("Enter the distance between each sensor\n ");
aidanPJG 54:9322b1b76e13 24 while (1){
aidanPJG 54:9322b1b76e13 25 if (pc.readable())
aidanPJG 54:9322b1b76e13 26 {
aidanPJG 49:889751dd0395 27 pc.scanf("%lf", &sensorDistance); //has to &lf because must know the size of it before getting it in
aidanPJG 48:e9578f56534a 28 break;
aidanPJG 48:e9578f56534a 29 }
aidanPJG 48:e9578f56534a 30 }
aidanPJG 54:9322b1b76e13 31 pc.printf( "SensorDistance : %f", sensorDistance );
aidanPJG 54:9322b1b76e13 32 return(sensorDistance);
aidanPJG 54:9322b1b76e13 33 }