Hello, There !
Project Environment : Arduino Mega 2560, 10-bit ADC, Alphanumeric LCD
In one of the my project, i am trying to display the status of range of potentiometer only when the ADC data is stable (like the range for 10 bit ADC is 0 to 1023) so that i want to print if the range is between 0 to 200 want to display state-1, for 201 to 300 want to display state-2, for 301 to 400 want to display state-3 ! .
But in that case it shows the correct stable ADC value but shows state-2 every time for less than 1s and then update correct state. so i want hide " state-2" display before correct status.
repeated 3 times, where only one (hard-coded) digit is changing, have a first function return an int (or a uint8_t) from 0 to 3. Then, have a second function build up a buffer according to what the first function returns. Finally, have a third function actually print the buffer that function 2 has made. In this way, you can test each part individually and go on to the next part when the previous one is behaving.
You don't need case, nor even else if: a chain of successive ifs will do.
For instance:
#define FLOOR_3 400
#define FLOOR_2 300
#define FLOOR_1 200
uint8_t checkState (void)
{
uint8_t state = 0; // will be returned if every if fails
if (currentValue < FLOOR_3) state = 3;
if (currentValue < FLOOR_2) state = 2;
if (currentValue < FLOOR_1) state = 1;
return state;
}