Arduino clock and ptoblem with the program

Hello!
My idea is to make a clock with the arduino (UNO) and a LCD keypad shield. But i dont want to use the ordinary font for the display. I want to use the font from this video. I have the code for it:

// include the library
#include <LiquidCrystal.h>
 
// initialize the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// the 8 arrays that form each segment of the custom numbers
byte bar1[8] = 
{
        B11100,
        B11110,
        B11110,
        B11110,
        B11110,
        B11110,
        B11110,
        B11100
};
byte bar2[8] =
{
        B00111,
        B01111,
        B01111,
        B01111,
        B01111,
        B01111,
        B01111,
        B00111
};
byte bar3[8] =
{
        B11111,
        B11111,
        B00000,
        B00000,
        B00000,
        B00000,
        B11111,
        B11111
};
byte bar4[8] =
{
        B11110,
        B11100,
        B00000,
        B00000,
        B00000,
        B00000,
        B11000,
        B11100
};
byte bar5[8] =
{
        B01111,
        B00111,
        B00000,
        B00000,
        B00000,
        B00000,
        B00011,
        B00111
};
byte bar6[8] =
{
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B11111,
        B11111
};
byte bar7[8] =
{
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00111,
        B01111
};
byte bar8[8] =
{
        B11111,
        B11111,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000,
        B00000
};
 
 
 
void setup()
{
  // assignes each segment a write number
  lcd.createChar(1,bar1);
  lcd.createChar(2,bar2);
  lcd.createChar(3,bar3);
  lcd.createChar(4,bar4);
  lcd.createChar(5,bar5);
  lcd.createChar(6,bar6);
  lcd.createChar(7,bar7);
  lcd.createChar(8,bar8);
  
  // sets the LCD's rows and colums:
  lcd.begin(16, 2);
 
}
 
void custom0(int col)
{ // uses segments to build the number 0
  lcd.setCursor(col, 0); 
  lcd.write(2);  
  lcd.write(8); 
  lcd.write(1);
  lcd.setCursor(col, 1); 
  lcd.write(2);  
  lcd.write(6);  
  lcd.write(1);
}
 
void custom1(int col)
{
  lcd.setCursor(col,0);
  lcd.write(32);
  lcd.write(32);
  lcd.write(1);
  lcd.setCursor(col,1);
  lcd.write(32);
  lcd.write(32);
  lcd.write(1);
}
 
void custom2(int col)
{
  lcd.setCursor(col,0);
  lcd.write(5);
  lcd.write(3);
  lcd.write(1);
  lcd.setCursor(col, 1);
  lcd.write(2);
  lcd.write(6);
  lcd.write(6);
}
 
void custom3(int col)
{
  lcd.setCursor(col,0);
  lcd.write(5);
  lcd.write(3);
  lcd.write(1);
  lcd.setCursor(col, 1);
  lcd.write(7);
  lcd.write(6);
  lcd.write(1); 
}
 
void custom4(int col)
{
  lcd.setCursor(col,0);
  lcd.write(2);
  lcd.write(6);
  lcd.write(1);
  lcd.setCursor(col, 1);
  lcd.write(32);
  lcd.write(32);
  lcd.write(1);
}
 
void custom5(int col)
{
  lcd.setCursor(col,0);
  lcd.write(2);
  lcd.write(3);
  lcd.write(4);
  lcd.setCursor(col, 1);
  lcd.write(7);
  lcd.write(6);
  lcd.write(1);
}
 
void custom6(int col)
{
  lcd.setCursor(col,0);
  lcd.write(2);
  lcd.write(3);
  lcd.write(4);
  lcd.setCursor(col, 1);
  lcd.write(2);
  lcd.write(6);
  lcd.write(1);
}
 
void custom7(int col)
{
  lcd.setCursor(col,0);
  lcd.write(2);
  lcd.write(8);
  lcd.write(1);
  lcd.setCursor(col, 1);
  lcd.write(32);
  lcd.write(32);
  lcd.write(1);
}
 
void custom8(int col)
{
  lcd.setCursor(col, 0); 
  lcd.write(2);  
  lcd.write(3); 
  lcd.write(1);
  lcd.setCursor(col, 1); 
  lcd.write(2);  
  lcd.write(6);  
  lcd.write(1);
}
void loop(){
  lcd.setCursor(1,0);
  lcd.write(2);
  lcd.write(3);
  lcd.write(4);
  lcd.setCursor(1, 1);
  lcd.write(7);
  lcd.write(6);
  lcd.write(1);
}

But, if I want to display the digit “5”, every time I have to tupe:

lcd.setCursor(1,0);
  lcd.write(2);
  lcd.write(3);
  lcd.write(4);
  lcd.setCursor(1, 1);
  lcd.write(7);
  lcd.write(6);
  lcd.write(1);

Can I do some sort of macro for this (and for every other digit)?

Can I do some sort of macro for this (and for every other digit)?

How about putting the code in a function and the list of segments for each digit in an array. Pass the number to the function, use it as the index to the array and use a for loop to show the segments from the array.

