LCD numbers flicker?

this is my first time farting around with the LCD I made a few changes to the original sample code given in the lesson. i have it say something then clear and start the counter, but the numbers are all glitchy and are not showing up properly.

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("insert text");
  lcd.setCursor(0, 1);
  lcd.print("insert text!");
  delay(1500);
}

void loop() {
  lcd.clear();
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  // print the number of seconds since reset:
lcd.print(millis()/1000);

any help is much appreciated!!

is this because of the clear command? how would I separate the sequence?

The last part of the code is missing.

do you mean the }? it is in my IDE I just didn't highlight it to copy it over. if that is not what you mean then could you clarify?

I'm an idiot. i added a delay to the setup and moved the lcd.clear to the setup instead of the loop and it works fine now. how do I cycle between the countdown and a text without resetting the counter?

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("insert text");
  lcd.setCursor(0, 1);
  lcd.print("insert text!");
  delay(1500);
  lcd.clear();
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 0);
  // print the number of seconds since reset:
lcd.print(millis() / 1000);

I don't know if there is one character or several pages of code missing!

You will have to explain that in more detail. What countdown? What text? What should cause the cycling?

Also please bear in mind this forum is supposed to be family friendly, so please don't include words that could be considered offensive. If the forum moderators see them they might feel compelled to impose a ban, so consider editing your posts now before that happens.

1 Like

opp sorry about that I left it out of my statement but didn't omit it from the code. fixed it. in the lesson, it just starts a counter from when it initiates the loop. lcd.print(millis() / 1000); it's silly and doesn't really serve a purpose other than to show a possibility in the lesson.
my question is there a way to have the LCD swap back and forth from the setup prompt

lcd.print("insert text");
  lcd.setCursor(0, 1);
  lcd.print("insert text!");

or really any other message for example start the setup with something like "FINAL EXAM" then have the loop start the counter lcd.print(millis() / 1000) and then when it gets to a certain int have it pop up with something like "5 minutes left" then resume counting without interrupting the count or pausing it while the text is up. so say it's at 10 (seconds) then a text takes its place like "5 minutes left" and the text stays on screen for 5 (seconds) when the counter resumes it'll be at 16 (seconds) as if it was never interrupted.
this is all just for fun and to learn the code any help is appreciated but not necessary.
thank you for working with me 8D

Ok, the answer is yes, you can do all that.

The elapsed milliseconds counter, that the millis() function accesses, runs continuously, regardless of what your code is doing.

You can use if().... else if().... else if()..... constructs to figure out what time range it is and print what you want on the LCD in each range.

As you don't seem to be interested in the actual milliseconds, it might make your code shorter and easier if you calculate the seconds from the milliseconds once at the start of loop()

void loop() {
  unsigned long seconds = millis()/1000;

  if (seconds < 60) {
    //Print something
  }
  else if (seconds < 300) {
    //Print something else
  }
  else {
    //Print final message
  }
}

Notice that I check the time ranges in increasing order, so it's not necessary to say seconds >= 60 and seconds < 300 to identify each time range.

1 Like

@wathefox Request - When placing code in the message box for a posting, it's more useful if, in the IDE, you use control-T to format the code, and then use the 'copy for forum' command, then simply paste the result into the message. That gives us the entire code(no wondering if he omitted the }, or another 50 lines of code), and it's autoformatted for viewing as 'code' within the message.

1 Like

I am so sorry guys I ended up moving on after closing this out and didn't notice the responses. I apologize that was very rude of me. thank you for being so helpful. I've been doing some practice with the coding and that actually makes some sense now. as when I made the post I probably wouldn't have known what was going on here! but thank you again for your time and effort it is very much appreciated! ill make my way back to this and give it a shot!

thank you for the info I'll try to make sure I implement this next time I need to make a post! you guys are great keep up the awesome work!

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