int delayTime = 1500;
//positionArray[aantal stappen][aantal index]
int Miner[3][3] = {{250, 50, 1}, {20, 10, 1}, {30, 40, 1}}; // {x,y,click}
int currentX = 0;
int currentY = 0;
int currentStep = 0;
#include <AFMotor.h>
#include <Servo.h>
AF_Stepper motorX(48, 1);
AF_Stepper motorY(48, 2);
Servo clicker;
void setup() {
clicker.attach(9);
motorX.setSpeed(200);
motorY.setSpeed(200);
motorX.step(250,BACKWARD, MICROSTEP);
motorX.release();
motorY.step(250, BACKWARD, MICROSTEP);
motorY.release();
}
void loop() {
goToPos(Miner[currentStep][0], Miner[currentStep][1]);
if(Miner[currentStep][2] == 1){
clicker.write(90);
delay(500);
clicker.write(0);
}
delay(delayTime);
currentStep++;
if (currentStep == 3){
currentStep = 0;
}
}
void forward(int steps, AF_Stepper as) {
as.step(steps, FORWARD, MICROSTEP);
}
void backward(int steps, AF_Stepper as) {
as.step(steps, BACKWARD, MICROSTEP);
}
void goToPos(int x, int y) {
if (currentX > x) {
backward(currentX - x, motorX);
}
if (currentY > y) {
backward(currentY - y, motorY);
}
if (currentX < x) {
forward(x - currentX, motorX);
}
if (currentY < y) {
forward(y - currentY, motorY);
}
currentX = x;
currentY = y;
}