From e29cf9224f615492fc0bd9cc2541ece4b2ef17f8 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Wed, 17 Nov 2021 15:48:37 -0700 Subject: [PATCH] fixed terminal reading --- src/main.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e3d15f6..bef12cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,12 +9,15 @@ double PITCH_MAX = 7; double zero_height; -void setup() { - yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE - pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE +float read_float(); - Serial.println("Level the TVC and press enter."); - Serial.readString(); +void setup() { + delay(1000); + // yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + // pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + + Serial.println("Level the TVC and press 1."); + read_float(); // Do a full range of movement of the servos for (double pct = -100.0; pct <= 100.0; pct += 1.0) { @@ -22,27 +25,27 @@ void setup() { double pitch_pos = pct * PITCH_MAX; yaw.write(yaw_pos); - pitch.write(pitch_pos); + // pitch.write(pitch_pos); delay(15); } Serial.print("Please input the point height in millimeters: "); - String zero_string = Serial.readString(); - zero_height = zero_string.toFloat(); + String zero_string = read_float(); } void loop() { Serial.print("Enter Yaw Coord: "); - float yaw_pos = Serial.readString().toFloat(); + float yaw_pos = read_float(); + Serial.println(); Serial.print("Enter Pitch Coord: "); - float pitch_pos = Serial.readString().toFloat(); + float pitch_pos = read_float(); Serial.println(); Serial.println("Moving servos..."); - yaw.write(yaw_pos); - pitch.write(pitch_pos); + // yaw.write(yaw_pos); + // pitch.write(pitch_pos); Serial.print("Calculating current height"); for (int i = 0; i < 5; i++) { @@ -55,4 +58,13 @@ void loop() { Serial.println("Please verify current height is correct: " + String(height) + "\n\n\n\n\n"); +} + +float read_float() { + while (Serial.available() == 0) { + delay(100); + } + float num = Serial.parseFloat(); + Serial.print(num); + return num; } \ No newline at end of file