How do I serial print multi information variable in a ardunio?

hello guys
i have some problem my project used ssd1306 and ardunio uno
i have 4 case in my sketch and page in my screen

case 0: 
         display.clearDisplay();
        display.setTextSize(1);
        display.print(F("SENSOR1"));
        Serial.print(SENSOR1);
        display.setCursor(40,12);
        display.display();
    break;

    case 1: 
           display.clearDisplay();
        display.setTextSize(1);
        display.print(F("SENSOR2"));
        Serial.print(SENSOR2);
        display.setCursor(40,12);
        display.display();
        break;

    case 2: 
         display.clearDisplay();
        display.setTextSize(1);
        display.print(F("SENSOR3"));
        Serial.print(SENSOR3);
        display.setCursor(40,12);
        display.display();
    

    break;

    case 3:  
         display.clearDisplay();
        display.setTextSize(1);
        display.print(F("SENSOR4"));
        Serial.print(SENSOR4);
        display.setCursor(40,12);
        display.display();
    

    break;

My problem is that I do not find the information of all 4 sensors in one place through serial monitor
On every page I am on, only the information of the same sensor is sent through the serial monitor
How can I have the information of all 4 sensors in one place on the serial?

not sure i totally understand your issue

i dislike having lcd/oled commands throughout the code because there are so many of them. what i prefer is to have a single function passed as many strings as the display has, format the strings and call that function

i think the may help you in this case because those same strings can be sent to the serial monitor

sprintf() can be used to format a single string with multiple variables and text.

if there are separate strings allocated for each sensor, each case can handle formatting the string for the sensor and call to display the strings for that sensor. after the switch, multiple serial printlns can send the strings for all sensors to the serial monitor

2 Likes

you did not post your full code. So it is unpossible to say where to place the serial output.

Just a rough estimation: it has to be outside all cases.
So put all
Serial.print(SENSOR1);
Serial.print(SENSOR2);
Serial.print(SENSOR3);
Serial.print(SENSOR4);

above or below your switch-case structure.
where it fits best and what the exact place would be can only be said of you post your sketch from the very first to the very last line

anyway. You seem to not really understand what is going on in your code.
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

2 Likes