Bug In code I2C LCD

Hi. My LCD works, but it isn't showing what I told it to show as it is staying blank. here is the annotation:


used tinker cad.

Here is my code:

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <ezButton.h>

#define Ypos A0
#define P1 A1
#define P2 A2
#define ESC_PIN 2
Servo esc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
ezButton button(3);

int speed = 0;
int Press1;
int Press2;
int avg_Ps;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  delay(500);
  lcd.print("Loading...");
  delay(1000);
  lcd.setCursor(1, 2);
  esc.attach(ESC_PIN, 1000, 2000);
  pinMode(Ypos, INPUT);
  pinMode(P1, INPUT);
  pinMode(P2, INPUT);
  lcd.setCursor(0, 1);
  lcd.print("Starting Devices...");
  delay(1550);
  lcd.clear();

  main();
}

void loop() {

  int UserDt = Serial.parseInt();
  esc.write(UserDt);
}

int main () {
  esc.write(18);
  delay(1000);
  esc.write(36);
  delay(1000);
  esc.write(54);
  delay(1000);
  esc.write(72);
  delay(1000);
  esc.write(90);
  delay(1000);
  esc.write(108);
  delay(1000);
  esc.write(126);
  delay(1000);
  esc.write(144);
  delay(1000);
  esc.write(162);
  delay(1000);
  esc.write(180);
  lcd.setCursor(0, 0);
  lcd.print("MAX SPEED");
  lcd.setCursor(0, 1);
  lcd.print("Switching to Command Prompt");
  while(Serial.available()==0){
    esc.write(0);
    }
  
}

I tried debugging it and I feel like that the problem is induced because of the "main" function. After removing it the program worked. but I need that function. Please Help.

Review:
Learn To Use LCD 1602 (I2C & Parallel) With Arduino UNO :tv: - Arduino Project Hub

You have a main function, but don't call setup or loop.

Best to get rid of it - put the main code in loop

Call this routine something else. "main" is a special entry point routine in C.

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