From c17371a76d8e4f7fae2c60ace74cbb6ecdc47749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=94=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B0=D1=87=D0=B5=D0=B2?= Date: Tue, 13 Feb 2024 18:47:51 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?/=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lcd_print.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ lcd.h | 8 ++++ 2 files changed, 121 insertions(+) create mode 100644 Lcd_print.cpp create mode 100644 lcd.h diff --git a/Lcd_print.cpp b/Lcd_print.cpp new file mode 100644 index 0000000..6379e6f --- /dev/null +++ b/Lcd_print.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lcdpcf8574.h" +#include "pcf8574.h" +#include "i2cmaster.h" +#include "lcd.h" +#include + +struct DisplayData { + char topLine[64]; + int value1; + int value2; + int value3; +}; + +struct TextCounter { + unsigned long startTime; + int incrementValue; +}; + +TextCounter textCounter; + +void Lcd_inciliation() { + lcd_init(LCD_DISP_ON_BLINK); // инициализация дисплея + lcd_home(); // домой курсор + lcd_led(0); // вкл подсветки + textCounter.startTime = millis(); // Запоминаем время запуска программы +} + +void fillBuffer1(const char * source, char * buffer, size_t bufferSize, int incrementValue) { + int startIndex = incrementValue % strlen(source); // Определяем начальный индекс на основе incrementValue + int endIndex = startIndex + 16; + + if (endIndex > strlen(source)) { + // Если endIndex превышает длину строки source, переносим его на начало строки + endIndex = endIndex - strlen(source); + + // Копируем символы с конца строки source + strncpy(buffer, source + startIndex, strlen(source) - startIndex); + + // Копируем оставшиеся символы с начала строки source + strncat(buffer, source, endIndex); + } else { + strncpy(buffer, source + startIndex, endIndex - startIndex); + } + buffer[endIndex - startIndex] = '\0'; // Установка нулевого символа в конце буфера +} + +void fillBuffer2(int value1, int value2, int value3, char * buffer, size_t bufferSize) { + snprintf(buffer, bufferSize, "%d.%d.%d", value1, value2, value3); +} + +int convertR(char h, char t, char o) +{ + return ((h - '0') * 100 + (t - '0') * 10 + (o - '0') * 1); + +} + + +void first_nine(struct DisplayData arr) { + size_t len = strlen(arr.topLine); + memmove(arr, arr.topLine + 9, len - 8 ); +} + +void printLcd(const char * inputText) +{ + unsigned long currentTime = millis(); // Текущее время + // Проверяем, прошло ли 500 мс с момента последнего увеличения incrementValue + if (currentTime - textCounter.startTime >= 500) { + textCounter.incrementValue++; // Увеличиваем incrementValue на 1 + textCounter.startTime = currentTime; // Обновляем время + } + + struct DisplayData displayData; + strncpy(displayData.topLine, inputText, sizeof(displayData.topLine) - 1); + displayData.topLine[sizeof(displayData.topLine) - 1] = '\0'; + displayData.value1 = convertR(displayData.topLine[0], displayData.topLine[1], displayData.topLine[2]); + displayData.value2 = convertR(displayData.topLine[3], displayData.topLine[4], displayData.topLine[5]); + displayData.value3 = convertR(displayData.topLine[6], displayData.topLine[7], displayData.topLine[8]); + + first_nine(displayData); + + // Буферы для заполнения данных + char buffer1[17]; + char buffer2[17]; + + // Заполнение буфера 1 + fillBuffer1(displayData.topLine, buffer1, sizeof(buffer1), textCounter.incrementValue); + + // Заполнение буфера 2 + fillBuffer2(displayData.value1, displayData.value2, displayData.value3, buffer2, sizeof(buffer2)); + + // Создание массива для вывода на дисплей + char displayArray[32]; + strncpy(displayArray, buffer1, 16); // Копирование первых 16 символов из buffer1 в displayArray + strncpy(displayArray + 16, buffer2, 16); // Копирование первых 16 символов из buffer2 в displayArray, начиная с позиции 16 + + // Вывод данных на экран + lcd_gotoxy(0, 0); + lcd_puts(displayArray); + + lcd_gotoxy(0, 1); + lcd_puts(displayArray + 16); // Вывод второй половины displayArray +} + diff --git a/lcd.h b/lcd.h new file mode 100644 index 0000000..b66935b --- /dev/null +++ b/lcd.h @@ -0,0 +1,8 @@ +#ifndef Lcd_print_h +#define Lcd_print_h +#include + +void Lcd_inciliation(); +void printLcd(const char* inputText); + +#endif \ No newline at end of file