if statement

Hi to all
I am a beginner in arduino

i made these codes

int start = 0;
int microvawe = 0;
int buttonlast = 0;
int counter = 0;
int buttonlast2 = 0;
int count = 0;
int control=0;
int control2=0;
int counter1=0;

void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(3, INPUT);
pinMode(11, OUTPUT);
pinMode(10,OUTPUT);
pinMode(4, INPUT);

}

void loop()
{
start= digitalRead(2);
microvawe=digitalRead(3);
control=digitalRead(4);

if (start!=buttonlast)
{
if (start==HIGH)
{
count++;
Serial.println("on");
Serial.print("1 ");
Serial.println(buttonlast);}}
if (count==1)
{
if (microvawe!=buttonlast2)
{
if (microvawe==HIGH)
{
counter++;
Serial.println("on");
Serial.print("2 ");
Serial.println(buttonlast2);}}}
if (count==1)
{
if (control!=control2)
{
if (control==HIGH)
{ counter1++;
Serial.println("on");
Serial.print("control ");
Serial.println(buttonlast);}}
if (counter1==1)
{
digitalWrite(10,HIGH);
delay(600);
digitalWrite(10,LOW);
delay(600);
}
if (counter1==2)
{
digitalWrite(10,HIGH);
delay(700);
digitalWrite(10,LOW);
delay(700);
}
if (counter1==3)
{
digitalWrite(10,HIGH);
delay(800);
digitalWrite(10,LOW);
delay(800);
}
if (counter1==4)
{
digitalWrite(10,HIGH);
delay(900);
digitalWrite(10,LOW);
delay(900);
}
if (counter1==5)
{
digitalWrite(10,HIGH);
delay(1000);
digitalWrite(10,LOW);
delay(1000);
}

}

if (counter==1)
{
digitalWrite(13,HIGH);
delay(100);
digitalWrite(13,LOW);
delay(100);
}
if (counter==2)
{
digitalWrite(13,HIGH);
delay(200);
digitalWrite(13,LOW);
delay(200);
}
if (counter==3)
{
digitalWrite(13,HIGH);
delay(300);
digitalWrite(13,LOW);
delay(300);
}
if (counter==4)
{
digitalWrite(13,HIGH);
delay(400);
digitalWrite(13,LOW);
delay(400);
}
if (counter==5)
{
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);
}
if (counter==6)
{
digitalWrite(13,HIGH);
delay(600);
digitalWrite(13,LOW);
delay(600);
}
if (counter==7)
{
digitalWrite(13,HIGH);
delay(700);
digitalWrite(13,LOW);
delay(700);

}

else if (count==2){
digitalWrite(11,HIGH);
delay(700);
digitalWrite(11,LOW);
delay(700);}

delay(200);

start=buttonlast;
microvawe=buttonlast2;
control=control2;
}

when you first press 1-button and then 2-button and and two leds blink
but when i press 1- button again , led of 2- button must turn off
how to do that
i am not good at english
sorry for my english

.png

This would appear to be a school exercise.
You must first formulate a clear description of the problem.

Let us say the four leds in your picture are numbered L1, L2, L3 and L4 starting from the left.
Let us say the three buttons are numbered B1, B2 and B3 starting from the left.

Is this correct:
If button B1 is pressed, then if sometime after, button B2 is pressed, Leds L1 and L2 should
blink for x milliseconds.
If sometime after L1 and L2 blink, button B1 is pressed, something should happen ?

yes you are right .thank you
something should happen=
if B1 is pressed , L2 should stop blinking ,

I got your PM but in principle this should be dealt with in the forum.

OK so:

If B1 is pressed, then if sometime after, button B2 is pressed, Leds L1 and L2 should
blink continuously (duty cycle X% ).

If sometime after L1 and L2 begin to blink, and button B1 is pressed, L2 stops blinking but L1 continues to blink. Is that correct ?

From your picture, it would appear that

L1 - pin13 -
L2 - pin12 -
L3 - pin11 -
L4 - pin10 -

B1 - pin4 -
B2 - pin3 -
B3 - pin2 -

It is not completely clear how all this all relates to the sketch you posted. What is the purpose of the variable counter ?

I have a microvawe oven to repair .
my microwave control block is bot working, so i am going to make a circuit in arduino
it has fuctions:
timer for microvawe
and power control
grill heater
so i am making this code

my aim is :
when you press b1 , the side of microwave works and b2 controls timer to 30second,2minutes, 5minutes, ......
b3 controls power control of the magnetron in microwave
if you press b1 again , grill heater of the microvawe works and b2 and b3 functions stop working .
thank you in advance
sorry for my poor english

OK. Let us just be clear about this. You are trying to model the function of a microwave oven using LEDs and buttons. You understand that for a real microwave oven, there are other safety considerations like, for example. a door interlock to prevent the magnetron operating when the door is open etc. and there other things like the turntable motor to look at ?

B1 sets the microwave in some sort of programming mode. B2 can cycle through 30second,2minutes, 5minutes cooking times. When the user has chosen a cooking time with B2, then pressing B3 starts the microwave cooking until the timer expires.

A further press of B1 stops any microwave cooking and switches the grill function on.

What happens if a user does not want to use the grill function but the next user want to start again with normal microwave oven functions. Will this force the grill on immediately for the second user ?
Also, how is the grill function switched off ?

the grill function is stopped by pressing reset button :slight_smile:
i press the reset button untill i learn a function that starts again

microvawe has mechanical switches to protect from open door.

you said:

A further press of B1 stops any microwave cooking and switches the grill function on.

how to do this

OK. So you have also a reset button which is not shown in your schematic.

Anyway, to switch between normal microwave oven functions and grill functions, you need a state variable which has say a value of 1 for microwave functions and an value of 2 for grill functions.

If the state variable (lets call it currentFunction) has a value of 1 and the button 1 is once again pressed, then currentFunction gets a value of 2 to indicate that the grill should be switched on.

How with your LEDs are you going to indicate all these states:

waiting for user to enter cooking time
setting cooking time.
end of cooking time.
Grill switched on.
Microwave oven ready for next user

Ok . thank you . i understand you .
i will try to rewrite the codes tomorrow and.send here
it is 22:40 now
good night
thank you very much

i though how to make variable 1 and variable 2 for microvawe and grill functions but couldnt
how to make it .please help me

Start by saying what function each of these LEDs has (taken from your schematic):

Leds:
L1 - pin13 -
L2 - pin12 -
L3 - pin11 -
L4 - pin10 -

Buttons: taken from your description in post #4
B1 - pin4 -  the "side" of microwave ?  A second press cancels the timer, stops the magnetron and switches the grill on.
B2 - pin3 -  timer. Cycles through 30second,2minutes, 5minutes 
B3 - pin2 -  switches magnetron in microwave on

What do you mean by the "side of the microwave" (button B1) ?
Is there is no way of switching the grill off, except by resetting the Arduino ?

After it is clear what should happen then we can try to work out how the code should be structured.