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
%
button.resetCount();
count
will be 3, then 4, 5, etc. But constrain will keepcount1
stuck at 2. You could usebutton.resetCount();
when you printc
to start over. Or usecount1 = count % 3
like jsotola suggested.