Hi! I´m new at arduino coding so i´m having some trouble! I want to make a quiz game with only 3 giant pressure buttons . The problem i´m having is when i press the button the led turns on , but i want that when i press the button , the led stays on until i press the "reset" button...
I just have this code:
int led = 8;
int botao = 7;
void setup()
{
pinMode(led, OUTPUT);
pinMode(botao, INPUT);
}
void loop()
{
if (digitalRead(botao) == HIGH)
{
digitalWrite(led, LOW);
}
if (digitalRead(botao) == LOW)
{
digitalWrite(led, LOW);
}
else
{
digitalWrite(led, HIGH);
}
}
Your code says if the button is High switch the LED off and if the button is Low switch the LED off or if not switch the LED on. Does that make sense to you?
And you only have one button not 3 so there's no reset button. You need to make a little bit more effort than that.
if (digitalRead(botao) == LOW)
{
digitalWrite(led, HIGH);
And yes i only have one button because first i want to test only one and then is more easy to finish the entire code.
But to make the led always on when the button is pressed what i need to make?
Thank you.
Thank you Wawa for offering me that code.. I resetted the arduino and then i send the code that you gave me ... it worked but instead of the led turn on just when i press it stayed on even when i didnt press.. it just stayed on...
I´ll attach a image of my circuit.
Can you help me modifying the code you gived me?
const byte botao1 = 5; // button 1 connected to pin 5 and ground
Didn't say anything about using a resistor, or 5volt for the button.
The code I wrote uses the internal (inside the chip) pull up resistors.
Remove the 10k resistor, and connect the button(s) between pin and ground.
Leo..