Hi Guys, I try to find something for my idea but not lucky yet.
I want 3 push button, for one LED. So you have to hit every push button before LED goes on.
One button more for LED goes off.
is it simple? i have no idea how to approach it.
Think of the logic behind what you want to do. You have three things that can only be used once, and when they are all gone, something happens.
Like you had 3 coins in a bag and you take out one at a time. When the bag is empty, you do something. Now when you attempt to remove a coin from the empty bag, then you do a different thing.
So, in programming terms. We have 3 switch identifiers in a container (let's say it's an array). When a switch is pressed, we set its identifier in the array to -1. When the array has only -1's in it, then you turn on the LED. Now, when a switch is pressed, you see that the container is full of -1's, so you turn off the LED.
Turning that logic into code is left as an exercise for the student.
want to every button remeber his status. So if button 2 is hit and it gets hit again i want to do nothing. When every button is pressed then the LED turn on. And if i hit 4 times button 2, dont care.
You have the idea
You should look at the code examples in the IDE, specifically the Button and Blink examples.
Here is a code snippit to get you started
button1 = digitalRead(button1_Pin);
if (button1 == LOW) // It is pressed
{
button1_pressed = true;
}
if (button1_pressed == true) && (button2_pressed == true) && (button3_pressed == true)
{
// Light the LED
}
Build failed!
In file included from sketch.ino.cpp:1:0:
sketch.ino: In function 'void setup()':
/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h:41:14: error: expected ')' before numeric constant #define LOW 0x0
^
sketch.ino:17:26: note: in expansion of macro 'LOW'
digitalWrite(LED_PIN LOW);
^~~
sketch.ino:17:29: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'
digitalWrite(LED_PIN LOW);
^
In file included from sketch.ino.cpp:1:0:
/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h:135:6: note: declared here
void digitalWrite(uint8_t pin, uint8_t val);
^~~~~~~~~~~~