Skip to content

Instantly share code, notes, and snippets.

@giljr
Created August 14, 2019 02:05
Show Gist options
  • Save giljr/e03fcf384382b4dfba9e37f3834650dc to your computer and use it in GitHub Desktop.
Save giljr/e03fcf384382b4dfba9e37f3834650dc to your computer and use it in GitHub Desktop.
// Motor x-Axis
int Red = 14; // Firing order for 4-Wire Micro-step Motor
int Brown = 15; // First Brown coil
int Yellow = 16; // Then Yellow coil and so on...
int Orange = 10;
// Motor y-axis
// int Red = 2; // Firing order for 28BYJ-48 Stepper Motor
// int Brown = 3; // First Brown coil
// int Yellow = 4; // Then Yellow coil and so on...
// int Orange = 5;
long del = 500000; // 50.000 (+SPEED) -> 999.000 (-SPEED)// ABOVE this figure the motor will stall:/
void setup() {
pinMode(Red, OUTPUT);
pinMode(Brown, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Orange, OUTPUT);
for (int e = 0; e <= 5; e++) {
//for (int i = 0; i <= 40; i++) {
for (int i = 0; i <= 35; i++) {
phaseOne();
phaseTwo();
phaseThree();
phaseFour();
}
//for (int j = 0; j <= 40; j++) {
for (int j = 0; j <= 35; j++) {
phaseFour();
phaseThree();
phaseTwo();
phaseOne();
}
}
}
void phaseOne() {
digitalWrite(Red, LOW);
digitalWrite(Brown, HIGH);
digitalWrite(Yellow, HIGH);
digitalWrite(Orange, LOW);
delayMicroseconds(del);
}
void phaseTwo() {
digitalWrite(Red, LOW);
digitalWrite(Brown, HIGH);
digitalWrite(Yellow, LOW);
digitalWrite(Orange, HIGH);
delayMicroseconds(del);
}
void phaseThree() {
digitalWrite(Red, HIGH);
digitalWrite(Brown, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Orange, HIGH);
delayMicroseconds(del);
}
void phaseFour() {
digitalWrite(Red, HIGH);
digitalWrite(Brown, LOW);
digitalWrite(Yellow, HIGH);
digitalWrite(Orange, LOW);
delayMicroseconds(del);
}
void motorOff() {
digitalWrite(Red, LOW);
digitalWrite(Brown, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Orange, LOW);
}
// the loop routine runs over and over again forever:
void loop() {
for (int e = 0; e <= 5; e++) {
//for (int i = 0; i <= 40; i++) {
for (int i = 0; i <= 35; i++) {
phaseOne();
phaseTwo();
phaseThree();
phaseFour();
}
//for (int j = 0; j <= 40; j++) {
for (int j = 0; j <= 35; j++) {
phaseFour();
phaseThree();
phaseTwo();
phaseOne();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment