Actuator control prog I'm having problems with!

I’m not an old hand at this and my code, at the moment, is rather crude. I am however, over 50 and have bad eyesight. Any help would be greatly appreciated.

I don’t understand why backUpButton is not behaving as it should. Or indeed as the other buttons do. I cannot find the error in my backUpButton code. And with the previous iteration of my code and an untouched breadboard, ALL buttons are functioning. So, it cannot be a hardware issue!

The button backUpButton is supposed to extend an actuator, via a relay, for the time the button is held or untill the limit switch backLimTop is hit. But what is happening is the backUpButton on close does nothing but on release it turns on power to backUpMotor and will not turn it off untill backLimTop is HIT.

The other buttons ie. backDownButton etc. does what it should. IE.Press the backDownButton, relay backDownMotor switches, when button released, relay closes and all is fine. If while backDownButton held the backLimBot is hit backDownButton becomes unresponsive and backDownMotor shuts off. Which is exactly what should happen.

Someone who’s knowledge is over and above my own should be able to find it

Please, any help?

Larry

PS. It’s on a mega2560
PPS. There are 2 actuators named backMotor and liftMotor.

The code:

#include <EEPROM.h>

/* Larry’s actuator control program
*

  • L. Steingold
  • Saturday 1 July 2017 16:00
  • copyrighted 1 July 2017

*/

//Button definitions

// Back limit and mid point switch defines

int backLimTop = 53;
int backLimMid = 52;
int backLimBot = 51;

// Lift limit and mid point defines

int liftLimTop = 50;
int liftLimMid = 49;
int liftLimBot = 48;

//Movement switch defines

int backUpButton = 47;
int backDownButton = 46;
int liftUpButton = 45;
int liftDownButton = 44;
int centreButton = 43;

// Relay pins defines

int backUpMotor = 22;
int backDownMotor = 23;
int liftUpMotor = 24;
int liftDownMotor = 25;

// LED defines
// Relay BACK status LED defines

int ledBackTop = 26;
int ledBackMid = 27;
int ledBackBot = 28;

// Relay LIFT status LED defines
int ledLiftTop = 29;
int ledLiftMid = 30;
int ledLiftBot = 31;

void setup() {
// Limit switches
// BACK motor limit switch inputs

pinMode(backLimTop, INPUT);
pinMode(backLimMid, INPUT);
pinMode(backLimBot, INPUT);

// LIFT motor limit switch inputs

pinMode(liftLimTop, INPUT);
pinMode(liftLimMid, INPUT);
pinMode(liftLimBot, INPUT);

//Movement button inputs

pinMode(backUpButton, INPUT);
pinMode(backDownButton, INPUT);
pinMode(liftUpButton, INPUT);
pinMode(liftDownButton, INPUT);
pinMode(centreButton, INPUT);

// Relay outputs only 1 OFF per motor!

pinMode(backUpMotor,OUTPUT);
pinMode(backDownMotor,OUTPUT);
pinMode(liftUpMotor,OUTPUT);
pinMode(liftDownMotor,OUTPUT);

// LED outputs

pinMode(ledBackTop,OUTPUT);
pinMode(ledBackMid,OUTPUT);
pinMode(ledBackBot,OUTPUT);
pinMode(ledLiftTop,OUTPUT);
pinMode(ledLiftMid,OUTPUT);
pinMode(ledLiftBot,OUTPUT);

// Relay Control outputs. 0 = ON.

digitalWrite(backUpMotor,HIGH);
digitalWrite(backDownMotor,HIGH);
digitalWrite(liftUpMotor,HIGH);
digitalWrite(liftDownMotor,HIGH);

// Back limit switches

digitalWrite(backLimTop, HIGH);
digitalWrite(backLimMid, HIGH);
digitalWrite(backLimBot, HIGH);

// LIFT motor limit switche inputs

digitalWrite(liftLimTop, HIGH);
digitalWrite(liftLimMid, HIGH);
digitalWrite(liftLimBot, HIGH);

//Movement button inputs

digitalWrite(backUpButton, HIGH);
digitalWrite(backDownButton, HIGH);
digitalWrite(liftUpButton, HIGH);
digitalWrite(liftDownButton, HIGH);
digitalWrite(centreButton, HIGH);

// Status LED arrays

digitalWrite(ledBackTop,LOW);
digitalWrite(ledBackMid,LOW);
digitalWrite(ledBackBot,LOW);
digitalWrite(ledLiftTop,LOW);
digitalWrite(ledLiftMid,LOW);
digitalWrite(ledLiftBot,LOW);
}

