/* LiquidCrystal Library - Hello World Demonstrates the use a 20x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. This sketch prints "Hello World!" to the LCD and shows the time. 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 This example code is in the public domain. */ // Include the library code: #include // Initialize the library with the numbers of the interface pins // rs, enable, d0, d1, d2, d3, d4, d5, d6, d7 LiquidCrystal lcd(12, 13, 4, 5, 6, 7, 8, 9, 10, 11); uint8_t rows = 2; uint8_t cols = 20; char cln =' '; unsigned long startTime; unsigned long partTime; // Double height numeric character set 3 byte zero[8] = { B11110, B10010, B10010, B10010, B10010, B10010, B10010, B10010, }; byte one[8] = { B10000, B10000, B10000, B10000, B10000, B10100, B10100, B11111, }; byte two[8] = { B11100, B10000, B10000, B10000, B10000, B10000, B10000, B10000, }; byte three[8] = { B10010, B10010, B10010, B10010, B10010, B10010, B11110, B00000, }; byte four[8] = { B00100, B00100, B00100, B00100, B00100, B00100, B00100, B00100, }; byte five[8] = { //colon B00000, B00000, B00000, B00100, B00000, B00000, B00000, B00000, }; byte six[8] = { B11111, B00001, B00001, B00001, B00001, B00001, B11111, B00000, }; byte seven[8] = { B11110, B00010, B00010, B00010, B00010, B00010, B00010, B00010, }; // Double height numeric character set 3 byte nums[10][2] = { {0,3}, //0 {4,'|'}, //1 {7,'['}, //2 {7,6}, //3 {1,'|'}, //4 {2,6}, //5 {2,21}, //6 {7,'|'}, //7 {0,21}, //8 {0,6} }; //9 void setup() { // Set up the LCD's number of columns and rows: lcd.begin(cols, rows); // Print a message to the LCD. lcd.print("hello, world!"); delay(2000); // Program our 8 programmable characters lcd.createChar(0, zero); lcd.createChar(1, one); lcd.createChar(2, two); lcd.createChar(3, three); lcd.createChar(4, four); lcd.createChar(5, five); lcd.createChar(6, six); lcd.createChar(7, seven); startTime = ((((long)12*60)+32)*60+00); // initialise time // but would need to get real time from somewhere to make display useful lcd.clear(); lcd.setCursor(0, 1); lcd.print("The time is"); } // Display a double height digit in column specified void doubleHeight(uint8_t n, byte col) { int i; if ((col>=0) & (col < cols) & (n>=0) & (n<10)) for (i=0; i<2; i++ ) { lcd.setCursor(col,i); lcd.write(nums[n][i]); } } void loop() { // Toggle hms separator (colon) cln = char(' ')+char(5) - cln; partTime = startTime + millis()/1000; // wraps back to start after 50 days or so! // (time keeping accuracy dependant upon accuracy of Arduino timer) // Print each digit, starting at least significant // and shift partTime one digit doubleHeight(partTime % 10, 19); // seconds partTime=partTime/10; doubleHeight(partTime % 6, 18); // tens of seconds partTime=partTime/6; // display minutes separator lcd.setCursor(17, 0); lcd.write(cln); lcd.setCursor(17, 1); lcd.write(cln); doubleHeight(partTime % 10, 16); // minutes partTime=partTime/10; doubleHeight(partTime % 6, 15); // tens of minutes partTime=partTime/6; // display hours seperator lcd.setCursor(14, 0); lcd.write(cln); lcd.setCursor(14, 1); lcd.write(cln); partTime = partTime % 24; doubleHeight(partTime % 10, 13); // hours partTime=partTime/10; doubleHeight(partTime % 6, 12); // tens of hours partTime=partTime/6; delay(492); // loop every half second or so // (delay doesn't affect time keeping, just colon flash rate) }