Created
November 28, 2019 16:04
-
-
Save ming-chu/6ce99910cbd44a90663399b83a85eb1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simple Stepper Motor Control Exaple Code | |
* | |
* by Dejan Nedelkovski, www.HowToMechatronics.com | |
* | |
*/ | |
// defines pins numbers | |
const int stepPin = 3; | |
const int dirPin = 4; | |
void setup() { | |
// Sets the two pins as Outputs | |
pinMode(stepPin,OUTPUT); | |
pinMode(dirPin,OUTPUT); | |
} | |
void loop() { | |
//dirPin->LOW/HIGH: 順逆時針方向 | |
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(500); | |
digitalWrite(stepPin,LOW); | |
delayMicroseconds(500); | |
} | |
delay(1000); // One second delay | |
//dirPin->LOW/HIGH: 順逆時針方向 | |
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(500); | |
digitalWrite(stepPin,LOW); | |
delayMicroseconds(500); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment