Req: Display two pages of data alternately using U8glib

Hi

I need to use U8glib to display the output of a routine which is controlled by a loop variable ‘param’.
‘param’ cycles from 0 to 7 and determines the various picture elements (e.g. bitmaps) to be displayed.
When param = 2, I want to display the first page of data; then pause for 1 sec.
When param = 7, I want to display the second page of data, then pause for 1 sec.
Then continue to loop endlessly.

Despite following the tutorials and reading the forums, I’ve been unable to find a construct based around U8glib’s ‘draw’ loop which will enable me to display data in this way.

As required by U8glib, my original routine was in a ‘for’ loop controlled by loop variable ‘param’; so I’ve made the ‘for’ loop into a function ‘void draw(int param)’, which is called from the ‘draw’ loop within the main loop; and am cycling the value of ‘param’ from within the ‘draw’ loop.

The code below will display the first page correctly if the second ‘for’ loop is commented out; otherwise it displays both the first and second pages simultaneously (i.e. superimposed/overlapping).

However, try as I might, I can’t find a way to show the two pages alternately.

I’d be very grateful if you could show me how to construct my ‘draw’ loop to achieve the above effect.

Many thanks in anticipation

Dave

void loop(void) 
{ 
  // picture loop 

  u8g.firstPage();   
  do {
    for(int param = 0;param<3;param++)//  draw all elements for first page:
    {  
      draw(param);
    }
    if (param == 2) // when all elements for first page are drawn, pause to display for 1 sec
    {
      delay(1000);
    }

    for(int param = 3;param<8;param++) //  draw all elements for second page:
    {  
      draw(param);
    }
    if (param == 7) // when all elements for second page are drawn, pause to display for 1 sec
    {
      delay(1000);
    }


  } 
  while( u8g.nextPage() );//end of picture loop 

} // end of void loop

Hi Dave

First you need to group your procedures according to what needs to be displayed on one page. For the first page, this seems to be: draw(0); draw(1); draw(2);

I personally suggest to introduce a procedure for this (to simplify the code):

void draw_page_1(void)
{
draw(0);
draw(1);
draw(2);
}

Of course you could still use the param loop. Same should be done for draw_page_2()

Second, the delay and the different pages must be selected/switched outside the picture loop. This might look like this:

  u8g.firstPage();   
  do {
   draw_page_1();
  } 
  while( u8g.nextPage() );//end of picture loop 
  delay(1000);
  u8g.firstPage();   
  do {
   draw_page_2();
  } 
  while( u8g.nextPage() );//end of picture loop

Oliver

Hi Oli

Thank you so much for your quick and helpful reply, and clear explanation.

My code is working fine now & I'm delighted!

Also I wanted to say a big thank you for all your work on developing u8glib, and for making it freely available.

Much appreciated.

Best wishes

Dave

Hi Dave67, i want to do something like you, can you help me with your code or something.

Thanks.