// Design by Eko Andriyanto
// Sebaik-baik manusia adalah yang paling bermanfaat bagi orang lain
// Maju Teknik Art 0878-5063-1600
#include <AccelStepper.h>
#define DIR_A 11
#define STEP_A 12
#define DIR_B 8
#define STEP_B 9
#define START_BUTTON A1
#define POT_PIN A0
#define RELAY_PIN_1 10
#define RELAY_PIN_2 6
#define STEPS_PER_REV 1600
#define DEBOUNCE_DELAY 100 // 100ms debounce time
AccelStepper motorA(AccelStepper::DRIVER, STEP_A, DIR_A);
AccelStepper motorB(AccelStepper::DRIVER, STEP_B, DIR_B);
bool isRunning = false;
unsigned long lastButtonCheck = 0;
int lastButtonState = HIGH;
void setup() {
pinMode(START_BUTTON, INPUT_PULLUP);
pinMode(RELAY_PIN_1, OUTPUT);
pinMode(RELAY_PIN_2, OUTPUT);
digitalWrite(RELAY_PIN_1, LOW);
digitalWrite(RELAY_PIN_2, LOW);
motorA.setMaxSpeed(2000);
motorA.setAcceleration(2000);
motorB.setMaxSpeed(4000);
motorB.setAcceleration(4000);
motorA.setCurrentPosition(0);
motorB.setCurrentPosition(0);
}
void loop() {
int currentButtonState = digitalRead(START_BUTTON);
// Deteksi ketika button berubah dari HIGH ke LOW (ditekan)
if (currentButtonState == LOW && lastButtonState == HIGH) {
lastButtonCheck = millis(); // Catat waktu saat button mulai ditekan
}
// Jika button masih ditekan setelah debounce time dan system tidak sedang running
if (currentButtonState == LOW &&
(millis() - lastButtonCheck >= DEBOUNCE_DELAY) &&
!isRunning) {
isRunning = true;
runSequence();
isRunning = false;
lastButtonCheck = millis(); // Reset setelah sequence selesai
}
lastButtonState = currentButtonState; // Simpan state untuk loop berikutnya
}
void runSequence() {
digitalWrite(RELAY_PIN_1, HIGH);
delay(500);
digitalWrite(RELAY_PIN_2, HIGH);
struct Step {
float angle;
int stepB;
};
Step steps[] = {
{ 0, 800 }, { 22.5, 1600 }, { 45, 1600 }, { 67.5, 1600 },
{ 90, 1600 }, { 112.5, 1600 }, { 135, 1600 }, { 157.5, 1600 },
{ 180, 1600 }, { 202.5, 1600 }, { 225, 1600 }, { 247.5, 1600 },
{ 270, 1600 }, { 292.5, 1600 }, { 315, 1600 }, { 337.5, 1600 },
{ 360, 1600 }, { 382.5, 800 }
};
int totalSteps = sizeof(steps) / sizeof(steps[0]);
for (int i = 0; i < totalSteps; i++) {
moveMotorA(steps[i].angle);
moveMotorB(steps[i].stepB);
}
motorA.setCurrentPosition(0);
motorB.setCurrentPosition(0);
digitalWrite(RELAY_PIN_1, LOW);
digitalWrite(RELAY_PIN_2, LOW);
}
void moveMotorA(float angle) {
int targetSteps = (angle / 360.0) * STEPS_PER_REV;
motorA.moveTo(targetSteps);
while (motorA.distanceToGo() != 0) {
updateSpeed();
motorA.run();
}
}
void moveMotorB(int stepsToMove) {
long targetPosition = motorB.currentPosition() + stepsToMove;
motorB.moveTo(targetPosition);
while (motorB.distanceToGo() != 0) {
updateSpeed();
motorB.runSpeed();
}
}
void updateSpeed() {
int potValue = analogRead(POT_PIN);
int speed = map(potValue, 0, 1023, 1000, 5000);
motorA.setSpeed(speed);
motorB.setSpeed(speed);
}START
emergency
BUZZER
selenoid benang
selenoid capit kok
pedal manual
wiring di seri start dan pedal
menggunakan tombol push botton NO NO