delay() stops code when trying to output to LCD

Hello,

I made some custom characters using some resources I found and I got some designs down but I'm trying to get the code to alternate between one and the other.

It's super fast so I understand if I put one followed by the other, we wont even see the first one and it'll stay on the second one.

When I put in a delay(500) between the two, it doesn't output the second image at all and just hangs on the first one. I don't know why.

If I am missing information to help figure out why this isn't working or if this is the wrong place to post this, please tell me!

Thanks,

  • doug
/*
  LiquidCrystal Library - Hello World

 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 modified 7 Nov 2016
 by Arturo Guadalupi

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld

*/

// include the library code:
#include <LiquidCrystal.h>


// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long time;

byte fill[8] = {
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111,
  0b11111
};

byte bot_eye[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b11111,
  0b11111
};

byte top_eye[8] = {
  0b11111,
  0b11111,
  0b11111,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

byte glee_1[8] = {
  0b00000,
  0b00011,
  0b01111,
  0b11111,
  0b11100,
  0b10000,
  0b00000,
  0b00000
};

byte glee_2[8] = {
  0b00111,
  0b11111,
  0b11111,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

byte glee_3[8] = {
  0b11100,
  0b11111,
  0b11111,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

byte glee_4[8] = {
  0b00000,
  0b11100,
  0b11111,
  0b00111,
  0b00001,
  0b00000,
  0b00000,
  0b00000
};

byte empty[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

void neutral() {

  lcd.begin(16, 2);
  
  lcd.createChar(0, fill);
  lcd.createChar(2,top_eye);
  lcd.createChar(1,bot_eye);
  
  //Left Eye
  lcd.setCursor(3,0);
  lcd.write((uint8_t)0);

  lcd.setCursor(4,0);
  lcd.write((uint8_t)2);

  lcd.setCursor(5,0);
  lcd.write((uint8_t)2);

  lcd.setCursor(6,0);
  lcd.write((uint8_t)0);

  lcd.setCursor(3,2);
  lcd.write((uint8_t)0);

  lcd.setCursor(4,2);
  lcd.write((uint8_t)1);

  lcd.setCursor(5,2);
  lcd.write((uint8_t)1);

  lcd.setCursor(6,2);
  lcd.write((uint8_t)0);

  // Right Eye (col+3)
  lcd.setCursor(9,0);
  lcd.write((uint8_t)0);

  lcd.setCursor(10,0);
  lcd.write((uint8_t)2);

  lcd.setCursor(11,0);
  lcd.write((uint8_t)2);

  lcd.setCursor(12,0);
  lcd.write((uint8_t)0);

  lcd.setCursor(9,2);
  lcd.write((uint8_t)0);

  lcd.setCursor(10,2);
  lcd.write((uint8_t)1);

  lcd.setCursor(11,2);
  lcd.write((uint8_t)1);

  lcd.setCursor(12,2);
  lcd.write((uint8_t)0);
}

void glee(){
   lcd.begin(16, 2);
   lcd.createChar(3,glee_1);
   lcd.createChar(4,glee_2);
   lcd.createChar(5,glee_3);
   lcd.createChar(6,glee_4);
   lcd.createChar(7,empty);

     //Left Eye
  lcd.setCursor(3,0);
  lcd.write((uint8_t)3);

  lcd.setCursor(4,0);
  lcd.write((uint8_t)4);

  lcd.setCursor(5,0);
  lcd.write((uint8_t)5);

  lcd.setCursor(6,0);
  lcd.write((uint8_t)6);

  lcd.setCursor(3,2);
  lcd.write((uint8_t)7);

  lcd.setCursor(4,2);
  lcd.write((uint8_t)7);

  lcd.setCursor(5,2);
  lcd.write((uint8_t)7);

  lcd.setCursor(6,2);
  lcd.write((uint8_t)7);

  // Right Eye (col+3)
  lcd.setCursor(9,0);
  lcd.write((uint8_t)3);

  lcd.setCursor(10,0);
  lcd.write((uint8_t)4);

  lcd.setCursor(11,0);
  lcd.write((uint8_t)5);

  lcd.setCursor(12,0);
  lcd.write((uint8_t)6);

  lcd.setCursor(9,2);
  lcd.write((uint8_t)7);

  lcd.setCursor(10,2);
  lcd.write((uint8_t)7);

  lcd.setCursor(11,2);
  lcd.write((uint8_t)7);

  lcd.setCursor(12,2);
  lcd.write((uint8_t)7);
  
  }

  void loop(){
   // for(int i = 1; i > 0; i++){
      glee();
     time = millis();
      neutral();
      
      
    
    }

int main(){
    loop();

  
  }

You don't have delay anywhere. You don't loop at all, so your code will only do one glee() followed by one neutral().

Why do you overwrite the main function?

If you use the normal approach (with a setup() and a loop() function and don't overwrite main()), you will need two delays, else it looks like only the 1st one shows. The second one will show but so briefly that you will not see it.

...
...

void setup()
{
}

void loop()
{
  glee();
  delay(500);
  neutral();
  delay(500);
}

Thanks your your reply!

Yep that fixed it. I had delay in there earlier sorry for not having it in the code, I must've deleted it during troubleshooting before copying the whole thing and posting here.

When I changed int main back to void setup it worked.

It works after doing what you said.

Thanks!