Noob here getting started need help with using LCD16x2 with pushbuttons

Hi to start off I am kind of new in arduino and need some help
First what I need to do over all is a kind of ventilator but right now I am working in creating a menu with an LCD and some pushbuttons and then work on the details of every sensor I’ll be using
So right now what I want is for my display to display first “Welcome to your Ventilator” and the clear the screen and put up Menu and the variables.
This is my code the buttons are for later

#include <LiquidCrystal.h>

int button1 = 3;
int button2 = 4;
int buttonNew1;
int buttonNew2;
int buttonOld1 = 1;
int buttonOld2 = 1;
int modo;

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() { // put your setup code here, to run once:
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16,2);

}

void loop() { // put your main code here, to run repeatedly:
  buttonNew1 = digitalRead(button1);
  buttonNew2 = digitalRead(button2);
  lcd.setCursor(0,0);
  lcd.print("Welcome to your");
  lcd.setCursor(3,1);
  lcd.print("Ventilator");
  delay(2000);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Menu");
  lcd.setCursor(0,1);
  lcd.print("Temp/FiO2/Flujo");
  
}

when i run it the fisrt message comes up good but then the words get mixed in together so it does not display correctly any help with this? There is a lot more I need to do but since I am just starting in arduino any quick fix thanks

The loop() function loops. You send the second message to the LCD then, right away the program loops back to the start and you write the first message. The easy way to see this is to put a delay() after writing the second message and clear the LCD again before displaying the first message.

#include <LiquidCrystal.h>

int button1 = 3;
int button2 = 4;
int buttonNew1;
int buttonNew2;
int buttonOld1 = 1;
int buttonOld2 = 1;
int modo;

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup()   // put your setup code here, to run once:
{
   pinMode(button1, INPUT_PULLUP);
   pinMode(button2, INPUT_PULLUP);
   Serial.begin(9600);
   lcd.begin(16, 2);

}

void loop()   // put your main code here, to run repeatedly:
{
   buttonNew1 = digitalRead(button1);
   buttonNew2 = digitalRead(button2);
   lcd.setCursor(0, 0);
   lcd.print("Welcome to your");
   lcd.setCursor(3, 1);
   lcd.print("Ventilator");
   delay(2000);

   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Menu");
   lcd.setCursor(0, 1);
   lcd.print("Temp/FiO2/Flujo");
   delay(2000);  // ***************** added delay
   lcd. clear(); // ***************** added clear()
}

Avoid using the clear() function in loop() code. It is slow and can cause the display to flicker. Overwrite old data and use spaces to clear the area to print to.

lcd.setCursor(0,0);
lcd.print("humidity =      ");  // padded with spaces to overwrite old data
lcd.setCursor(10,0);
lcd.print(humidity);

groundFungus:
The loop() function loops. You send the second message to the LCD then, right away the program loops back to the start and you write the first message. The easy way to see this is to put a delay() after writing the second message and clear the LCD again before displaying the first message.

#include <LiquidCrystal.h>

int button1 = 3;
int button2 = 4;
int buttonNew1;
int buttonNew2;
int buttonOld1 = 1;
int buttonOld2 = 1;
int modo;

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup()   // put your setup code here, to run once:
{
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16, 2);

}

void loop()   // put your main code here, to run repeatedly:
{
  buttonNew1 = digitalRead(button1);
  buttonNew2 = digitalRead(button2);
  lcd.setCursor(0, 0);
  lcd.print(“Welcome to your”);
  lcd.setCursor(3, 1);
  lcd.print(“Ventilator”);
  delay(2000);

lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(“Menu”);
  lcd.setCursor(0, 1);
  lcd.print(“Temp/FiO2/Flujo”);
  delay(2000);  // ***************** added delay
  lcd. clear(); // ***************** added clear()
}

ok so I changed it to this

#include <LiquidCrystal.h>

int button1 = 8;
int button2 = 9;
int button3 = 10;
int buttonNew1;
int buttonNew2;
int buttonNew3;
int buttonOld1 = 1;
int buttonOld2 = 1;
int buttonOld3 = 1;
int modo;


LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

void setup() { // put your setup code here, to run once:
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Welcome to your");
  lcd.setCursor(3,1);
  lcd.print("Ventilator");
  delay(2000);

}

void loop() { // put your main code here, to run repeatedly:
  buttonNew1 = digitalRead(button1);
  buttonNew2 = digitalRead(button2);
  buttonNew3 = digitalRead(button3);
  
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Menu");
  lcd.setCursor(0,1);
  lcd.print("Temp/FiO2/Flujo");
  delay(250);
  
}

This way the first message displays once and then we come into my menu section but it flickers with the delay I placed do I fix this with just a greater delay?? and if so that delay wont affect any variables and inputs i put in as I go forward

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