-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f04362d
commit a99e483
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//Written By Nikodem Bartnik - nikodembartnik.pl | ||
#define STEPPER_PIN_1 9 | ||
#define STEPPER_PIN_2 10 | ||
#define STEPPER_PIN_3 11 | ||
#define STEPPER_PIN_4 12 | ||
int step_number = 0; | ||
void setup() { | ||
pinMode(STEPPER_PIN_1, OUTPUT); | ||
pinMode(STEPPER_PIN_2, OUTPUT); | ||
pinMode(STEPPER_PIN_3, OUTPUT); | ||
pinMode(STEPPER_PIN_4, OUTPUT); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
OneStep(false); | ||
delay(2); | ||
|
||
|
||
} | ||
|
||
|
||
void OneStep(bool dir){ | ||
if(dir){ | ||
switch(step_number){ | ||
case 0: | ||
digitalWrite(STEPPER_PIN_1, HIGH); | ||
digitalWrite(STEPPER_PIN_2, LOW); | ||
digitalWrite(STEPPER_PIN_3, LOW); | ||
digitalWrite(STEPPER_PIN_4, LOW); | ||
break; | ||
case 1: | ||
digitalWrite(STEPPER_PIN_1, LOW); | ||
digitalWrite(STEPPER_PIN_2, HIGH); | ||
digitalWrite(STEPPER_PIN_3, LOW); | ||
digitalWrite(STEPPER_PIN_4, LOW); | ||
break; | ||
case 2: | ||
digitalWrite(STEPPER_PIN_1, LOW); | ||
digitalWrite(STEPPER_PIN_2, LOW); | ||
digitalWrite(STEPPER_PIN_3, HIGH); | ||
digitalWrite(STEPPER_PIN_4, LOW); | ||
break; | ||
case 3: | ||
digitalWrite(STEPPER_PIN_1, LOW); | ||
digitalWrite(STEPPER_PIN_2, LOW); | ||
digitalWrite(STEPPER_PIN_3, LOW); | ||
digitalWrite(STEPPER_PIN_4, HIGH); | ||
break; | ||
} | ||
}else{ | ||
switch(step_number){ | ||
case 0: | ||
digitalWrite(STEPPER_PIN_1, LOW); | ||
digitalWrite(STEPPER_PIN_2, LOW); | ||
digitalWrite(STEPPER_PIN_3, LOW); | ||
digitalWrite(STEPPER_PIN_4, HIGH); | ||
break; | ||
case 1: | ||
digitalWrite(STEPPER_PIN_1, LOW); | ||
digitalWrite(STEPPER_PIN_2, LOW); | ||
digitalWrite(STEPPER_PIN_3, HIGH); | ||
digitalWrite(STEPPER_PIN_4, LOW); | ||
break; | ||
case 2: | ||
digitalWrite(STEPPER_PIN_1, LOW); | ||
digitalWrite(STEPPER_PIN_2, HIGH); | ||
digitalWrite(STEPPER_PIN_3, LOW); | ||
digitalWrite(STEPPER_PIN_4, LOW); | ||
break; | ||
case 3: | ||
digitalWrite(STEPPER_PIN_1, HIGH); | ||
digitalWrite(STEPPER_PIN_2, LOW); | ||
digitalWrite(STEPPER_PIN_3, LOW); | ||
digitalWrite(STEPPER_PIN_4, LOW); | ||
|
||
|
||
} | ||
} | ||
step_number++; | ||
if(step_number > 3){ | ||
step_number = 0; | ||
} | ||
} | ||
|
||
|