I need coding help on this. I have 6 keys up , down , right ,left, select, NONE.
Here i need small code which return the status of key being pressed and stay remain in same state.
Assume i pressed left key , it has to stay in left key stage unless another key pressed.
if none key is pressed means no key pressed it should stay in previous key being pressed
void lcd_call()
{
int button=0; // Ok
int prev_button=0; // No, this will overwrite prev_button and it will not remember what the button previously was. Take it out and make it global.
button = read_LCD_buttons(); // Ok
if (button!=btnNONE) // add spaces for clarity, what does btnNONE equal, -1, 0, '/0' ?
{
goto labe1; //NO!!! Labels are not needed, especially not for something as simple as this.
}else // separate them on new lines
{
prev_button= button; // When do you compare button to prev_button?
}
label:serial.println("hello"); // Again, don't use labels.
int prev_button=0; [b]// No, this will overwrite prev_button and it will not remember what the button previously was. Take it
int prev_button;//Is it correct
if (button!=btnNONE) [b]// add spaces for clarity, what does btnNONE equal, -1, 0, '/0' ? [/b]
btnNONE =5;
HazardsMind:
I understand what you want to do. But you need to follow the comments I gave you. Do you know what a global variable is, and why are you using labels?
Yes i know, global variable is a variable that is accessible in every scope. But i don't which variable made as global variable Here.
Have you checked other code i have written .The code 2 seem working fine if i can retrieve the previous state of button pressed.
Thanks for the code. I tested this . it doing same thing it stay in loop . it wait for key to press again to update the time and date
It should valid for the other key.
means to say if right key pressed it always show Display_angle();
but here it is coming back to digitalClockDisplay(); since no key has been pressed.
Ahh, I forgot that when no button is pressed, it outputs 5. So what you do is add “&& button != btnNONE” to “if(button != prev_button)” and it will work.
Why do you have all those read lcd button lines? They are not needed, all you need is the first one. That "glitter" is what happens when you rapidly clear the screen and show a new value over and over again.
Yes, of course.
Only write to the display if the values have changed since last time.
There's a clue in the title of this thread.
Ya I have Written code written for the same problem, If any key pressed store status and display relevant display .. Is there any wrong with my code syntax so it producing glitter
Syntax is not going to cure "glitter" - if syntax is wrong, the compiler will tell you.
Not writing to the display when you don't need to is going to cure "glitter".