Skip to content

Add a 1-phase excitation pattern #62

@s1204IT

Description

@s1204IT
const byte STEPPER_MOTOR_1_PIN = 32;
const byte STEPPER_MOTOR_2_PIN = 33;
const byte STEPPER_MOTOR_3_PIN = 34;
const byte STEPPER_MOTOR_4_PIN = 35;

const byte STEPPER_PINS[] = { STEPPER_MOTOR_1_PIN, STEPPER_MOTOR_2_PIN, STEPPER_MOTOR_3_PIN, STEPPER_MOTOR_4_PIN };
const byte STEPPER_PATTERNS[4][4] = { { HIGH, LOW, LOW, LOW }, { LOW, HIGH, LOW, LOW }, { LOW, LOW, HIGH, LOW }, { LOW, LOW, LOW, HIGH } };

void stepper(const boolean reverse = false) {
  static byte step_index = 0;
  for (byte i = 0; i < 4; i++)
    digitalWrite(STEPPER_PINS[i], STEPPER_PATTERNS[reverse ? (3 - step_index) : step_index][i]);
  step_index = (step_index + 1) % 4;
}

This is the code I created to operate a single-phase excitation stepper motor.

Without an argument it moves one step clockwise, and if you pass true as an argument it moves one step counterclockwise.

As you can see from STEPPER_PATTERNS, in this case there is only one pin that goes HIGH.

Please add this pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: codeRelated to content of the project itselftype: enhancementProposed improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions