Hi the routine attached is to drive a stepper motor approx 1/2 turn forward and back again just once when pin3 goes HIGH.
When using "setSpeed (1000) the motor runs fine (no trigger yet it just bounces) and the serial output correctly shows pin3 status and motor speed.....when I change it to "setSpeed (motSpeed) the motor fails to run but no error msg.
Also the print routine only runs once.
motSpeed is set from the if/else statement and this seems to be working fine
What am I missing please?
Thanks in advance Tezzatron
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 32 //2048
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
int Steps2Take;
int switchPin = 3;
int motSpeed;
void setup()
{
Serial.begin (9600);
pinMode (switchPin, INPUT);
digitalWrite(switchPin, LOW);
}
void loop()
{
int pinState = digitalRead(switchPin);
Serial.print ("Pin Status ");
Serial.println (pinState);
delay (1000);
if (pinState == HIGH) { motSpeed = 1000; }
else { motSpeed = 0; }
Serial.print ("Motor Speed ");
Serial.println (motSpeed);
Steps2Take = STEPS_PER_OUTPUT_REVOLUTION;
small_stepper.setSpeed(1000);
small_stepper.step(Steps2Take);
delay(1000);
Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION;
small_stepper.setSpeed(1000);
small_stepper.step(Steps2Take);
delay(1000);
}