Files
SyncHome/trunk/Arduino/sketch_nano_A4988/sketch_nano_A4988.ino
2023-03-13 09:05:51 +00:00

45 lines
1.2 KiB
C++

/* Simple Stepper Motor Control Exaple Code
*
* by Dejan Nedelkovski, www.HowToMechatronics.com
* https://howtomechatronics.com/tutorials/arduino/how-to-control-stepper-motor-with-a4988-driver-and-arduino/
*
* https://forum.arduino.cc/index.php?topic=406110.0 <-- Shield midifications
*/
// defines pins numbers
const int stepPin = 5; // x:2, y:3, z:4
const int dirPin = 2; // x:5, y:6, z:7
const int enPin = 8; // all together
void setup() {
// Sets the two pins as Outputs
//pinMode(enPin,OUTPUT);
//digitalWrite(enPin,LOW);
pinMode(enPin,INPUT);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(50000);
digitalWrite(stepPin,LOW);
delayMicroseconds(50000);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(50000);
digitalWrite(stepPin,LOW);
delayMicroseconds(50000);
}
delay(1000);
}