Browse Source

Update Driver code v1.2

master
Evangelos Oulis 5 years ago
parent
commit
9025c13a2e
  1. 55
      autonomousCar/driver.ino/driver.ino.ino

55
autonomousCar/driver.ino/driver.ino.ino

@ -5,10 +5,31 @@
*
*/
/*
* Include all libraries.
*/
#include <Stepper.h>
/*
* -------------------------------------------------------
*/
/*
* All Definitions.
*/
#define STEPS 2048
/*
* -------------------------------------------------------
*/
// defines pins numbers
const int trigPin = 12;
const int echoPin = 9;
const int response = 13;
//const int response = 13;
/*
* For Motor Driver Pis.
*/
const int in1 = 2;
const int in2 = 4;
const int in3 = 7;
@ -16,9 +37,22 @@ const int in4 = 8;
const int rightSpeed = 5;
const int leftSpeed = 3;
/*
* For Stepper Motor Pins
*/
const int in1_1 = 6;
const int int2_1 = 10;
const int int3_1 = 11;
const int int4_1 = 13;
// defines variables
long duration;
int distance, distanceCm;
int i;
/*
*
*/
Stepper stepper(STEPS, in1_1, int2_1, int3_1, int4_1);
void clearUltrasonic(){
// Clears the trigPin
@ -30,7 +64,7 @@ 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(response, OUTPUT); // Sets to led aoutput.
pinMode(in1, OUTPUT); //Motor Driver 1st Pin
pinMode(in2, OUTPUT); //Motor Driver 2nd Pin
@ -40,8 +74,11 @@ pinMode(in4, OUTPUT); //Motor Driver 4th Pin
pinMode(rightSpeed, OUTPUT);
pinMode(leftSpeed, OUTPUT);
stepper.setSpeed(200);
Serial.begin(9600); // Starts the serial communication
clearUltrasonic();
i = 0;
}
int getDistance(int echoPin, int trigPin){
@ -114,7 +151,7 @@ void motor_stop(){
void loop() {
// Calculating the distance
distance= getDistance(echoPin, trigPin);
/*distance= getDistance(echoPin, trigPin);
// Prints the distance on the Serial Monitor
//Serial.print("Distance: ");
@ -127,6 +164,16 @@ if (distance < 10){
else{
forward();
digitalWrite(response, LOW);
}*/
//stepper.step(1200);
//delay(1000);
if (i < 2048){
stepper.step(5);
i += 4;
}
else{
stepper.step(5);
i = 0;
}
delay(1000);
delay(500);
}

Loading…
Cancel
Save