surfer_crx:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
I will also include a debounce as there is likely to be some noise where this will be used on completion. Would I be right in thinking that a switch statement is the one to use to get the screen to display the information from different sensors?
Hi,
Yes you could use a switch statement, it certainly will keep your sketch modular and easy to read.
switch (buttonPushCounter) {
case 0:
//display default screen
break;
case 1:
//display screen for if the button has been pressed once
break;
case 1:
//display screen for if the button has been pressed twice
break;
default: // if it's not one of the specific values you have screens for, reset to default
buttonPushCounter = 0;
// and then probably you'd need to do something to tell it to re-test
// the value of buttonPushCounter so it refreshes the display, or just
// let it catch up in the next iteration of loop() if there's no lengthy
// delay() in the loop.
break;
}
If you are planning on extending the project in future you just insert an additional 'known' state for buttonPushCounter to test for and it won't upset any of your other code.
Note that unless you reset the buttonPushCounter value to zero each time it runs through this switch statement, it's not really storing the number of buttons clicks in a row, but the menu state, so it will allow the user to navigate a screen at a time and then loop back to the first one. Not sure if that's what you're after...
Cheers !
Geoff