so something like this then (with an active wait) ?
// BTS7960 pins
const byte RPWM = 3;
const byte LPWM = 6;
const byte REN = 4;
const byte LEN = 7;
// Limit Switch
const byte buttonPin = 12;
void setup() {
pinMode(buttonPin, INPUT); // external pull down
pinMode(RPWM, OUTPUT);
pinMode(LPWM, OUTPUT);
pinMode(LEN, OUTPUT);
pinMode(REN, OUTPUT);
digitalWrite(REN, HIGH);
digitalWrite(LEN, HIGH);
}
void loop() {
// wait for the limit switch to be activated
while (digitalRead(12) == LOW);
// do your stuff once
delay(500);
digitalWrite(LEN, HIGH);
digitalWrite(LPWM, HIGH);
delay(4000);
digitalWrite(LEN, LOW);
digitalWrite(LPWM, LOW);
delay(500);
digitalWrite(13, HIGH);
// wait for the limit switch to be reset
while (digitalRead(12) == HIGH);
delay(20); // poor's man anti-bounce
}
you don't use REN?
if you disable LEN, do you need to set the PWM to 0 too ?
13 was not set as an output, yet you do digitalWrite(13, HIGH);... that's not a good idea (activates the pull-up? ). is that just the LED built in or do you have something connected there?