const int enablePin = 2;
const int motorPins[4][2] = {
{3, 4}, // Motor 1: DIR, STEP
{6, 7}, // Motor 2
{9, 10}, // Motor 3
{12, 13} // Motor 4
};
const int buttonPins[4] = {A1, A2, A3, A4}; // Tasteri
const int dirSwitchPin = A0; // Prekidač smera
const int stepDelayUs = 2500; // brzina: 1 korak = 2500 µs
void setup() {
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW); // Aktiviraj sve drajvere
for (int i = 0; i < 4; i++) {
pinMode(motorPins[i][0], OUTPUT); // DIR
pinMode(motorPins[i][1], OUTPUT); // STEP
pinMode(buttonPins[i], INPUT_PULLUP); // Tasteri
}
pinMode(dirSwitchPin, INPUT);
}
void loop() {
for (int i = 0; i < 4; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
bool direction = digitalRead(dirSwitchPin);
digitalWrite(motorPins[i][0], direction); // DIR pin
digitalWrite(motorPins[i][1], HIGH); // STEP HIGH
delayMicroseconds(stepDelayUs);
digitalWrite(motorPins[i][1], LOW); // STEP LOW
delayMicroseconds(stepDelayUs);
}
}
}