washing maching coding can't do -please help me

I have recently got my arduino uno and I haven't got much knowledge of c programming .My assignment was to make a washing machine.The machine should start by buttonA is pressed and pump will on and also LCD should display on the 1st column "start".When buttonB be is pressed, pump goes off and LCD should display on the 1st column "water full".Always LCD should display on the 2nd column "door open". while buttonC is pressed,LCD should display on the 2nd column"door close".While buttonB and buttonC is pressed,relayA will on for 6 seconds and then relayB will on for 4 seconds and then relayA will be off for 6 seconds and then relayB will be off for 4 seconds .Like this ,relayA and relayB repeats 2 times.After that,valve on and LCD should display on the 1st column "drain" for 3 seconds and then LCD will display on the same column "finish" . if buttonB or buttonC is released,relayA and relayB will be off also LCD shouldn't display on the 1st column anything.

problems :

-I can't stop relayA and relayB when I release buttonB or buttonC.

  • when I run it a second time by pressing the buttonB and buttonC nothing happens.
  • After LCD display's "door close" when I press buttonC LCD display's like this"door opene". I tried to add lcd.clear(); and gave a delay but LCD flickers. )

what am I doing wrong?

this is the code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

//===============================================   mantaining switch  and  2input High output High====================================   
#define pump 13                 // pump             
#define buttonA 1             //  start       
const int buttonB = 6;              
const int buttonC = 7;             

int stateA = 0;                 // store  ledA state
int stateB = 0;                 // store  ledB state
int stateC =0;                  // store  ledC state

int val = 0;                    // store buttonA state 
int old_val = 0;                // store buttonA old state
//============================================== H bridge and  valve ==================================================================
int relayA = 8;               //    forward rotation
int relayB = 9;                  //  reverse rotation
int valve = 10;                   // water drain valve
int timer=0;
int maxnum = 1;     // 
int count = 0;
int justonce=0;//  counter
int runprogtwotime=0;

void setup() {
  lcd.begin(16,2);
  //============================================  mantaining switch  and  2input High output High====================================
   pinMode(buttonA, INPUT);
   pinMode(buttonB, INPUT);
   pinMode(buttonC,INPUT);
   
   pinMode(pump, OUTPUT); 
//============================================== H bridge and  valve ==================================================================                         
   pinMode(relayA,OUTPUT);
   pinMode(relayB, OUTPUT);
   pinMode(valve,OUTPUT);  

}
//////////

void loop() {
//============================================  mantaining switch    ====================================  
val = digitalRead(buttonA);

if ((val == HIGH)&&(old_val ==LOW)) {
 
  stateA = 1 - stateA;                           // invert ledA state
  delay(10);
}
 old_val = val; 
lcd.setCursor(0,1); 
//lcd.noDisplay(); 
  if (stateA == 1) {
lcd.display();
  lcd.clear();    
digitalWrite(pump, HIGH);        // turn  pump  ON  and    stay's on 
lcd.setCursor(0,0);
lcd.print("start");
delay(50);
  }


//=========================================== 2input High output High ===================================== 
stateB = digitalRead(buttonB);
 stateC= digitalRead(buttonC);
if (stateB== HIGH  ){                            // buttonC state is high                       
 lcd.clear() ;
 lcd.display();
 
 lcd.print("water full");
 delay(500);
 stateA = LOW;                                  
  digitalWrite(pump,LOW);}               // pump off
  
 if(stateC==HIGH){
lcd.setCursor(0,1);
lcd.display();
lcd.print("door close");}
else{
lcd.setCursor(0,1);
lcd.display();
lcd.print("door open");
}
    if(runprogtwotime<1){//outernested if
  while (stateB == HIGH && stateC == HIGH) {        // when  buttonB state and buttonC state High   
        
  
                    
   
lcd.clear();
lcd.print("washing");
    
                     
  


//=========================================== H bridge =======================================================                     
  
 if (timer < maxnum){
  for(count=0; count<2; count++)
    {
     // lcd.print(count);
    digitalWrite(relayA, HIGH);   
   
    delay(6000); 
     digitalWrite (relayB,HIGH); 
    
    
    delay(4000);
    digitalWrite(relayA,LOW);
    delay(6000);
    digitalWrite(relayB,LOW);
    delay(4000);
   
   
  
   // count++; 
  




}//inside if
 }
////////////////////////////////////////
 if(justonce==0){
  digitalWrite(valve,HIGH);
  lcd.clear();
  lcd.print("drain");
  delay(3000);
  digitalWrite(valve,LOW);
  lcd.clear();
  
  lcd.print("finish");
  delay(500);
  justonce++;
  runprogtwotime++;
 break; 
}
//////////////////////////////////
}//nested if
   }//outernested if
}

_3rd_step_to_continue.ino (3.9 KB)

what am I doing wrong?

Apart from posting the same question three times?

Take the text in your original post and write each step as a different paragraph.

Then follow through the steps with a pencil and paper. Modify the steps until they make sense.

You should be able to identify what needs to be done by your program. Then write your program to follow the steps.

...R

Get rid of all the delays. Whilst the Arduino is doing the delay(), it can't do anything else, like read your switches.
Have a look at "blink without delay" here:http://arduino.cc/en/Tutorial/BlinkWithoutDelay

Even though LCD display flickers, it seems like it does work apart from displaying "opene".is there anyway I could break out from while loop or if condition as it counts ? Anyway,I will try the link.thanks for the help.