const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;
void setup()
{
// Deklarasi pin sebagai output
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
// Atur arah putar motor searah jarum jam
digitalWrite(dirPin, HIGH);
// Putar motor dengan kecepatan rendah
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(1000); // Waktu tunda 1 detik
// Atur arah putar motor berlawanan arah jarum jam
digitalWrite(dirPin, LOW);
// Putar motor dengan kecepatan tinggi
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000); // Waktu tunda 1 detik
}