How to get an lcd screen to print different things depending on how often a button is pressed?

I have been trying to get an lcd screen to print a different phrase every time the button is pressed and released however I cant get any code to work this is the wiring I have but as no code has even remotely worked I haven't attached this.

Welcome to the forum

Take a look at the StateChangeDetection example in the IDE. It demonstrates how to count keypresses. Given the number of keypresses you can use it to select the phrase to be displayed from an array of such phrases

Your button is wired incorrectly. It looks like it is going from arduino pin to button to +5V. That means when the button is pressed, it reads HIGH. Unfortunately, when the button is not pressed, the pin is floating (e.g. not connected to anything) so it will read a random value, HIGH or LOW.

Connect one corner of the button to ground. Connect the opposite corner (diagonally) to the arduino pin and declare the pin as pinMode(buttonPin, INPUT_PULLUP)

This makes the button HIGH when not pressed and LOW when pressed. By using the diagonal corners of a 4 leg button, it does not matter if you rotate the button 90 degrees accidentally when putting it into the breadboard. It will still work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.