#include <Stepper.h>
#include <Servo.h>
Servo myservo;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 5, 6, 7, 8);
int potpin = 0;
int val;
int latval = 0;
void setup() {
Serial.begin(9600);
myservo.attach(9);
pinMode(12, OUTPUT);
digitalWrite(12, LOW);
myStepper.setSpeed(60);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
if (val != latval){
Serial.println(val);
delay(25);
latval = val;
if (val == 180){
Serial.println("Max");
digitalWrite(12, HIGH);
delay(15);
myStepper.step(stepsPerRevolution);
delay(15);
}
if (val <= 165){
digitalWrite(12, LOW);
delay(15);
}
}
}