void clearEeprom(){

for (int i = 0 ; i < 7 ; i++){
EEPROM.write(i, 0);
}
}

void setEeprom(int addr,byte direct){
EEPROM.write(addr,direct);
return;
}

byte getEeprom(int addr){
byte got = EEPROM.read(addr);
return(got);

}

void displayStatus(){
// Display the state of last switch tripped
// Uses EEPROM to read which was the last switches hit and in what direction the actuator was going in.
}

void pollLimSwitches(){
// TRAVEL LIMIT AND MIDDLE SWITCHES TESTS AND SET MEMORY 0 TO SHOW LAST TRIPPED SWITCH

// BACK TOP LIMIT SWITCH TEST
if(digitalRead(backLimTop) == LOW){ // If backLimTop pressed

delay(10); // Short delay for bounce
setEeprom(0,1); // This means TOP switch HIT can only be on way UP

}

// BACK MIDDLE LIMIT SWITCH TEST
if(digitalRead(backLimMid) == LOW){

delay(10);
if (digitalRead(backUpButton) == LOW){
setEeprom(0,2); //This means the mid way was hit when going up. Which means we are in the upper half of the actuator
}
else{
setEeprom(0,3); //This means the mid way was hit when going down. Which means we are in the lower half of the actuator
}
}

// BACK BOTTOM LIMIT SWITCH TEST
if(digitalRead(backLimBot) == LOW){

delay(10);
setEeprom(0,4); // This means it could only have been going DOWN to hit the BOTTOM limit switch.

}

// LIFT TOP LIMIT SWITCH TEST
if(digitalRead(liftLimTop) == LOW){

delay(10);
setEeprom(0,5); // Set to 5 because it could only have been moving UP to HIT the top switch

}

// LIFT MIDDLE LIMIT SWITCH TEST
if(digitalRead(liftLimMid) == LOW){

delay(10);

if (digitalRead(backUpButton) == LOW){
setEeprom(0,6); //This means the mid way was hit when going up. Which means we are in the upper half of the actuator
}
else{
setEeprom(0,7); //This means the mid way was hit when going down. Which means we are in the lower half of the actuator
}
}

// LIFT BOTTOM LIMIT SWITCH TEST
if(digitalRead(liftLimBot) == LOW){

delay(10);

setEeprom(0,8); // This means it could only HIT the BOTTOM switch going down
}

return;
}

void loop()
{

//pollLimSwitches();

// BACK motor control

if( digitalRead(backUpButton) == LOW && digitalRead(backLimTop) == HIGH){
delay(10);

while(digitalRead(backUpButton) == LOW && digitalRead(backLimTop) == HIGH){
digitalWrite(backUpMotor,LOW);
pollLimSwitches();
}

digitalWrite(backUpMotor,HIGH);

}

if( digitalRead(backDownButton) == LOW && digitalRead(backLimBot) == HIGH) {
delay(10);

while(digitalRead(backDownButton) == LOW && digitalRead(backLimBot) == HIGH){
digitalWrite(backDownMotor,LOW);
pollLimSwitches();

}
digitalWrite(backDownMotor,HIGH);

}

// LIFT motor control

if( digitalRead(liftUpButton) == LOW && digitalRead(liftLimBot) == HIGH){
delay(10);

while(digitalRead(liftUpButton) == LOW && digitalRead(liftLimBot) == HIGH){
digitalWrite(liftUpMotor,LOW);
pollLimSwitches();
}

digitalWrite(liftUpMotor,HIGH);

}

if( digitalRead(liftDownButton) == LOW && digitalRead(liftLimBot) == HIGH){
delay(10);

while(digitalRead(liftDownButton) == HIGH && digitalRead(liftLimBot) == HIGH){
digitalWrite(liftDownMotor,LOW);
pollLimSwitches();

}
digitalWrite(liftDownMotor,HIGH);

}
}

Please post your code - attachments are hard to read on mobile devices.

It's OK, I found it.

I really must get to the opticians ASAP!

Thanks anyway!

Larry