simple but chalenging relay problem

So I have been working on this for a while now i have trule hit a road block with my skill.The prozect is based on an arduino uno, 3 relays ,2 buttons and a screen. The 2 buttons are suposed to switch betwin the relays one acting as a plus and the other as a minus , for exaple if relay 1 is on and button plus is pressed then the program suld turn off relay 1 and turn on relay 2.The same sould hapen if the button is pressed again and go from relay 2 to 3( I am sorry if I am being repeteteve ) the same uld hapen with button m,inus but in reverse. The screen is there to tell you what relay is on (you will notise in the code that relay 3 is labled as “MAXIMUM EFORT” ). Anyways i wrote the code to the best of my ability and it seems to run but it just doesent work it seems as if the button presses do not register( yes i have checed the whiring 1000 times it is not the problem). without any further mambling here is the code . Lituraly any help is more than aprisiated
(btw the display does turn on desplays " D1 " as well relay 1 that also turns on "
the buttons are momentery switches an the display runs of a 12c lcd driver

telikos_kodikas.ino (1.35 KB)

You should include your code in code tags unless it is too large. Here it is properly formatted:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int buttonplus = 6;
const int buttonminus = 7;

int Relay1 = 0;
int Relay2 = 1;
int Relay3 = 2;
int pinState1 = 0;
int pinState2 = 0;
int pinState3 = 0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int buttonState1 = 0;
int buttonState2 = 0;
void setup() 
{
  const int buttonplus = 6;
  const int buttonminus = 7;
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
  pinMode(Relay3, OUTPUT);
  lcd.clear();
  buttonState1 = digitalRead(buttonplus);
  buttonState2 = digitalRead(buttonminus);
  int pinState1 = digitalRead(Relay1);
  int pinState2 = digitalRead(Relay2);
  int pinState3 = digitalRead(Relay3);
}

void loop() {
  digitalWrite(Relay1, LOW);
  digitalWrite(Relay2, HIGH);
  digitalWrite(Relay3, HIGH);
  lcd.setCursor(6, 0);
  lcd.print("D1");

  if (buttonState1 == HIGH)
  { 
    if (pinState1 == LOW)
    { digitalWrite(Relay1, HIGH);
      digitalWrite(Relay2, LOW);
      lcd.print("D2");
    }

    // ad d1 edo
    else if (pinState2 == LOW)
    { 
      digitalWrite(Relay2, HIGH);
      digitalWrite(Relay3, LOW);
      lcd.setCursor(1, 0);
      lcd.print("MAXIMUM EFFORT");
    }
  }

  if (buttonState2 == HIGH)
  { 
    if (pinState3 == LOW)
    { 
      digitalWrite(Relay3, HIGH);
      digitalWrite(Relay2, LOW);
      lcd.setCursor(6, 0);
      lcd.print("D2");
    }
    else if (pinState2 == LOW)
    { 
      digitalWrite(Relay2, HIGH);
      digitalWrite(Relay1, LOW);
      lcd.print("D1");
    }
  }
}

I see several issues with your code:

1) You re-declare buttonplus and buttonminus within your setup() function. Those constants are already declared globally so you should delete them from the setup function.

2) You re-declare pinState1, pinState2, and pinState3 within your setup() function. Those variables are NOT the same as the globally declared pinState1, pinState2, and pinState3. You should remove the int declarations and use the global declarations in your assignments.

3) You really should set the pin modes for buttonplus and buttonminus pins even though they default to input. It is good practice.

4) You are only reading the button states during setup() so therefore you cannot detect a state change of the buttons unless you read the button statesduring your loop() function. In other words the variables buttonState1 and buttonState2 never change once you exit setup().

5) You are only reading the pin states (relay states) during setup() as well, so those variables are never changing either.

6) You should be checking for the state change of the buttons NOT the current state of the buttons. Look at this tutorial:

StateChangeDetection

How are your buttons wired? Your code implies they wired with a pull-down resistor.