How to create pages for OLED screen

Hello evrybody
I hope your are going well!

I would like to improve my code for my meteo stations.
My stations take serveral measures and for each measure, a fonction is called

get_temperature()
get_humidity()
get_pressure()
get_sun();
get_wind();
get_battery();
get_luminosity()
and more...

my OLED (128x64) can only show 5 lines, then I need to make pages.
The problem, some sensors can be actuve or not, then I can give an index for a sensor.
get_temperature() can be the fist function called, but if the temperature is inactive, get_humidity() is the first called function

here is an exemple of page1

temperature: 26°C
humidity: 44%
pressure:90
battery:4.1V

As you can see, there is text, number and number with comma for each line

The idea is at the end of each function I save the text/value into a array of a strcut


get_temperature()
{
  // Here is the code to get the value from the sensor
  
  // Print the value
  oled.print("Temperature: ");
  oled.print(tmp);
  oled.print("°C");
  oled.display();
  
  // Add here the code to save the text and the value into the first line of the page 1
}

I need to save the text and the value into a page at a line. Because, when my station sleep, I have a press button. When I press it, it wake up the sensors a show the page 1. When I press is again it showes the page 2, when I press it showes the page 3, and if there is no page 3, it show the page 1.

My problem is how to assign a measure form one of the function to a page and line free, dynamicly, keeping in mind that a sensor can be inactive. It meen, pressure, can be at line 3, or 1 or 4....

Do you see?

I started by writing a"draft" scruct (I have not tested it yet)

struct init_lignes { // for DS18B20 calibration
    char ligne1;
    int16_t value1;
    char ligne2;
    int16_t value2;
    char ligne3;
    int16_t value3;
    char ligne4;
    int16_t value4;
    char ligne5;
    int16_t value5;
  };

  struct init_pages
  {
    init_lignes ligne1;
    init_lignes page2;
    init_lignes page3;
  };

  init_pages pages;

but it does not help a lot, as we never now on wich line a measure will be.

I wonder if you have an idea how to do that at the end of function?

A human word, I would say

If a line is free on the first page, save the value, or look for the next line free. IF all line of the page 1 is busy, look to save on the page 2 or 3...

How would you do it in Arduino language???
How sould I start?

many THANKS

You could do it with a two dimensional array of char. As you read your sensors, any that are available get an entry put into the next empty row. When you display the first page, show the first four rows from the array.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.