
int stepperpostion = 0;
int dirpin = 10;
int steppin = 9;
int target = 15; 


const int analogInPin = A4;  // Analog input pin that the potentiometer is attached to
//const int analogOutPin = 8;  // Analog input pin that the potentiometer is attached to


//const int sensor = 7; //pin 7 on ardunio that its connected to.
int sensorValue = 0;  
//int outputValue = 0;


void setup(){
  Serial.begin(9600);
  pinMode(dirpin, OUTPUT); // direction pin on servo motor control board
  pinMode(steppin, OUTPUT); // amount of steps that need to be taken, for my specfic motor which is 48 steps
  //digitalWrite(dirpin, HIGH); /// <<<<<<<<
}

void loop() {
  
  sensorValue = analogRead(analogInPin);
  target = map(sensorValue,0, 1023, -20, 20);
  Serial.print("target: ");
  Serial.print(target); 
  Serial.print(" SensorVal: ");
  Serial.print(sensorValue);
  Serial.print(" stepperpos: ");
   Serial.println (stepperpostion); 

  if (stepperpostion != target){
  
  
 if (stepperpostion < target){  
 digitalWrite (dirpin, HIGH); // turn pin on to make it spin
 stepperpostion ++; 
 }

  if (stepperpostion > target){
  digitalWrite (dirpin, LOW); 
  stepperpostion --; 
   }
  digitalWrite (steppin, HIGH);
  delay (50);
  digitalWrite (steppin, LOW);
  delay (50);
}

}