Ok, but how can i do it?

Stan_be:
Ok, but how can i do it?

Call custom5().

Stan_be:
Ok, but how can i do it?

Two steps:

1st step: Create an array of 10 digits and initialize the array with the data of your font:

byte bignums[10][2][3]

Where 10 is the number of custom digits. 2 the number of rows and 3 the number of columns for each custom digit.

2nd step: Create a function than can print each digit from the array to the desired position on the LCD as you want it.

Are you an experienced programmer or do you need additional assistance?

I am not an experienced programmer, any help will be highly appreciated! I understood the main idea, but i don't know how to make it work.

Stan_be:
I am not an experienced programmer, any help will be highly appreciated! I understood the main idea, but i don’t know how to make it work.

So here is some example code which uses the big digits created from custom characters as you wanted it.

I use a different custom character creation which doesn’t need arrays to save some RAM.

If you need to save even more RAM, the bignums array will have to be created in PROGMEM, but it would complicate the coding of the printbigchar() function a little bit.

So here is a second counter which counts up to 9999 with showing ‘big digits’ on a text LCD:

// second counter on LCD with "big digits" by 'jurs'
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#define LCD_WIDTH 16
#define LCD_HEIGHT 2


void loadchars() {  // This subroutine programs the custom character data into the LCD
  lcd.command(64);
  // custom character 0
  lcd.write((byte)B11100);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11100);
  // custom character 1
  lcd.write((byte)B00111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B00111);
  // custom character 2
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  // custom character 3
  lcd.write((byte)B11110);
  lcd.write((byte)B11100);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B11000);
  lcd.write((byte)B11100);
  // custom character 4
  lcd.write((byte)B01111);
  lcd.write((byte)B00111);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00011);
  lcd.write((byte)B00111);
  // custom character 5
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  // custom character 6
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00111);
  lcd.write((byte)B01111);
  // custom character 7
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.home();
}

byte bignums[11][2][3] = {
// digits are 3 characters wide and 2 lines high
// define which characters to use for each number. 255 is a solid block; 32 or 254 is a space  
// the format is { {TopLeft, TopMiddle, TopRight}, {BottomLeft, BottomMiddle, BottomRight} }
 { {1, 7, 0}, {1, 5, 0} },      // data to display "0"
 { {32, 32, 0}, {32, 32, 0} },  // data to display "1"
 { {4, 2, 0}, {1, 5, 5} },      // data to display "2"
 { {4, 2, 0}, {6, 5, 0} },      // data to display "3"
 { {1, 5, 0}, {32, 32, 0} },    // data to display "4"
 { {1, 2, 3}, {6, 5, 0} },      // data to display "5"
 { {1, 2, 3}, {1, 5, 0} },      // data to display "6"
 { {1, 7, 0}, {32, 32, 0} },    // data to display "7"
 { {1, 2, 0}, {1, 5, 0} },      // data to display "8"
 { {1, 2, 0}, {6, 5, 0} },      // data to display "9"
};


void printbigchar(byte digit, byte col) { // This subroutine prints the big font characters on the LCD screen
 if (digit > 9) return;                   // reject anything above 9
 for (int i = 0; i < 2; i++) {            // count i from 0 to 1
   lcd.setCursor(col*4 , i);              // set LCD cursor at correct point
   for (int j = 0; j < 3; j++) {          // count j from 0 to 2
     lcd.write((byte)bignums[digit][i][j]);     // write proper block to LCD from array
   }
   lcd.write(254);                        // write an empty space
 }
 lcd.setCursor(col + 4, 0);               // move the cursor to the top line, col + 4
}


void setup(){
  lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  loadchars();
}


unsigned long secondCounter;

void loop()
{
  unsigned long currentSecond=millis()/1000;
  if (currentSecond!=secondCounter)
  {
    secondCounter=currentSecond;
    char buf[11];
    snprintf(buf,sizeof(buf),"%04ld",currentSecond);
    for (int i=0;i<4;i++)  printbigchar(buf[i]-'0', i);
  }
}

Each ‘big digit’ will be printed 4 columns wide: 3 columns with custom character data and one column seperating the different ‘big digits’ from each other. So on a 16 character display you can have 4 ‘big digits’ to be displayed.

Please feel free to ask if you have any questions.

Ok...You have done a great job with this. I'd love to follow you, if you have a channel, in youtube or instructables (or some other website) for arduino projects.

But I have another question. :slight_smile:
You have made a counter, and the digits are displayed acording to it. But for start I want to know how to display a number. What is the command for it? Is it something like this?

 lcd.write((byte)bignums[digit][0][1])

If I want to display "5" on the display, how to do it?

Stan_be:
If I want to display "5" on the display, how to do it?

This is how the printbigchar() function works: First parameter is the digit (0...9), second parameter is the position on the LCD display.

So you can print the big digit 5 at different positions using:

printbigchar(5, 0);

or

printbigchar(5, 1);

or

printbigchar(5, 2);

or

