Browse Source

Update v1.2

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

53
autonomousCar/autonomousCar.ino

@ -255,36 +255,55 @@ void moveCar(){
} }
} }
void park() { 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); 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()
{
while (Serial.available() > 0) {
int inChar = Serial.read(); int Serial_Input()
if (isDigit(inChar)) { {
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: // convert the incoming byte to a char and add it to the string:
inString += (char)inChar; number = Serial.parseInt();
} }
// if you get a newline, print the string, then the string's value: // if you get a newline, print the string, then the string's value:
if (inChar == '\n') {
Serial.print("Value:"); Serial.print("Value:");
Serial.println(inString.toInt()); Serial.println(number);
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input: // clear the string for new input:
inString = "";
}
} }
return number;
} }
void loop() { void loop() {
@ -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