Created
November 12, 2018 01:06
-
-
Save brennancheung/27ab655c6e16ade8b1c2016d287af946 to your computer and use it in GitHub Desktop.
This file contains 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
int PUL = 10; | |
int DIR = 11; | |
int ENA = 12; | |
void setup() { | |
pinMode(PUL, OUTPUT); | |
pinMode(DIR, OUTPUT); | |
pinMode(ENA, OUTPUT); | |
digitalWrite(PUL, LOW); | |
digitalWrite(ENA, LOW); | |
digitalWrite(DIR, HIGH); | |
Serial.begin(9600); | |
Serial.println("init"); | |
digitalWrite(ENA, HIGH); | |
delay(100); | |
digitalWrite(ENA, LOW); | |
} | |
void movement(int dir, long steps, long delayMs) { | |
for (long i=0; i<steps; i++) { | |
digitalWrite(DIR, dir); | |
digitalWrite(PUL, HIGH); | |
delayMicroseconds(delayMs); | |
digitalWrite(PUL, LOW); | |
} | |
} | |
int d = 1000; | |
void loop() { | |
// delay(1000); return; | |
long pulses = 800; | |
long usecs = 100; | |
while (true) { | |
movement(LOW, pulses, usecs); | |
delay(d); | |
movement(HIGH, pulses, usecs); | |
delay(d); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment