LAGSILVA
Published © CC BY-NC-ND

Text Clock Bilingual (EN+PT) with Arduino

Text Clock with Arduino that can display the time in two languages: English or Portuguese.

BeginnerShowcase (no instructions)30 minutes3,568

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
DFRobot - LCD Keypad Shield for Arduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Text_Clock_LCD_in_English_or_Portuguese_V1_0.ino

Arduino
/*
     Project:   Text Clock in English or Portuguese
     Hardware:  Arduino UNO R3 - LCD Keypad Shield
     Version:   Rev 1.0 (International Standard Notation of Time)
     Date:      12.Jul.2019
     Author:    LAGSILVA
     License:   CC BY-NC-ND 4.0
                (Attribution-NonCommercial-NoDerivatives 4.0 International)
*/

#include <LiquidCrystal.h>      // LCD library
#include <Time.h>               // Time library
#include <TimeLib.h>

// LiquidCrystal lcd(rs, enable, d4, d5, d6, d7)
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// Global Variables
byte hh, mm, ss;
byte hTens, hUnits, mTens, mUnits;
bool inicio = true;
String textH, textM;
byte k, ok;
byte language;                  //(0 = English / 1 = Portuguese)

byte botoes = 5;
int estadoBotoes = 0;

#define btnRight 1
#define btnLeft 2
#define btnUp 3
#define btnDown 4
#define btnSelect 5
#define btnNone 6

byte clock0[8] = {31, 21, 27, 10, 10, 27, 17, 31};
byte clock1[8] = {31, 21, 31, 10, 10, 27, 17, 31};
byte clock2[8] = {31, 17, 27, 14, 14, 27, 17, 31};
byte clock3[8] = {31, 17, 27, 10, 10, 31, 21, 31};

String num1[] = {
  "", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN",
  "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN",
  "", "UM", "DOIS", "TRES", "QUATRO", "CINCO", "SEIS", "SETE", "OITO", "NOVE", "DEZ",
  "ONZE", "DOZE", "TREZE", "QUATORZE", "QUINZE", "DEZESSEIS", "DEZESSETE", "DEZOITO", "DEZENOVE"
};

String num2[] = {
  "", "TWENTY", "THIRTY", "FOURTY", "FIFTY", " ",
  "", "VINTE", "TRINTA", "QUARENTA", "CINQUENTA", " E "
};


void setup() {

  language = 0;                           //(0 = English / 1 = Portuguese)

  lcd.createChar(0, clock0);
  lcd.createChar(1, clock1);
  lcd.createChar(2, clock2);
  lcd.createChar(3, clock3);

  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  lcd.clear();

  lcd.setCursor(3, 0);
  lcd.print("TEXT CLOCK");
  lcd.setCursor(0, 1);
  lcd.print("by LAGSILVA 2019");
  delay(2000);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print(">EN:PT");
  lcd.setCursor(1, 1);
  lcd.print("00:00");

  lcd.setCursor(11, 0);
  lcd.print("LANG.");
  lcd.setCursor(11, 1);
  lcd.print("HH:MM");

  while (ok == 0) {

    botoes = lerBotoes();

    if (botoes == btnRight) {   // Set to Portuguese language
      lcd.setCursor(0, 0);
      lcd.print(" ");
      lcd.setCursor(6, 0);
      lcd.print("<");
      lcd.setCursor(6, 0);
      lcd.blink();
      language = 1;
    }

    if (botoes == btnLeft) {    // Set to English language
      lcd.setCursor(6, 0);
      lcd.print(" ");
      lcd.setCursor(0, 0);
      lcd.print(">");
      lcd.setCursor(0, 0);
      lcd.blink();
      language = 0;
    }

    if (botoes == btnUp) {      // Set HOUR
      adjustTime(3600);
      adjustTime(-second());
      hh = hour();
      if (hh >= 10) {
        lcd.setCursor(1, 1);
        lcd.print(hh);
      }
      else {
        lcd.setCursor(1, 1);
        lcd.print("0");
        lcd.print(hh);
      }
      lcd.setCursor(0, 1);
      lcd.blink();
    }

    if (botoes == btnDown) {    // Set MINUTE
      adjustTime(60);
      adjustTime(-second());
      hh = hour();
      if (hh >= 10) {
        lcd.setCursor(1, 1);
        lcd.print(hh);
      }
      else {
        lcd.setCursor(1, 1);
        lcd.print("0");
        lcd.print(hh);
      }
      mm = minute();
      if (mm >= 10) {
        lcd.setCursor(4, 1);
        lcd.print(mm);
      }
      else {
        lcd.setCursor(4, 1);
        lcd.print("0");
        lcd.print(mm);
      }
      lcd.setCursor(6, 1);
      lcd.blink();
    }

    if (botoes == btnSelect) {
      ok = 1;
      lcd.noBlink();
      lcd.clear();
      adjustTime(-second());
    }
  }

}


int lerBotoes() {           // Buttons reading

  delay(120);

  estadoBotoes = analogRead(0);
  if (estadoBotoes > 1000) return btnNone;
  if (estadoBotoes < 50)   return btnRight;
  if (estadoBotoes < 250)  return btnUp;
  if (estadoBotoes < 450)  return btnDown;
  if (estadoBotoes < 650)  return btnLeft;
  if (estadoBotoes < 850)  return btnSelect;
  return btnNone;           // Return NONE when all options fails

}


void loop() {

  hh = hour();
  mm = minute();
  ss = second();

  if (ss == 0 || inicio == true) {

    inicio = false;
    lcd.clear();

    // Print HOUR
    if (hh >= 20) {
      hTens = hh / 10;
      hUnits = hh % 10;
      textH = String(num2[hTens - 1 + 6 * language]) + " " + String(num1[hUnits + 20 * language]) + " ";
      if (language == 1) {
        if (hh == 20) {
          textH = "VINTE ";
        }
        if (hh == 21) {
          textH = "VINTE UMA ";
        }
        if (hh == 22) {
          textH = "VINTE DUAS ";
        }
      }
      if (language == 1 && mm > 0) {
        textH = textH + "E";
      }
    }
    if (hh <= 19) {
      hTens = hh;
      textH = String(num1[hTens + 20 * language]) + " ";
      if (hh == 0) {
        textH = "ZERO ";
      }
      if (hh == 1) {
        textH = "UMA ";
      }
      if (hh == 2) {
        textH = "DUAS ";
      }
      if (language == 1 && mm > 0) {
        textH = textH + "E";
      }
    }
    lcd.setCursor(0, 0);
    lcd.print(textH);

    // Print MINUTE
    if (mm >= 20) {
      mTens = mm / 10;
      mUnits = mm % 10;
      textM = String(num2[mTens - 1 + 6 * language]) + num2[5 + 6 * language] + String(num1[mUnits + 20 * language]) + " ";
      if (mm == 44 || mm == 54 || mm == 55 || mUnits == 0) {
        textM = String(num2[mTens - 1 + 6 * language]) + " " + String(num1[mUnits + 20 * language]) + " ";
      }
    } else {
      mTens = mm;
      textM = String(num1[mTens + 20 * language]) + " ";
      if (mm == 0 && language == 0) {
        textM = "HUNDRED";
      }
      if (hh >= 2 && mm == 0 && language == 1) {
        textM = "HORAS";
      }
      if (hh <= 1 && mm == 0 && language == 1) {
        textM = "HORA";
      }
    }
    lcd.setCursor(0, 1);
    lcd.print(textM);

    delay(1000);
  }

  // HOURGLASS plotting
  lcd.setCursor (13, 0);
  lcd.write(byte(k));
  k = (k + 1) % 4;
  delay(125);

  // Print SECOND
  lcd.setCursor(14, 0);
  if (ss < 10) {
    lcd.print("0");
  }
  lcd.print(ss);

}

Credits

LAGSILVA

LAGSILVA

21 projects • 329 followers
Coding, Electronic Prototyping with Arduino and Data Analysis are my hobbies.

Comments