// Raspberry Pi Pico + Stepper Motor Example

#define DIR_PIN 2
#define STEP_PIN 3
#define btnPin 9
int calibratedStepsUp;
int calibratedStepsDown;

enum direction
{
  NONE,
  UP,
  DOWN,
};
direction dir;

void setup() {
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  digitalWrite(STEP_PIN, LOW);
  Serial.begin(115200);
}

void calibrateSteps(direction dir)
{
  if(dir == UP)
  {
        for(calibratedStepsUp = 0; digitalRead(btnPin) != HIGH; calibratedStepsUp++)
    {
    digitalWrite(STEP_PIN, HIGH);
    digitalWrite(STEP_PIN, LOW);
    delay(10); // 2 ms * 200 = 0.4 seconds
    }
  }
  else if(dir == DOWN)
  {
        for(calibratedStepsDown = 0; digitalRead(btnPin) != HIGH; calibratedStepsDown++)
    {
    digitalWrite(STEP_PIN, HIGH);
    digitalWrite(STEP_PIN, LOW);
    delay(10); // 2 ms * 200 = 0.4 seconds
    }
  }
}

void loop() {
  // Move 200 steps (one rotation) CW over one second
  digitalWrite(DIR_PIN, HIGH);
}


BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
A4988