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.
Dependencies: LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P
Fork of DUMP_TRUCK_SPR2017 by
Revision 4:2f1a0f628875, committed 2016-11-29
- Comitter:
- Josahty
- Date:
- Tue Nov 29 20:04:34 2016 +0000
- Parent:
- 3:cd6e2d7c7c9c
- Child:
- 5:dc4cf6cc24b3
- Commit message:
- trying to improve the Drive function by allowing it to take more than one character at a time from the terminal
Changed in this revision
| DumpTruck.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/DumpTruck.cpp Tue Nov 15 21:30:12 2016 +0000
+++ b/DumpTruck.cpp Tue Nov 29 20:04:34 2016 +0000
@@ -1,6 +1,8 @@
#include "DumpTruck.h"
#include "stdlib.h"
#include "QEI.h"
+#include "stdio.h"
+#include "string.h"
Serial pc(USBTX, USBRX);
@@ -90,44 +92,69 @@
// terminal prompt for distance
pc.printf("Please enter the truck distance:\r\n");
// sets return value to given value
- float input = pc.getc();
- input = input - 48;
+ //float input = pc.getc();
+ //input = input - 48;
// returns value
+ //return input;
+
+ char c;
+ char buffer[128];
+ pc.gets(buffer, 4);
+ float input = strtod(buffer,NULL);
return input;
+
}
float DumpTruck::setTruckSpeed(){
- float mod = 0;
- float div = 10;
- pc.printf("Enter a direction - 1 = forward, 0 = backward:\r\n");
- float dir = pc.getc();
- while ((dir<48)||(dir>49)){
- pc.printf("Invalid input. Please enter a valid direction, 1 or 0: \r\n");
- dir = pc.getc();
- }
- if (dir == 48) {
- mod = -1; }
- else {
- mod = 1; }
-
- // terminal prompt for speed
- pc.printf("Please enter a truck speed from 0-9 or F for full speed:\r\n");
- // sets return value to given value
- float input = pc.getc();
- while ((input<48)||(input>57)){
- if((input == 70) || (input == 102)) {
- input = 1;
- input = input * mod;
- return input;
- }
- pc.printf("Invalid input. Please enter a valid speed from 0-9 or F: \r\n");
- input = pc.getc();
- }
- input = input - 48;
- input = input * (1/div);
- // returns value
- input = input * mod;
- return input;}
+// float mod = 0;
+// float div = 10;
+// pc.printf("Enter a direction - 1 = forward, 0 = backward:\r\n");
+// float dir = pc.getc();
+// while ((dir<48)||(dir>49)){
+// pc.printf("Invalid input. Please enter a valid direction, 1 or 0: \r\n");
+// dir = pc.getc();
+// }
+// if (dir == 48) {
+// mod = -1; }
+// else {
+// mod = 1; }
+//
+// // terminal prompt for speed
+// pc.printf("Please enter a truck speed from 0-9 or F for full speed:\r\n");
+// // sets return value to given value
+// float input = pc.getc();
+// while ((input<48)||(input>57)){
+// if((input == 70) || (input == 102)) {
+// input = 1;
+// input = input * mod;
+// return input;
+// }
+// pc.printf("Invalid input. Please enter a valid speed from 0-9 or F: \r\n");
+// input = pc.getc();
+// }
+// input = input - 48;
+// input = input * (1/div);
+// // returns value
+// input = input * mod;
+
+
+ pc.printf("Enter a speed from -10 to +10:\r\n");
+ char c;
+ char buffer[128];
+ pc.gets(buffer, 4);
+ float input = strtod(buffer,NULL);
+
+ while ((buffer[0] < 43) || (buffer[0] > 45)) {
+ pc.printf("Invalid input. Please correct input and try again:\r\n");
+ setTruckSpeed();
+ }
+
+ pc.printf("buffer[0]: %d\r\n",buffer[0]);
+ pc.printf("buffer[1]: %d\r\n",buffer[1]);
+ pc.printf("buffer[2]: %d\r\n",buffer[2]);
+ input = input / 10;
+
+ return input;}
void DumpTruck::stop(){
