I'm trying to create a program that will run a stepper motor until it hits a microswitch. Once it hits the microswitch I need it to then move in the opposite direction. I've got the motor to stop once it hits the microswitch, but I'm running into problems running the motor after that.
I'm using the same "myMotor->step ()" function that I use to initially move the stepper, but now I get the error "myMotor does not name a type."
I've attached my code below. Any help would be greatly appreciated!
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include <Servo.h>
#include <AccelStepper.h>
#include "Arduino.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
int i=0;
int pin=2;
void setup() {
AFMS.begin();
Serial.begin(9600);
myMotor->setSpeed(100);
Serial.println("yeet");
while (i<100){
i=analogRead(2);
Serial.print("i=");
Serial.println(i);
myMotor->step(10,FORWARD,SINGLE);
}
}
[b] myMotor->step(10,FORWARD,SINGLE);[/b]
void loop() {}