From 1e4bba322a225d04aa997e308529f21e7bb0c207 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Tue, 10 Dec 2019 11:46:55 +0200 Subject: [PATCH] Autonomous car parking code. --- autonomousCar/driver.ino/driver.ino.ino | 127 ++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 autonomousCar/driver.ino/driver.ino.ino diff --git a/autonomousCar/driver.ino/driver.ino.ino b/autonomousCar/driver.ino/driver.ino.ino new file mode 100644 index 0000000..6a87294 --- /dev/null +++ b/autonomousCar/driver.ino/driver.ino.ino @@ -0,0 +1,127 @@ +/* +* Athors: Oulis Evnagelos, Oulis Nikolaos, Katsibras Drosos +* Ultrasonic Sensor HC-SR04 and Arduino +* Dual Stepper Motor Shiled 1.1 +* +*/ + +// defines pins numbers +const int trigPin = 10; +const int echoPin = 9; +const int response = 12; +const int in1 = 2; +const int in2 = 4; +const int in3 = 7; +const int in4 = 8; +const int rightSpeed = 5; +const int leftSpeed = 3; + +// defines variables +long duration; +int distance; + +void clearUltrasonic(){ + // Clears the trigPin + analogWrite(trigPin, LOW); + delayMicroseconds(2); +} + +void setup() { +pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output +pinMode(echoPin, INPUT); // Sets the echoPin as an Input + +pinMode(response, OUTPUT); // Sets to led aoutput. + +pinMode(in1, OUTPUT); //Motor Driver 1st Pin +pinMode(in2, OUTPUT); //Motor Driver 2nd Pin +pinMode(in3, OUTPUT); //Motor Driver 3rd Pin +pinMode(in4, OUTPUT); //Motor Driver 4th Pin + +pinMode(rightSpeed, OUTPUT); +pinMode(leftSpeed, OUTPUT); + +Serial.begin(9600); // Starts the serial communication +clearUltrasonic(); +} + +//Stepper Function +void step(/*boolean dir,*/int steps){ +// digitalWrite(dirPin1,dir); +// digitalWrite(dirPin2,dir); + delay(50); + for(int i=0;i