Browse Source

Update v1.2

master
Evangelos Oulis 5 years ago
parent
commit
a492573936
  1. 69
      autonomousCar/autonomousCar.ino

69
autonomousCar/autonomousCar.ino

@ -255,37 +255,56 @@ void moveCar(){
} }
} }
void park() { void park(int parkingNo) {
turnRight(255); 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(); forward();
delay(TURN_TIME); delay(TURN_TIME);
absolute(255);
motor_stop(); motor_stop();
absolute(255);
forward(); forward();
delay(400); delay(400);
} }
String inString;
void Serial_Input()
{ int Serial_Input()
{
while (Serial.available() > 0) { int number;
int inChar = Serial.read(); if (Serial.available() > 0) {
if (isDigit(inChar)) { number = Serial.parseInt();
// convert the incoming byte to a char and add it to the string: while (number <= 0) {
inString += (char)inChar; // 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: }
if (inChar == '\n') {
Serial.print("Value:"); // if you get a newline, print the string, then the string's value:
Serial.println(inString.toInt());
Serial.print("String: "); Serial.print("Value:");
Serial.println(inString); Serial.println(number);
// clear the string for new input: // clear the string for new input:
inString = "";
} }
}
} return number;
}
void loop() { void loop() {
// Calculating the distance // Calculating the distance
@ -295,8 +314,8 @@ void loop() {
//Serial.print("Distance: "); //Serial.print("Distance: ");
//Serial.println(distance); //Serial.println(distance);
// Read serial input: // Read serial input:
Serial_Input();
park(); park(Serial_Input());
//delay(1000); //delay(1000);
// if (distance <15) { // if (distance <15) {
// // Change direction to motors // // Change direction to motors

Loading…
Cancel
Save