#include <Stepper.h>
#define VERT_PIN A0
#define HORZ_PIN A1
// change this to the number of steps on your motor
#define STEPS 8
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);
int previous = 0;
const int trigPin = 5;
const int echoPin = 4;
long duration;
int distance;
int safetyDistance;
int add;
int abb;
int pin = 7;
int pin2 = 6;
int val;
// the previous reading from the analog input
#include <Stepper.h>
void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(10000);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
pinMode(pin, INPUT_PULLUP) ;
pinMode(pin2, INPUT_PULLUP) ;
}
void loop() {
// get the sensor value
int vert = analogRead(VERT_PIN);
int horz = analogRead(HORZ_PIN);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
stepper.step(val - previous);
previous = val;
if (analogRead(VERT_PIN) >= 600){
add -=1;
val = add;
delay(200);
}
if (analogRead(VERT_PIN) <= 400){
add +=1;
val = add;
delay(200);
}
if (digitalRead(pin) == LOW){
val =-distance/16;
delay(200);
}
if (digitalRead(pin2) == LOW){
val = add;
delay(200);
}
}
// move a number of steps equal to the change in the
// sensor reading
// remember the previous value of the sensor