02/07/15

Dependencies:   mbed

Dependents:   TabbedGUIMbed

Committer:
aidanPJG
Date:
Wed Jul 15 13:52:20 2015 +0000
Revision:
49:889751dd0395
Parent:
48:e9578f56534a
Child:
50:d794595c6868
user input works for integer number of sensors and decimal distance

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aidanPJG 48:e9578f56534a 1 #include "mbed.h"
aidanPJG 48:e9578f56534a 2
aidanPJG 48:e9578f56534a 3 extern Serial pc;
aidanPJG 48:e9578f56534a 4 int sensorNumber;
aidanPJG 49:889751dd0395 5 double sensorDistance;
aidanPJG 48:e9578f56534a 6
aidanPJG 48:e9578f56534a 7 float input(){
aidanPJG 48:e9578f56534a 8 pc.printf("Ready to Read.\n");
aidanPJG 48:e9578f56534a 9 pc.printf("Enter the number of sensors\n");
aidanPJG 48:e9578f56534a 10 while (1){
aidanPJG 48:e9578f56534a 11 if (pc.readable())
aidanPJG 48:e9578f56534a 12 {
aidanPJG 48:e9578f56534a 13 pc.scanf("%d", &sensorNumber);
aidanPJG 48:e9578f56534a 14 pc.printf("Enter the distance between each sensor\n ");
aidanPJG 49:889751dd0395 15 pc.scanf("%lf", &sensorDistance); //has to &lf because must know the size of it before getting it in
aidanPJG 48:e9578f56534a 16 break;
aidanPJG 48:e9578f56534a 17 }
aidanPJG 48:e9578f56534a 18 }
aidanPJG 49:889751dd0395 19 pc.printf("sensorNumber : %d \t sensorDistance : %f", sensorNumber, sensorDistance );
aidanPJG 48:e9578f56534a 20 return(sensorNumber, sensorDistance);
aidanPJG 48:e9578f56534a 21 }