Hi
I am making a pan and tilt gimble that will make sweeping scans left to right and moving down a notch after each left to right movement.
Accuracy is not important and all movement is stopped when a button is pressed hence the use of delay while motors are running
I have hall effect and incremental rotary encoders to hand but that would be over kill for this project .
I have come up with the following code which seems rather repetitive and looking at making it shorter and cutting it down to a couple of lines.
Can anyone please advise.
#include <AFMotor.h>
#include <Button.h>
Button button = Button(12,PULLUP);
AF_DCMotor motor(4);
AF_DCMotor motor2(2);
void setup() {
}
void loop() {
if(button.isPressed()){
motor.run(RELEASE);
}else{
motor.run(FORWARD);
delay(5000);
motor.run(BACKWARD);
delay(5000);
motor.run(RELEASE);
motor2.run(FORWARD);
delay(1000);
motor2.run(RELEASE);
motor.run(FORWARD);
delay(5000);
motor.run(BACKWARD);
delay(5000);
motor.run(RELEASE);
motor2.run(FORWARD);
delay(1000);
motor2.run(RELEASE);
motor.run(FORWARD);
delay(5000);
motor.run(BACKWARD);
delay(5000);
motor.run(RELEASE);
motor2.run(FORWARD);
delay(1000);
motor2.run(RELEASE);
motor.run(FORWARD);
delay(5000);
motor.run(BACKWARD);
delay(5000);
motor.run(RELEASE);
motor2.run(FORWARD);
delay(1000);
motor2.run(RELEASE);
}
}