发送连续值时如何在 OLED 显示屏中显示值而不使整个文本闪烁?

问题描述 投票:0回答:0

我正在尝试使用 STM32 微控制器显示从 NTC 温度传感器读取的值并将其写入 OLED 显示屏。然而,当我不断发送值时,整个文本和值不断闪烁,而不仅仅是值。我只希望更新的值闪烁,并且支持文本(如“温度 NTC1:”)不闪烁。

这是我在 while 循环中尝试的代码,我使用了该网站的显示库:https://controllerstech.com/oled-display-using-i2c-stm32/

char tempStr[32];  ///16
                            SSD1306_Init (); // initialize the display
                        SSD1306_Clear();  // Clear the screen
                        SSD1306_GotoXY(10, 10);  // Adjust Y position for the first temperature value
                    snprintf(tempStr, sizeof(tempStr),"Temp NTC1: %.2f °C" , temperature_ntc1);  // Format NTC1 temperature value to string and store in tempStr array
                    SSD1306_Puts(tempStr, &Font_7x10, SSD1306_COLOR_WHITE);    //Print/ Display NTC1 temperature
                    SSD1306_GotoXY(10, 30);  //Adjust the Y position for the second temperature value
                    snprintf(tempStr, sizeof(tempStr),"Temp NTC2: %.2f °C" , temperature_ntc2); //Format NTC2 temperature
                    SSD1306_Puts(tempStr, &Font_7x10, SSD1306_COLOR_WHITE); //Print/ Display NTC2 temperature
                    SSD1306_UpdateScreen(); //Update the display by sending buffer data to controller
                    HAL_Delay(5000);

我尝试在 while 循环之外给出这个特定的字符串(下面给出的代码)作为静态文本,但是当发送新值时整个文本仍然不断闪烁。

我真正想要的是“Temp NTC1:和Temp NTC2:”保持静态,并且在更新新值时读数值每秒保持闪烁。

char staticText1[] = "Temp NTC1: ";
char staticText2[] = "Temp NTC2: ";
char tempStr1[32];
char tempStr2[32];

SSD1306_Init();   // Initialize OLED

while (1)
{
    // .temperature calculation code for NTC1 ...

    // Format NTC1 temperature value
    snprintf(tempStr1, sizeof(tempStr1), "%.2f °C", temperature_ntc1);

    // ... temperature calculation code for NTC2 ...

    // Format NTC2 temperature value
    snprintf(tempStr2, sizeof(tempStr2), "%.2f °C", temperature_ntc2);

    SSD1306_Clear();  // Clear the entire screen

    // Display static text for NTC1
    SSD1306_GotoXY(10, 10);
    SSD1306_Puts(staticText1, &Font_7x10, SSD1306_COLOR_WHITE);

    // Display NTC1 temperature value
    SSD1306_GotoXY(10 + strlen(staticText1) * 7, 10);
    SSD1306_Puts(tempStr1, &Font_7x10, SSD1306_COLOR_WHITE);

    // Display static text for NTC2
    SSD1306_GotoXY(10, 30);
    SSD1306_Puts(staticText2, &Font_7x10, SSD1306_COLOR_WHITE);

    // Display NTC2 temperature value
    SSD1306_GotoXY(10 + strlen(staticText2) * 7, 30);
    SSD1306_Puts(tempStr2, &Font_7x10, SSD1306_COLOR_WHITE);

    SSD1306_UpdateScreen();

    HAL_Delay(1000);  // Update the values every second
}
c stm32 microcontroller hardware display
© www.soinside.com 2019 - 2024. All rights reserved.