1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| // <a href="https://www.youtube.com/watch?v=Bp8iVILpD24" target="_blank">https://www.youtube.com/watch?v=Bp8iVILpD24</a>
int stepperpins[] = {2,3,4,5}; //pins du stepper
int stepperCurPos = 0; //pin activé
void SetupStepper()
{
for (int x=0; x<4; x++)
pinMode(stepperpins[x], OUTPUT);
}
void MoveStepper(int direction)
{
digitalWrite(stepperpins[stepperCurPos], 0); //turn off current pin
stepperCurPos += direction;
if (stepperCurPos > 3)
stepperCurPos = 0;
if (stepperCurPos < 0)
stepperCurPos = 3;
digitalWrite(stepperpins[stepperCurPos], 1); //turn on new current pin
}
void setup() {
SetupStepper();
}
int msdly = 3;
void loop() {
for (int x=0; x<200; x++)
{
MoveStepper(1);
delay(msdly);
}
for (int x=0; x<200; x++)
{
MoveStepper(-1);
delay(msdly);
}
} |
Partager