Interrupt refreshing help

Hey guys,

I'm working on a project that prints data to a 2.8" LCD screen and I am having some issues figuring out how to have the data refresh constantly (aka live data) and when I touch a different part of the screen I want it to interrupt the refreshing so it will refresh different data after the new screen has been drawn

Here is the pseudo code of what I have:

check for what page is being pressed
go to page being pressed

if already on that page
run refresh method
else
clear old page
draw new page
write data to screen

if pressed for a different tab
clear screen
draw that page
write data to screen

My problem is that it's cycling through refreshing the page so fast that it's not catching when i'm pressing a different tab. I was thinking something like having it record current time, if at least 5 seconds haven't passed then don't refresh, but I would like it to refresh as fast as possible.

Would this work?

while not being pressed
refresh
else
go to page being pressed

Sorry I'm new to designing something so complex since I've only been programming on an arduino for a few months or so.

Thanks guys.

You want us to debug pseudo code? Afraid not. Actual code please.

Read this before posting a programming question

Nick,

I'm not asking anyone to debug code. I'm asking the best way to approach my problem of hardware interrupts. I would like to learn how it works and I can debug the code myself.

You don't necessarily need interrupts. There isn't enough information to guide you really. One approach is to check for a press frequently (eg. every 10th of a second).

My problem is that it's cycling through refreshing the page so fast that it's not catching when i'm pressing a different tab.

I don't really understand that bit. You mean "so slow" that it's not catching presses?

You could conceivably have an interrupt set a flag, and then test that flag once the screen is refreshed.

Sorry for being confusing, I'm not sure exactly what I want so I don't know how to ask. Here is a good way of explaining it. I followed your link and found this:
" For example, if you are cooking dinner you may put the potatoes on to cook for 20 minutes. Rather than staring at the clock for 20 minutes you might set a timer, and then go watch TV. When the timer rings you "interrupt" your TV viewing to do something with the potatoes."

This is exactly what I want to do.

I want to keep refreshing the screen until it senses another press on the screen and does what that press asks.

Here is my code that is relevant, it's not well commented as of right now, I started this project at 5:00pm yesterday and now it's 1:20am.

void loop()
{
      
  digitalWrite(13, HIGH);
  Point p = ts.getPoint();
  digitalWrite(13, LOW);

  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) 
  {
     
      p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
      p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);

      if (p.x > 270) {        // the top bar is being touched
            
         if (p.y > 0 && p.y < 60) {    // the first tab on the top bar is being pushed
            if (page != 1){
              tempscr();               //load the temperature screen
              page=1;
            }
         } 
         else if (p.y > 60 && p.y < 120) { // the second tab on the top bar is being pushed
             if (page != 2){
              ampscr();                    // load the amperage screen
              page=2;
            }
           }
         else if (p.y > 120 && p.y < 180) {  // the second tab on the top bar is being pushed
             if (page != 3){
              physcr();                      // load the physical screen
              page=3;
            }
         }
         else if (p.y > 180 && p.y < 240) {  // the second tab on the top bar is being pushed
            if (page != 4){
              prefscr();                     // load the preferences screen
              page=4;
            }
         }
      }
  }
  
      // REFRESH
      if (page == 1)      // if the current page is the temp page
      {  
        clearcenter();    // clear the area where the old data is
        retemp();         // print the new data
      }
      else if (page == 2)
      {
        reamps();
        clearcenter();
      }
      else if (page == 3)
      {
        clearcenter();
        rephys();
      }
      else if (page == 4)
      {
        clearcenter();
        repref();
      }
      
}

That is what I currently have. It refreshes very quickly (I would say around 1-1.5 times a second) and when I press to go to another tab it just keeps refreshing unless I rapidly press another tab and catch it between refreshes.

Without seeing your other functions it is hard to advise, but the good news is, you can do what you want. It might take a bit of restructuring, but the basic concept is well within the capabilities of the device.

Maybe you just need to slow down the sampling a bit, perhaps with a delay(50) (aargh :astonished: ) at the end of the loop() function.

      if (page == 1)      // if the current page is the temp page
      {  
        clearcenter();    // clear the area where the old data is
        retemp();         // print the new data
      }
      else if (page == 2)
      {
        reamps();
        clearcenter();
      }
      else if (page == 3)
      {
        clearcenter();
        rephys();
      }
      else if (page == 4)
      {
        clearcenter();
        repref();
      }

I like consistency. This is not.

I think you should insert "page change" detection. Like, currPage, prevPage. If currPage != prevPage then clear and display data, else don't touch the display.
This should make the screen refresh only when needed, instead of doing it at every cycle.

HTH

PaulS:
I like consistency. This is not.

Sorry there was a typo there, I'm going through my code today to try and comment everything and fix stupid errors, I'll post all my code after.

tuxduino:
I think you should insert "page change" detection. Like, currPage, prevPage. If currPage != prevPage then clear and display data, else don't touch the display.
This should make the screen refresh only when needed, instead of doing it at every cycle.

HTH

I will be receiving data that changes on each page that's why I need the page to refresh so often.

Like I told PaulS, I'm going to clean up my code and post it later today. Thanks for all the help guys/gals.

I will be receiving data that changes on each page that's why I need the page to refresh so often.

Ok, so in theory you need to refresh the page either if there was a page change request or new data has arrived. If data comes in "fast", then it's simpler to always update the page, like you said.