HELP: on and off of 1 led using two switch

good day everyone, can you please help me about on this problem, i do and research some related topic on this and i didnt make it i do only on off of 1 led using 1 pushbutton. can you please help me what im gonna code on coz im not good in programming.

i have 1 led and two button switch (pushbutton 1 and pushbutton 2). the flow of code is this.
when i "run/compile" the state of led is "off" and when i press whether pushbutton 1 or pushbutton 2 the led will on. and the when the led is on when i press whether pushbutton 1 or pushbutton 2 the led will go off

here is the schematic diagram that i see on net but i im not sure if it is the same schematic diagram that i will use too.

thanks in advance guys

as.PNG

Write the code which will turn one led on and off with one button in the manner you want. The StateChangeDetection example in the ide 02Digital examples section will be a good place to start.

When you get done, you will see that there are some conditional statments like
if (digitalRead(some button pin) == some value dependent upon your wiring){
//take some action
}

When you have the one button code you want, take a look at the boolean "logical or" operator

How to add the second button will be evident.

What I like to use in this case is this kind of flip-flop :

boolean b=0

void setup()
 {
 pinMode(3, INPUT);
 pinMode(5,INPUT);
 pinMode(8,OUTPUT);
 }

void loop()
 {
 if (digitalRead(3)||digitalRead(5)) b=1-b;
 digitalWrite(8,b);
 delay(250);
 }

Cheers

Pierre

That is not how a logic or operation works. You would use

if(digitalRead(3) == LOW || digitalRead(5) == LOw) // do stuff

Also you can not do b=1-b to a Boolean variable to do this use

b=~b;

Note that symbol is not a minus but a tilda.

Grumpy_Mike:
That is not how a logic or operation works. You would use

if(digitalRead(3) == LOW || digitalRead(5) == LOw) // do stuff

digitalRead is true or false, so you could use it directly.
if (digitalRead(3)==HIGH) is the same than if (digitalRead(3))

Also you can not do b=1-b to a Boolean variable to do this use

b=~b;

Note that symbol is not a minus but a tilda.

It nevertheless works. For boolean you could also use b=!b.

digitalRead is true or false, so you could use it directly.
if (digitalRead(3)==HIGH) is the same than if (digitalRead(3))

Do you actually think I don't know this?
I am explaining things for a beginner and it is my opinion that what I wrote is a lot clearer that what you wrote. Clarity is important when you are learning concepts for the first time. Once you have that under your belt you can get "clever" but beware creating elegance.

Grumpy_Mike:
Do you actually think I don't know this?
I am explaining things for a beginner and it is my opinion that what I wrote is a lot clearer that what you wrote. Clarity is important when you are learning concepts for the first time.

I'm sorry I didn't want to be unpleasant. I understand now what you meant.

Grumpy_Mike:

b=~b;

I made a test and ~ doesn't seem to work in this case, with b as a boolean.
If b=0 then ~b=1, but if b=1 then ~b=1.

According to the doc, ~b is similar to -b-1, so if b = 1 you will get -2, but as b is a single bit boolean, I suppose that -2 is casted as 1.

!b or 1-b work though.