Go Down

Topic: Updating data displayed only if it changes? (Read 1 time) previous topic - next topic

jerseyguy1996

I've always had this question in my mind.  When sending out data to be displayed on an LCD display (or in my case an OLED display) I have always wondered if there is anything wrong with hammering the registers repeatedly with the same data over and over again.  Example:

Code: [Select]
void loop
{
  if(digitalRead(button))
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Not Pressed");
    display.display();
  }
  else
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Pressed");
    display.display();
  }
}


I hate that I am sending the same thing to the display over and over again when really I just need to send it once when the button is pressed and once when the button is released.  Because of this I end up doing something that feels convoluted like:

Code: [Select]
boolean last_button_position = false;
void loop
{
  if(digitalRead(button) && !last_button_position)
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Not Pressed");
    display.display();
    last_button_position = true;
  }
 
  if(!digitalRead(button) && last_button_position)
  {
    display.clearDisplay();
    display.setCursor(0,0);
    display.print("Pressed");
    display.display();
    last_button_position = false;
  }
}


Now given my propensity to always find the absolute worst way to do something programmatically, I can only assume that this is possibly the worst way to do this.  What do you guys do to avoid constantly sending the same data to be displayed over and over again?

Arduino Uno;
Mega328

PaulS

Quote
I have always wondered if there is anything wrong with hammering the registers repeatedly with the same data over and over again.

They don't know. They don't care.

The problem comes when the clearing and redisplay of data takes a while. If that time doesn't matter (the display doesn't flicker; the code doesn't block), then it doesn't matter. If it does, then clearing the screen and re-displaying the data only when there is a change can improve the performance of the overall program.

UKHeliBob

Changing only those parts of the display that have actually changed, rather than clearing the whole display can make a difference too.  The code would be neater and be easier to maintain if the routine to display data were made into a function with the parameters being the data to display and the coordinates where it should be displayed.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

jerseyguy1996

So basically it doesn't matter unless I need my program to run faster.  It does get a bit behind when reading serial information coming in so I guess I will put the test in there to see if I need to update the display or not.
Arduino Uno;
Mega328

Runaway Pancake

Isn't it a matter of
Code: [Select]

if (new_data != old_data)
{
  // print new_data
  // old_data = new_data
}

? ? ?
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

PaulS

Quote
Isn't it a matter of

They type of new_data and old_data determine whether the != operator is an appropriate one, but that's the general idea.

jerseyguy1996


Isn't it a matter of
Code: [Select]

if (new_data != old_data)
{
  // print new_data
  // old_data = new_data
}

? ? ?


That's basically what my second code example above does.  I ended up just making a boolean that keeps track of which of two states the system can be in.  If the state is 0 and the boolean shows that we are displaying state as 1 then we update the display and vice versa.  Seems to work fine for me.
Arduino Uno;
Mega328

freddie43

I wondered if anyone had got any further with this topic?

Here in UK we have just quit Daylight Saving time and I realised my Arduino LCD clock was an hour out for several months of the year.

I sorted that thanks to https://github.com/JChristensen/Timezone.

But now my display has quite a flicker to it, which is
a) Distracting
b) I wonder about the effect on the display?

I attach an image as it wouldn't paste where I wanted it to.

Basically the display is:

Tue 1 Nov 2016
08:49:48 AM GMT

(GMT is Greenwich Mean Time - a hark back to the UK's Imperial Days!)

What would be nice would be if only the changes get output
- that is easy with the first line as it only changes once a day
- but rather more complex with the second line, where it would be good to only output the one or two (or more) digits which change

Maybe this is only an intellectual exercise but it has certainly got my brain ticking, and I wondered if anyone had sorted it (or similar)? - I have Googled the Forum and the web
Greybeard programmer since the dawn of time.
Much enjoying the challenges of Arduino.

PaulS

Are we supposed to see the flickering in the snapshot? I didn't. Looked nice and steady to me.

Writing to the display only when there is new data to write is trivial. All you need to do is keep track of what you wrote last time.

Your code seems to have gone AWOL.

odometer

#9
Nov 01, 2016, 10:38 am Last Edit: Nov 01, 2016, 10:38 am by odometer
I wondered if anyone had got any further with this topic?

Here in UK we have just quit Daylight Saving time and I realised my Arduino LCD clock was an hour out for several months of the year.

I sorted that thanks to https://github.com/JChristensen/Timezone.

But now my display has quite a flicker to it, which is
a) Distracting
b) I wonder about the effect on the display?
We cannot locate the problem unless you post your code. And it will save us time if you begin by posting the entire sketch, not just the part you think is the problem.


By the way, I have made a clock using a similar display.
Here is the thread on it: http://forum.arduino.cc/index.php?topic=408565.msg2823857#msg2823857
I have not noticed any flicker on my clock's display, but then again, I did not include the Timezone or any similar library.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy