Sorry machan.....code eka verify kale nethi nisa awul keepayak thibba...ara error eka enne ekai...onna eka heduwa...dennam pothe etiyata monitoring weda karanna one
const int ForwardLimitSwitchPin = 2;
const int ReverseLimitSwitchPin = 3;
const int StepperStepPin = 4;
const int StepperDirectionPin = 5;
const int LimitSwitchActivated = LOW; // Limit switch grounds pin
const int StepperMaxRPM = 100;
const int buttonPin = 6; // the number of the pushbutton pin (choose the correct pin here)
bool ispushbuttonpressed = false; // Boolean to store push button logic
int buttonState = 0; //**correction
Stepper stepper(200, StepperStepPin, StepperDirectionPin);
int codeSection = 0; //use to check code only (remove it once code is finalized!)
void setup() {
pinMode(ForwardLimitSwitchPin, INPUT_PULLUP);
pinMode(ReverseLimitSwitchPin, INPUT_PULLUP);
stepper.setSpeed(StepperMaxRPM);
pinMode(buttonPin, INPUT); //declare push button signal as an input
Serial.begin(9600); //Serial Monitoring ON
Serial.println("Push button state\t\tForward LS State\t\tReverse LS State\t\tCode Section");
}
void loop() {
buttonState = digitalRead(buttonPin); // read push button on-off
if (buttonState == LOW) { //**LOW (not HIGH)
ispushbuttonpressed = true;
}
// Step forward until the limit switch is activated (forward rotating when hits S1) - LOOP 1
if ((ispushbuttonpressed == true) && (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added
codeSection = 1;
while (digitalRead(ForwardLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(1);
}
ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S2
}
// Step reverse until the limit switch is activated (forward rotating when hits S2) - LOOP 2
else if ((ispushbuttonpressed == true) && (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated)) { //**corrections added
codeSection = 2;
while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(-1);
}
ispushbuttonpressed == false; //re-set to avoid motor turning backward once reached S1
}
codeSection = 3; //IF monitors for a long non-of the above LOOPS executed!!
Serial.print(buttonState);
Serial.print("\t\t\t");
Serial.print(digitalRead(ForwardLimitSwitchPin));
Serial.print("\t\t\t");
Serial.print(digitalRead(ReverseLimitSwitchPin));
Serial.print("\t\t\t");
Serial.println(codeSection);
}