#include <Wire.h> #include <LiquidCrystal_I2C.h> int text[] = {77, 111, 110, 101, 121, 32, 115, 101, 99, 117, 114, 105, 116, 121}; LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2); // LCD экран подключается к шине I2C на плате esp32. void setup() { // put your setup code here, to run once: Serial.begin(115200); LCD.init(); LCD.backlight(); LCD.setCursor(0, 0); LCD.print("Welcom ROBBANK"); LCD.setCursor(0, 1); LCD.print("Calibrate System"); delay(1000); LCD.clear(); LCD.setCursor(0, 0); } void loop() { LCD.clear(); LCD.setCursor(0, 0); LCD.print("code:"); LCD.setCursor(0, 1); Text(); delay(2000); } void Text(){ LCD.setCursor(0, 1); for (int i=0; i<14; i++){ LCD.setCursor(i, 1); LCD.write(text[i]); } }
There are a few issues with your code: 1. You are trying to call the `Text()` function from the `loop()` function, but you haven't declared it as a function. You need to add the `void Text()` declaration before the `loop()` function. 2. In the `Text()` function, you are trying to set the cursor position to `i` and then print the character at index `i` from the `text` array. However, this will only print the character at the current cursor position, not overwrite the previous characters. You should use the `LCD.print()` function to print the character at the current cursor position. 3. You are trying to print the `text` array as a string, but the `text` array is an array of integers. You need to convert the integers to characters using the `char` data type. Here's the corrected code: ```cpp #include <Wire.h> #include <LiquidCrystal_I2C.h> int text[] = {77, 111, 110, 101, 121, 32, 115, 101, 99, 117, 114, 105, 116, 121}; LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2); void setup() { // put your setup code here, to run once: Serial.begin(115200); LCD.init(); LCD.backlight(); LCD.setCursor(0, 0); LCD.print("Welcom ROBBANK"); LCD.setCursor(0, 1); LCD.print("Calibrate System"); delay(1000); LCD.clear(); LCD.setCursor(0, 0); } void loop() { LCD.clear(); LCD.setCursor(0, 0); LCD.print("code:"); Text(); delay(2000); } void Text() { char str[15]; for (int i = 0; i < 14; i++) { str[i] = text[i]; } str[14] = '\0'; // null-terminate the string LCD.setCursor(0, 1); LCD.print(str); } ``` However, a more efficient way to print the string would be to use the `LCD.print()` function directly with the `text` array: ```cpp void Text() { char str[15]; for (int i = 0; i < 14; i++) { str[i] = text[i]; } str[14] = '\0'; // null-terminate the string LCD.setCursor(0, 1); LCD.print(str); } ``` Or even better, use a `String` object to store the text and print it directly: ```cpp #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <String.h> LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2); void setup() { // put your setup code here, to run once: Serial.begin(115200); LCD.init(); LCD.backlight(); LCD.setCursor(0, 0); LCD.print("Welcom ROBBANK"); LCD.setCursor(0, 1); LCD.print("Calibrate System"); delay(1000); LCD.clear(); LCD.setCursor(0, 0); } void loop() { LCD.clear(); LCD.setCursor(0, 0); LCD.print("code:"); String str; for (int i = 0; i < 14; i++) { str += (char)text[i]; } LCD.setCursor(0, 1); LCD.print(str); delay(2000); } ``` This way, you don't need to manually null-terminate the string or convert the integers to characters.