Is there anything wrong with this code?

Hi!

For about a week or two ago I bought the arduino starter kit, or maybe it was three or four weeks, I really can't keep any track of it. However I have gotten to the project where you learn LCDs and after some time now, I am starting to get into the more "complex" stuff I guess. When I say complex I mostly mean custom characters and so on. And today I wanted to write "Samuel's display" and have a progress bar underneath. I tried using this code:

#include <LiquidCrystal.h>

LiquidCrystal lcd (12,11,5,4,3,2);

byte p20[8] = {
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
};

byte p40[8] = {
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
};

byte p60[8] = {
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
};

byte p80[8] = {
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
};

byte p100[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};


  

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Intializing");
  lcd.setCursor(11,0);
  delay(500);
  lcd.print(".");  
  lcd.setCursor(12,0);
  delay(500);
  lcd.print(".");
  lcd.setCursor(13, 0);
  delay(500);
  lcd.print(".");
  
  delay(3000);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Samuel's display");
  
  lcd.createChar(0, p20);
  lcd.createChar(1, p40);
  lcd.createChar(2, p60);
  lcd.createChar(3, p80);
  lcd.createChar(4, p100);

}

void loop() {

  lcd.setCursor(0,1);
  lcd.print("                ");
  
  for(int i; i < 16; i++) {
   for (int j; j < 5; j++) {
    lcd.setCursor(i,1);
    lcd.write(byte(j));
    delay(100);
   } 
  }
}

But it did not work, so much question pretty much is, is it my code or is it the LCD that is messing with me? Because it displays "Samuel's display" and "Initializing" but the progress bar does not show up. Thanks for any help regarding this problem.

Samuel

But it did not work, so much question pretty much is, is it my code or is it the LCD that is messing with me?

There is a problem dealing with the custom character at location '0' having to do with how the newer versions of the Arduino IDE deal with 'printing' and/or 'writing'.

The easiest way to determine if this is the problem is to temporarily avoid using the character at that location.

There are several better solutions if that proves to be the problem, I'll try to locate one of the threads where they are spelled out.

Don

EDIT: Here's the solution, by Bill aka bperrybap:

Replace .... lcd.write(0); with .... lcd.write((uint8_t)0);

Use the search box at the upper right with the terms bperrybap and lcd.write((uint8_t)0); to get all the gory details.

So how would I replace the code still using the J variabe to keep track of where and how I should write the character, in other words, what does the final code look like with your changes?

working progress bar

#include <LiquidCrystal.h>

LiquidCrystal lcd (12,11,5,4,3,2);

byte p20[8] = {
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
};

byte p40[8] = {
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
};

byte p60[8] = {
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
};

byte p80[8] = {
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
};

byte p100[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};

byte p120[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};
  

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Intializing");
  lcd.setCursor(11,0);
  delay(500);
  lcd.print(".");  
  lcd.setCursor(12,0);
  delay(500);
  lcd.print(".");
  lcd.setCursor(13, 0);
  delay(500);
  lcd.print(".");
  
  delay(3000);
  
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Samuel's display");
  
  lcd.createChar(0, p20);
  lcd.createChar(1, p40);
  lcd.createChar(2, p60);
  lcd.createChar(3, p80);
  lcd.createChar(4, p100);
  lcd.createChar(5, p120);
}

void loop() {

 lcd.setCursor(0,1);
 lcd.print("                ");   
 
 for (int i = 0; i<16; i++)
 {
   
   for (int j=0; j<5; j++)
   {
      lcd.setCursor(i, 1);   
      lcd.write(j);
      delay(60);
    } 
  }
     for (int i=15; i>=0; i--)
 {
   
   for (int j=0; j<6; j++)
   {
      lcd.setCursor(i, 1);   
      lcd.write(j);
      delay(60);
    } 
  }
    for (int i = 0; i<16; i++)
 {
   
   for (int j=0; j<5; j++)
   {
      lcd.setCursor(i, 1);   
      lcd.write(j);
      delay(50);
    } 
  }
     for (int i=15; i>=0; i--)
 {
   
   for (int j=0; j<6; j++)
   {
      lcd.setCursor(i, 1);   
      lcd.write(j);
      delay(50);
    } 
  }
    for (int i = 0; i<16; i++)
 {
   
   for (int j=0; j<5; j++)
   {
      lcd.setCursor(i, 1);   
      lcd.write(j);
      delay(50);
    } 
 }
 
 for (int i = 0; i<16; i++)
 {
   
   for (int j=0; j<5; j++)
   {
      lcd.setCursor(i, 1);   
      lcd.write(j);
      delay(50);
    } 
 }
}

change the code in the main loop if u dislike my progress bar

i am using ide 1.6.3 and uno r3 by the way

siutoejai:
working progress bar

#include <LiquidCrystal.h>

LiquidCrystal lcd (12,11,5,4,3,2);

byte p20[8] = {
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
  B10000,
};

byte p40[8] = {
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
};

byte p60[8] = {
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
  B11100,
};

byte p80[8] = {
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
  B11110,
};

byte p100[8] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
};

byte p120[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};

void setup() {
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Intializing");
  lcd.setCursor(11,0);
  delay(500);
  lcd.print("."); 
  lcd.setCursor(12,0);
  delay(500);
  lcd.print(".");
  lcd.setCursor(13, 0);
  delay(500);
  lcd.print(".");
 
  delay(3000);
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Samuel's display");
 
  lcd.createChar(0, p20);
  lcd.createChar(1, p40);
  lcd.createChar(2, p60);
  lcd.createChar(3, p80);
  lcd.createChar(4, p100);
  lcd.createChar(5, p120);
}

void loop() {

lcd.setCursor(0,1);
lcd.print("                ");

for (int i = 0; i<16; i++)
{
 
  for (int j=0; j<5; j++)
  {
      lcd.setCursor(i, 1); 
      lcd.write(j);
      delay(60);
    }
  }
    for (int i=15; i>=0; i--)
{
 
  for (int j=0; j<6; j++)
  {
      lcd.setCursor(i, 1); 
      lcd.write(j);
      delay(60);
    }
  }
    for (int i = 0; i<16; i++)
{
 
  for (int j=0; j<5; j++)
  {
      lcd.setCursor(i, 1); 
      lcd.write(j);
      delay(50);
    }
  }
    for (int i=15; i>=0; i--)
{
 
  for (int j=0; j<6; j++)
  {
      lcd.setCursor(i, 1); 
      lcd.write(j);
      delay(50);
    }
  }
    for (int i = 0; i<16; i++)
{
 
  for (int j=0; j<5; j++)
  {
      lcd.setCursor(i, 1); 
      lcd.write(j);
      delay(50);
    }
}

for (int i = 0; i<16; i++)
{
 
  for (int j=0; j<5; j++)
  {
      lcd.setCursor(i, 1); 
      lcd.write(j);
      delay(50);
    }
}
}





change the code in the main loop if u dislike my progress bar

i am using ide 1.6.3 and uno r3 by the way

Thanks a lot!