Im sorry, I see this more as a general problem, than one special code...But let me give an example so Im clearer about what I want.
sketch of code:
#include
initialize display and sensor communication;
define global variables;
// define functions
checkbuttonstatus; //checks which button was pressed or none
readtemperature//reads temperature from sensor
renewdata // takes temperature, compares it to the lowest and highest temperature it has stored, if it is higher rewrites highest, if its lower rewrites lowest
printmainmenu // prints on display current temperature, highest temp and lowest temperature
void setup() { }
void loop
{
boolean buttonnotpressed=1;
while(buttonnotpressed)
{
checkbuttonstatus; \if button was pressed buttonnotpressed becomes 0 and while loop stops, otherwise it is 1
readtemperature; \read sensor data
renewdata; \compare with stored data
printmainmenu;
delay(1000); }
//to get here somebody had to press a button
switch(buttonpressed) // we get different screens depending on which button was pressed
{
case button1: // show menu 1 for 2 seconds
case button2: //show menu 2 for 2 seconds
}
}
so I have actually two problems:
1st: when in the while(buttonnotpressed) loop, during 1s delay arduino ignores buttons input
2nd: when in the switch(buttonpressed) , during 2s delay arduino doesnt measure current temperature and doesnt store min and max temperature
First problem I could resolve by 1ms delay in while loop and counter to keep track how many times the loop went and then call readtemperature; renewdata; printmainmenu; only after 100loops went.
For the second problem I could write delay(1000); readtemperature; renewdata; delay(1000) instead of 2 second delay
But I find both of these solutions silly and adding lots of code. When in future I will add some submenus or want to prolong the display times, I find it very uncomfortable. Isnt there some nicer logical way to do this? Thanks