I am doing a project in which I am trying to display some information on 16,2 LCD. I want to display some information on LCD when we press 2 buttons at the same time. It should not work if we only press one button..both should be pressed at the same time and the information should be displayed. So,what should I doooo? I need some help with the coding..
Hopefully you don't mean they will become pressed at exactly the same instant, since that's impossible.
But you could do something like the following, assuming the buttons have pullup resistors and are low when pressed:
if (digitalRead(button1)==LOW && digitalRead(button2)==LOW )
{
//do whatever
}
Welcome to the forum
Assuming INPUT_PULLUP on the pins
if (digitalRead(button1Pin) == LOW && digitalRead(button2Pin) == LOW)
{
//do something
}
What is meant by Low in this condition?? I didnt get it..and I am very new here started 5 days ago...
What is Input pullup now?? I am very new so i dont understand...hope you will help me
int buttonten = digitalRead(one);
int buttonten2 = digitalRead(zero);
if(buttonten == HIGH and buttonten2 == HIGH){
lcd.setCursor(0, 0);
lcd.clear();
lcd.print("Neon 10");
lcd.setCursor(0, 1);
lcd.print("Ne 010 010 010 ");
Low means the pin is grounded. You connect the button from the pin to ground (not to 5V as you might more readily think...) and put this in setup()"
pinMode(*button pin number*, INPUT_PULLUP);
Then the pin would read high until the button is pressed then it will be low.
I wanted somethig like this but it didnt work.... ![]()
With 5 days experience I would expect that you would know what LOW meant in a test statement. What have you been doing for 5 days ?
As to INPUT_PULLUP, it is a parameter used in setting the pinMode for an input pin (please don't tell me that you don't know what pinMode() means). INPUT_PULLUP activates the built in pullup resistor for the pin keeping it HIGH until the pin is taken LOW indicating that the button has been pressed. Keeping it in a known state at all times eliminates triggering the input due to it picking up random electrical noise
should i put this in void setup??
That (post #6) should be ok if you have the buttons connected to 5V but then you also need an external pulldown resistor from the pin to ground.
(There are, alas, no built in pull downs which you can turn on like the pullups.)
Yes
No.
The resistors are not connected to anything useful.
Connect the push buttons simply between input pin and ground. Do not have any external resistors. Enable the internal pull up resistors like you have been told to by others on this thread.
Tip always use two contacts only on the push button and use the pins only across the corners.
what should I do then?
It's way simpler to use the internal pullup rather than mess around with external resistors, but I suppose in a simulator it doesn't make a huge difference.
But if you do have those external resistors, your pinMode will only say INPUT not INPUT_PULLUP.
I think you should abandon your project for a while and just work through the basic tutorials. You do need some knowledge otherwise you are just asking someone to do it for you.
At least not on the mainsteam Arduinos but other boards do support INPUT_PULLDOWN
should i just leave it like that and then just change the coding???
-
If you have the button connected across the pin and 5V with external pulldowns, pinMode is INPUT and a pressed button is high
-
If you have the button connected across the pin and ground, there are no external resistorsd, pinMode is INPUT_PULLUP and a pressed button is low.
The latter is recommended practice.
