Hi everyone, I have a big prob dat my brain does not want to understand
Here I have 2 buttons, b1 and b2, with b2 I want to switch my other led, lr, on. With b2 I want to turn lr off. I made the electronics, everything is fine, I tested it with only 5v and GND and everything was mervellous.
Here is my code :
const int b1 = 2;
const int b2 = 3;
const int lr = 10;
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
OK thank you for your asnwers,
Here is my code, I just want to be able to stop and light a led with two buttons,
Actually, when I launch the led is lightning and only b2 react by turning off the led when i press it
const int b1 = 2;
const int b2 = 3;
const int lv = 8;
void setup() {
 // put your setup code here, to run once:
pinMode(b1, INPUT);
pinMode(b2, INPUT);Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
pinMode(lv, OUTPUT);
digitalWrite(lv, HIGH);
}
void loop() {
int etatb1 = digitalRead(b1);
int etatb2 = digitalRead(b2);
int i;
if(etatb2 == LOW){
i = 1;
}
if(etatb1 == LOW){
i = 2;
}
if(i == 1){
digitalWrite(lv, LOW);
}
if(i == 2){
digitalWrite(lv, HIGH);
}
}
Get rid of i. Set the state of the LED based on the state of the switches.
You failed to post a schematic. I have no clue what those links are, so I'm not about to click one. I'm real leary of anything with mail and google in the name.
I'm going to assume that your switches are not wired correctly until you prove that they are.
The simplest way to wire a switch is to connect one leg to ground and connect the other leg to a digital pin, and set the pinMode() for that pin to INPUT_PULLUP. Why didn't you wire your switches that way?
I did it and this is the reason why I said that electronic was fine. My only problem is with the code I want to know is why my code isn't right.
Just what I want to do with my code:
When I push the second button (b2) I want my led to be turned on. And when I push the other button(b1) I want my led to be turned off. That's all.
But thx for taking the time to respond to me.
const int b = 2;
const int b2 = 3;
const int led = 8;
int etatb;
int etatb2;
void setup() {
 // put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(b, INPUT);
digitalWrite(led, HIGH);
etatb = HIGH;
etatb2 = HIGH;
}
void loop() {
 // put your main code here, to run repeatedly:
etatb = digitalRead(b);
etatb2 = digitalRead(b2);
if(etatb2 == LOW){
digitalWrite(led, LOW);}
if(etatb == LOW){
 digitalWrite(led, HIGH);}
}
I found,
my switches were perfectly wired, thank you PaulS!