Hello,
I am stumped as to how to configure this code. Does anybody know how to base a steppers stopping from a limit sensor? It will go pos or neg based off a HIGH/LOW from an external controller giving GND or 5+, but, I need to (I think) get a "feed+ or feed- instead of "step ().
I am definitely a bit lost here. If anybody would help, it is greatly appreciated. But, also if you can clarify why so I can learn as well would be great also.
I had it kind of working with the "commented out portions", but, decided to leave them just in case and to remind myself what I have tried.
I'll remove all extemporaneous items when finished.
Here is what I've got.
#include <Stepper.h>
#define motorSteps 200
#define motorPin1 9
#define motorPin2 10
#define motorPin3 11
#define motorPin4 12
const int inputPin = 2; // HI/LOW pushbutton pin
const int possensorPin = 3; // pos. direction sensor limit pin
const int negsensorPin = 4; // neg. direction sensor limit pin
const int posledPin = 5; // pos. LED Red
const int negledPin = 6; // neg. LED Green
//const int posdirectionPin = 7; // pushbutton pin
//const int negdirectionPin = 8; // pushbutton pin
int myStepperState; // variables will change:
int inputState = 0; // current state of the button
int possensorState = 255; //sets at 5+/HIGH
int negsensorState = 255; //sets at 5+/HIGH
//int posdirectionState = 0; // current state of the button
//int negdirectionState = 0; // current state of the button
// initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);
void setup()
{
// set the motor speed at 60 RPMS:
myStepper.setSpeed(60);
// initialize the pushbutton pins as an inputs:
Serial.begin(9600); // Initialize the Serial port:
pinMode(inputPin, INPUT);
//pinMode(posdirectionPin, INPUT);
//pinMode(negdirectionPin, INPUT);
pinMode(possensorPin, INPUT); //sets as pos. limit switch
pinMode(negsensorPin, INPUT); //sets as neg. limit switch
pinMode(posledPin, OUTPUT); // Up sets d-pin as output to activate LED Red
pinMode(negledPin, OUTPUT); // Down sets d-pin as uotput to activate LED Green
}
void loop()
{
Serial.println("P-Shuttle Test");
// read the state of the pushbuttons values:
inputState = digitalRead(inputPin);
possensorState = digitalRead(possensorPin);
negsensorState = digitalRead(negsensorPin);
// posdirectionState = digitalRead(posdirectionPin);
// negdirectionState = digitalRead(negdirectionPin);
if (inputState == HIGH); //if input pin gets 5+vdc
//if (posdirectionState == HIGH);
{
if (possensorState == LOW);
{
mystepper.step(0);
}
else if (possensor == HIGH);
{
digitalWrite(posledPin, HIGH); // LED Red
myStepper.step(300);
digitalWrite(posledPin, LOW);
}
}
if (inputState == LOW); //if input stays at resistored GND
//(negdirectionState == HIGH);
{
if (negsensor == LOW);
{
mystepper.step(0);
}
else if (negsensor == HIGH);
{
digitalWrite(negledPin, HIGH); // LED Green
myStepper.step(-300);
digitalWrite(negledPin, LOW);
}
}
}