2

my results are here.
0 press--"a"
1st press--"b"
2nd press--"c"
3rd press-- still showing "c"
When button pressed 3rd time, It must be repeated to show "a" again. How can I repeat above 3 results to LCD?

#include <LiquidCrystal.h> 
#include <ezButton.h> 
ezButton button(7); 
int count; 
int count1; 
const float rs = 1, en = 2, d4 = 3, d5 = 4, d6 = 5, d7 = 6; 
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 
void setup() { 
 button.setDebounceTime(50); // set debounce time to 50 milliseconds 
 button.setCountMode(COUNT_FALLING); 
 lcd.begin(16, 1); 
} 
void loop() { 
 int count = button.getCount(); 
 button.loop(); 
 count1 = constrain(count, 0, 2); 
 if(count1 == 0){ 
 lcd.print("a"); 
 } 
 if(count1 == 1){ 
 lcd.print("b"); 
 } 
 if(count1 == 2){ 
 lcd.print("c"); 
 } 
 delay(500); 
 lcd.clear(); 
} 
timemage
5,6391 gold badge14 silver badges25 bronze badges
asked Apr 30, 2023 at 13:27
3
  • investigate the remainder operator % Commented Apr 30, 2023 at 15:19
  • 1
    use button.resetCount(); Commented Apr 30, 2023 at 16:34
  • The ezButton counter will keep counting up every time you release the button. count will be 3, then 4, 5, etc. But constrain will keep count1 stuck at 2. You could use button.resetCount(); when you print c to start over. Or use count1 = count % 3 like jsotola suggested. Commented Apr 30, 2023 at 20:04

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.