From a4925739363f066457a17d4c039bbe93c0311576 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Sat, 18 Jan 2020 11:30:16 +0200 Subject: [PATCH] Update v1.2 --- autonomousCar/autonomousCar.ino | 69 +++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/autonomousCar/autonomousCar.ino b/autonomousCar/autonomousCar.ino index 23de2eb..1b67a78 100644 --- a/autonomousCar/autonomousCar.ino +++ b/autonomousCar/autonomousCar.ino @@ -255,37 +255,56 @@ void moveCar(){ } } -void park() { - turnRight(255); +void park(int parkingNo) { + int row = (parkingNo / 2) + 1; + int side = (parking % 2) //If side is 1 then the parking is to right + // else if is 0 the parking is to left. + + while (row > 0) { + absolute(255); + forward(); + delay(FORWARD_STEP); + motor_stop(); + + r--; + } + + //Check the side value to turn. + if (side == 1) { + turnRight(255); + else { + turnLeft(255); + } forward(); delay(TURN_TIME); - absolute(255); motor_stop(); + + absolute(255); forward(); delay(400); } - String inString; - void Serial_Input() - { - - while (Serial.available() > 0) { - int inChar = Serial.read(); - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - // if you get a newline, print the string, then the string's value: - if (inChar == '\n') { - Serial.print("Value:"); - Serial.println(inString.toInt()); - Serial.print("String: "); - Serial.println(inString); - // clear the string for new input: - inString = ""; + + +int Serial_Input() +{ + int number; + if (Serial.available() > 0) { + number = Serial.parseInt(); + while (number <= 0) { + // convert the incoming byte to a char and add it to the string: + number = Serial.parseInt(); + } + + // if you get a newline, print the string, then the string's value: + + Serial.print("Value:"); + Serial.println(number); + // clear the string for new input: } - } - } + + return number; +} void loop() { // Calculating the distance @@ -295,8 +314,8 @@ void loop() { //Serial.print("Distance: "); //Serial.println(distance); // Read serial input: - Serial_Input(); - park(); + + park(Serial_Input()); //delay(1000); // if (distance <15) { // // Change direction to motors