slow down if statement

im using if statement to check if two buttons are pressed

if ((digitalRead(point1)==HIGH) && (digitalRead(ground1)==HIGH))

adruino is checking it so fast , i want a little time, a second for example for the two buttons to be pressed.. what should i do ?

Wait for 1000 milliseconds, and then check again.

That will be true if both pins are held HIGH. Is that not working for you? Holding the buttons doesn't work?

If you want to press and release a button and then press another within one second, that is easy to program with a few variables to record which button was pushed and when. The code is actually fairly complex: this is much more than a 1 line program.

the question is what i should i do? im just a beginner and this is just the second trial of my project,

hossamsh: the question is what i should i do?

Give us a better description of what you want.

i need the code or the function that can check these two buttons are pressed.. not with if statement cause its checking it immediately , i need a time between the presses of the two buttons , not a specific period , just enough time for a human to press both buttons

Check when the first switch gets closed. Note the time. Check the time e the second switch gets closed. Note the time. Subtract the first time from the second time.

hossamsh: i need the code or the function that can check these two buttons are pressed.. not with if statement cause its checking it immediately , i need a time between the presses of the two buttons , not a specific period , just enough time for a human to press both buttons

Will the first button be held down? OR is it press and release and then press the second button? How much time do you want? What should happen if it takes too long? How long is too long?

Give a full description. Don't be afraid to be verbose. Most of us have excellent reading skills.

well.. when the first button is pressed there is a red led to light up.. but if the button is pressed with the other (both are pressed) a yellow led should light up instead of the red.. the problem is the time between the presses should be made by a human , (i could not press both exactly to get the yellow led, when i try to press both i always get the red led ) i need the solution for this i used that if statement "if ((digitalRead(point1)==HIGH) && (digitalRead(ground1)==HIGH))" and its not working for my purpose i need to press both by my hands and get the yellow led

OK, now show your full code instead of just one line. I knew there was more to this than you were letting on.

int point1 =2; int red =3; int yellow1 =4; int ground1 =10;

void setup() { pinMode(point1 , INPUT); pinMode(ground1 , INPUT);

}

void loop () { if ((digitalRead(point1)==HIGH) && (digitalRead(ground1)==LOW) ) { digitalWrite(red,HIGH); delay(2500); digitalWrite(red,LOW); }

if ((digitalRead(point1)==HIGH) && (digitalRead(ground1)==HIGH)) { digitalWrite(yellow1,HIGH); delay(1500); digitalWrite(yellow1,LOW); } }

OK, next time use code tags. My fault for not saying that before. I had assumed you had read this. How To Use This Forum. It's at the top of every section. Seems a bit silly to me to skip reading that and go straight to posting questions. But I guess folks these days just don't like reading the directions on things.

You don't have either of the pins your leds are on set as outputs. You should do that. Don't put multiple lines of code on one line. Put a line break between. They don't cost money. I'm talking about the delay calls on the same line with a digitalWrite.

If you hold both buttons for more than 2 and a half seconds, the red should turn off and the yellow turn on. The delay there stops anything else from happening for at least that long.

Rather than read the inputs and then react to them with

if ((digitalRead(point1)==HIGH) && (digitalRead(ground1)==LOW) ) {

you should read them and save the values to two variables. Then you can test each variable separately. It also makes debugging easier because you can print the values to check that you are getting what you think you should be getting.

For example

point1State = digitalRead(point1);
ground1State = digitalRead(ground1);

I have the feeling that you still need to define your requirement more carefully - particularly the situations that are not acceptable. Remember a computer is very very stupid and can only do what you tell it. It cannot know what you would like it to do.

...R