printbigchar(5, 3);

If you do all four lines of code, you will display '5555'.

Ok, it worked. I tried to use your big digits with the clock program, the problem was that your code was not abel to display digits bigger than 9, but i need to display the digits till 60 (for the minutes). So I started doing this:

// second counter on LCD with "big digits" by 'jurs'
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

#define LCD_WIDTH 16
#define LCD_HEIGHT 2


void loadchars() {  // This subroutine programs the custom character data into the LCD
  lcd.command(64);
  // custom character 0
  lcd.write((byte)B11100);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11110);
  lcd.write((byte)B11100);
  // custom character 1
  lcd.write((byte)B00111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B01111);
  lcd.write((byte)B00111);
  // custom character 2
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  // custom character 3
  lcd.write((byte)B11110);
  lcd.write((byte)B11100);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B11000);
  lcd.write((byte)B11100);
  // custom character 4
  lcd.write((byte)B01111);
  lcd.write((byte)B00111);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00011);
  lcd.write((byte)B00111);
  // custom character 5
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  // custom character 6
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00111);
  lcd.write((byte)B01111);
  // custom character 7
  lcd.write((byte)B11111);
  lcd.write((byte)B11111);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.write((byte)B00000);
  lcd.home();
}

byte bignums[61][2][6] = {
// digits are 3 characters wide and 2 lines high
// define which characters to use for each number. 255 is a solid block; 32 or 254 is a space  
// the format is { {TopLeft, TopMiddle, TopRight}, {BottomLeft, BottomMiddle, BottomRight} }
 { {1, 7, 0, 32, 32, 32}, {1, 5, 0, 32, 32, 32} },      // data to display "0"
 { {32, 32, 0, 32, 32, 32}, {32, 32, 0, 32, 32, 32} },  // data to display "1"
 { {4, 2, 0, 32, 32, 32}, {1, 5, 5, 32, 32, 32} },      // data to display "2"
 { {4, 2, 0, 32, 32, 32}, {6, 5, 0, 32, 32, 32} },      // data to display "3"
 { {1, 5, 0, 32, 32, 32}, {32, 32, 0, 32, 32, 32} },    // data to display "4"
 { {1, 2, 3, 32, 32, 32}, {6, 5, 0, 32, 32, 32} },      // data to display "5"
 { {1, 2, 3, 32, 32, 32}, {1, 5, 0, 32, 32, 32} },      // data to display "6"
 { {1, 7, 0, 32, 32, 32}, {32, 32, 0, 32, 32, 32} },    // data to display "7"
 { {1, 2, 0, 32, 32, 32}, {1, 5, 0, 32, 32, 32} },      // data to display "8"
 { {1, 2, 0, 32, 32, 32}, {6, 5, 0, 32, 32, 32} },      // data to display "9"
 { {32, 32, 0, 1, 7, 0}, {32, 32, 0, 1, 5, 0} },        // data to display "10"
 { {32, 32, 0, 32, 32, 0}, {32, 32, 0, 32, 32, 0} },    // data to display "11"
 { {32, 32, 0, 4, 2, 0}, {32, 32, 0, 1, 5, 5} },        // data to display "12"
 { {32, 32, 0, 4, 2, 0}, {32, 32, 0, 6, 5, 0} },        // data to display "13"
 { {32, 32, 0, 1, 5, 0}, {32, 32, 0, 32, 32, 0} },      // data to display "14"
 { {32, 32, 0, 1, 2, 3}, {32, 32, 0, 6, 5, 0} },        // data to display "15"
 { {32, 32, 0, 1, 2, 3}, {32, 32, 0, 1, 5, 0} },        // data to display "16"
};


void printbigchar(byte digit, byte col) { // This subroutine prints the big font characters on the LCD screen
 
 for (int i = 0; i < 2; i++) {            // count i from 0 to 1
   lcd.setCursor(col*4 , i);              // set LCD cursor at correct point
   for (int j = 0; j < 6; j++) {          // count j from 0 to 2
     lcd.write((byte)bignums[digit][i][j]);     // write proper block to LCD from array
   }
   lcd.write(254);                        // write an empty space
 }
 lcd.setCursor(col + 4, 0);               // move the cursor to the top line, col + 4
}


void setup(){
  lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  loadchars();
}
unsigned long secondCounter;

void loop()
{
  printbigchar(15, 0);
  printbigchar(15, 2);
  }

But I think I’m running out of memory. So far the program is using 37% of the memory And the clock program is using another 20%. Any ideas?

Ok never mind the "memory problem", there is none.

Ok, this is what i did.

Now, i want to make two dots, and make them blink, between the hour digits and the minute digits.

After that I want to make it work with RTC module.

After that I want to make the clock to set by a rotary encoder (push the encoder, make the hour digits blink, when turned to the left tha digits decreased, turned right, the digits increase, push it again the minute digits blink, when turned to the left tha digits decreased, turned right, the digits increase, push it again the digits stop blinking and the clock starts to work normally).

But for this two ideas, later. :smiley: