Hello there. I'm trying to build an Arduino clock. I have the basic code:
#include<Time.h>
#include<TimeAlarm.h>
#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"
{ {32, 32, 0, 1, 7, 0}, {32, 32, 0, 32, 32, 0} }, // data to display "17"
{ {32, 32, 0, 1, 2, 0}, {32, 32, 0, 1, 5, 0} }, // data to display "18"
{ {32, 32, 0, 1, 2, 0}, {32, 32, 0, 6, 5, 0} }, // data to display "19"
{ {4, 2, 0, 1, 7, 0}, {1, 5, 5, 1, 5, 0} }, // data to display "20"
{ {4, 2, 0, 32, 32, 0}, {1, 5, 5, 32, 32, 0} }, // data to display "21"
{ {4, 2, 0, 4, 2, 0}, {1, 5, 5, 1, 5, 5} }, // data to display "22"
{ {4, 2, 0, 4, 2, 0}, {1, 5, 5, 6, 5, 0} }, // data to display "23"
{ {4, 2, 0, 1, 5, 0}, {1, 5, 5, 32, 32, 0} }, // data to display "24"
{ {4, 2, 0, 1, 2, 3}, {1, 5, 5, 6, 5, 0} }, // data to display "25"
{ {4, 2, 0, 1, 2, 3}, {1, 5, 5, 1, 5, 0} }, // data to display "26"
{ {4, 2, 0, 1, 7, 0}, {1, 5, 5, 32, 32, 0} }, // data to display "27"
{ {4, 2, 0, 1, 2, 0}, {1, 5, 5, 1, 5, 0} }, // data to display "28"
{ {4, 2, 0, 1, 2, 0}, {1, 5, 5, 6, 5, 0} }, // data to display "29"
{ {4, 2, 0, 1, 7, 0}, {6, 5, 0, 1, 5, 0} }, // data to display "30"
{ {4, 2, 0, 32, 32, 0}, {6, 5, 0, 32, 32, 0} }, // data to display "31"
{ {4, 2, 0, 4, 2, 0}, {6, 5, 0, 1, 5, 5} }, // data to display "32"
{ {4, 2, 0, 4, 2, 0}, {6, 5, 0, 6, 5, 0} }, // data to display "33"
{ {4, 2, 0, 1, 5, 0}, {6, 5, 0, 32, 32, 0} }, // data to display "34"
{ {4, 2, 0, 1, 2, 3}, {6, 5, 0, 6, 5, 0} }, // data to display "35"
{ {4, 2, 0, 1, 2, 3}, {6, 5, 0, 1, 5, 0} }, // data to display "36"
{ {4, 2, 0, 1, 7, 0}, {6, 5, 0, 32, 32, 0} }, // data to display "37"
{ {4, 2, 0, 1, 2, 0}, {6, 5, 0, 1, 5, 0} }, // data to display "38"
{ {4, 2, 0, 1, 2, 0}, {6, 5, 0, 6, 5, 0} }, // data to display "39"
{ {1, 5, 0, 1, 7, 0}, {32, 32, 0, 1, 5, 0} }, // data to display "40"
{ {1, 5, 0, 32, 32, 0}, {32, 32, 0, 32, 32, 0} }, // data to display "41"
{ {1, 5, 0, 4, 2, 0}, {32, 32, 0, 1, 5, 5} }, // data to display "42"
{ {1, 5, 0, 4, 2, 0}, {32, 32, 0, 6, 5, 0} }, // data to display "43"
{ {1, 5, 0, 1, 5, 0}, {32, 32, 0, 32, 32, 0} }, // data to display "44"
{ {1, 5, 0, 1, 2, 3}, {32, 32, 0, 6, 5, 0} }, // data to display "45"
{ {1, 5, 0, 1, 2, 3}, {32, 32, 0, 1, 5, 0} }, // data to display "46"
{ {1, 5, 0, 1, 7, 0}, {32, 32, 0, 32, 32, 0} }, // data to display "47"
{ {1, 5, 0, 1, 2, 0}, {32, 32, 0, 1, 5, 0} }, // data to display "48"
{ {1, 5, 0, 1, 2, 0}, {32, 32, 0, 6, 5, 0} }, // data to display "49"
{ {1, 2, 3, 1, 7, 0}, {6, 5, 0, 1, 5, 0} }, // data to display "50"
{ {1, 2, 3, 32, 32, 0}, {6, 5, 0, 32, 32, 0} }, // data to display "51"
{ {1, 2, 3, 4, 2, 0}, {6, 5, 0, 1, 5, 5} }, // data to display "52"
{ {1, 2, 3, 4, 2, 0}, {6, 5, 0, 6, 5, 0} }, // data to display "53"
{ {1, 2, 3, 1, 5, 0}, {6, 5, 0, 32, 32, 0} }, // data to display "54"
{ {1, 2, 3, 1, 2, 3}, {6, 5, 0, 6, 5, 0} }, // data to display "55"
{ {1, 2, 3, 1, 2, 3}, {6, 5, 0, 1, 5, 0} }, // data to display "56"
{ {1, 2, 3, 1, 7, 0}, {6, 5, 0, 32, 32, 0} }, // data to display "57"
{ {1, 2, 3, 1, 2, 0}, {6, 5, 0, 1, 5, 0} }, // data to display "58"
{ {1, 2, 3, 1, 2, 0}, {6, 5, 0, 6, 5, 0} }, // data to display "59"
{ {1, 2, 3, 1, 7, 0}, {1, 5, 0, 1, 5, 0} }, // data to display "60"
};
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()
{
Serial.begin(9600);
setTime(20,26,0,1,1,11); //Set time to Saturday 20:26:00 Jan 1 2011
lcd.begin(LCD_WIDTH,LCD_HEIGHT);
loadchars();
}
unsigned long secondCounter;
void loop(){
digitalClockDisplay();
Alarm.delay(1000); //waith one second between clock display
}
void digitalClockDisplay()
{
//digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits<10)
Serial.print('0');
Serial.print(digits);
printbigchar(hour(),0);
printbigchar(minute(),2);
}