/* NOTES:
* The sequence of control signals for 4 control wires is as follows:
*
* Step C0 C1 C2 C3
* 1 1 0 1 0
* 2 0 1 1 0
* 3 0 1 0 1
* 4 1 0 0 1
*/
const uint8_t STEP_PINS[4] = {8, 9, 10, 11}; // Sets up our output pins for driving the stepper motor in a convenient array
const uint8_t STEPS[4][4] = {HIGH, LOW, HIGH, LOW, // "Answer Key" array for what our pin values need to be for each step
LOW, HIGH, HIGH, LOW,
LOW, HIGH, LOW, HIGH,
HIGH, LOW, LOW, HIGH};
uint8_t curr_step = 0; // Variable to keep track of our current "position" for driving the stepper motor
void step(bool); // Function declaration
void setup() {
for(uint8_t _pin = 0; _pin < 4; _pin++){
pinMode(STEP_PINS[_pin], OUTPUT);
}
}
void loop() {
for(uint8_t _dir = 0; _dir < 2; _dir++){
for(uint8_t _step = 0; _step <200; _step++){
step(_dir);
delay(10);
}
}
}
void step(bool direction=1){ // Function to track & execute our steps ... moves "forwards" if [direction] == 1
if(direction){ // and "backwards" if [direction] == 0 (defaults to "forwards" if no [direction]
curr_step++; // variable is passed to it)
if(curr_step >= 4){
curr_step = 0;
}
}else{
if(curr_step > 0){
curr_step--;
}else{
curr_step = 3;
}
}
for(uint8_t _pin = 0; _pin < 4; _pin++){
digitalWrite(STEP_PINS[_pin], STEPS[curr_step][_pin]);
}
}