LAGSILVA
Published © CC BY-NC-ND

Talking Clock 2 - New Version (Bilingual: EN-PT)

This digital clock speaks the time in two languages (English or Portuguese).

IntermediateFull instructions provided2 hours5,739

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
DFRobot DFPlayer Mini MP3
×1
Seeed 4 Digit Display
×1
Adafruit Speaker: 3W, 4 Ohm
×1
PAM8403 Audio Amplifier 3W + 3W
Optional
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×3
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Verbose Text to Speech - NCH Software

Story

Read more

Custom parts and enclosures

MP3 Voice Files

MP3 - Voice Files

Code

Talking_Clock_2_English_Portuguese_V1_2.ino

Arduino
Main code of Talking Clock 2
/*     Talking Clock 2 (English-Portuguese) - V1.2
            Author: LAGSILVA - 17.Feb.2018
           (Arduino UNO-R3 & DFPlayer_Mini)
        ** New Library: DFRobotDFPlayerMini **
  --------------------------------------------------------
  Note: All MP3 files name must be numered as "/MP3/nnnn.mp3"
    Ex: "/MP3/0000.mp3", "/MP3/0001.mp3", "/MP3/0002.mp3", ...
*/

#include <SoftwareSerial.h>       // Library to support DFPlayer
#include <DFRobotDFPlayerMini.h>  // Library for DFPlayer (module to play MP3 files)
#include <TM1637Display.h>        // Library for TM1637 Display (4 digitis x 7 segments)
#include <Time.h>                 // Time Library
#include <TimeLib.h>
#include <EEPROM.h>               // Library to read/write on EEPROM

SoftwareSerial mySoftwareSerial(3, 4);    // RX, TX
DFRobotDFPlayerMini myMP3;

byte ajustaModo = 7;              // Switch of Mode
byte ajustaHora = 6;              // Switch of Hours
byte ajustaMinuto = 5;            // Switch of Minutes

byte hora, minuto, modo, ultimoMinuto, ultimaHora, dezHora, uniHora, idioma, ultimoIdioma, bloqueio, tipo;

int vol, pinVol = 0;              // Volume Control by POT (Arduino pin: A0)

// Module connection pins (Digital Pins)
#define CLK 10                    // Arduino Conection on Pin #10 = CLK of Display Module
#define DIO 11                    // Arduino Conection on Pin #11 = DIO of Display Module

TM1637Display display(CLK, DIO);

//
//      A
//     ---
//  F |   | B
//     -G-
//  E |   | C
//     ---
//      D
//

uint8_t dataWithColon[] = {
  0b10111111, // 0
  0b10000110, // 1
  0b11011011, // 2
  0b11001111, // 3
  0b11100110, // 4
  0b11101101, // 5
  0b11111101, // 6
  0b10000111, // 7
  0b11111111, // 8
  0b11101111, // 9
  0b00000000, // 10
};


void setup()
{

  idioma = EEPROM.read(0);            // Read the EEPROM the Language Status: (0 = English / 100 = Portuguese)
  ultimoIdioma = idioma;

  mySoftwareSerial.begin(9600);       // Set serial for DFPlayer-mini mp3 module
  myMP3.begin(mySoftwareSerial);      // Begin MP3

  myMP3.volume (28);                  // Set Volume (0-30max)

  myMP3.EQ(DFPLAYER_EQ_ROCK);         // Set EQ
  // myMP3.EQ(DFPLAYER_EQ_NORMAL);
  // myMP3.EQ(DFPLAYER_EQ_POP);
  // myMP3.EQ(DFPLAYER_EQ_JAZZ);
  // myMP3.EQ(DFPLAYER_EQ_CLASSIC);
  // myMP3.EQ(DFPLAYER_EQ_BASS);

  display.setBrightness (10);         // Set Brightness (0 to 15 Max)

  pinMode(ajustaModo, INPUT_PULLUP);
  pinMode(ajustaMinuto, INPUT_PULLUP);
  pinMode(ajustaHora, INPUT_PULLUP);

  modo = 0;
  ultimoMinuto = -1;
  ultimaHora = -1;

  myMP3.playMp3Folder (60 + idioma);  // Play the Setting Mode
  delay(3000);

}


void loop() {

  hora = hour();
  minuto = minute();

  dezHora = hora / 10;
  uniHora = hora % 10;

  display.showNumberDec(dezHora, true, 1, 0);
  display.setSegments(dataWithColon + uniHora, 1, 1);
  display.showNumberDec(minuto, true, 2, 2);

  if (bloqueio == 1) {
    delay(500);
    display.showNumberDec(uniHora, true, 1, 1);
    delay(500);
  }

  if (digitalRead(ajustaHora) == LOW && bloqueio == 0) {    //Setup of hours
    ultimaHora = -1;
    adjustTime(3600);
    delay(200);
  }

  if (digitalRead(ajustaMinuto) == LOW && bloqueio == 0) {  //Setup of Minutes
    ultimoMinuto = -1;
    adjustTime(60);
    delay(200);
  }

  if (digitalRead(ajustaModo) == LOW) { // Mode Setup
    modo += 1;
    modo = modo % 5;
    delay(200);

    if (modo == 0) {                    // Play "Set The Time" mode
      display.setBrightness(10);        // Turn "on" the display
      myMP3.playMp3Folder (60 + idioma);
      delay(4000);
      bloqueio = 0;
    }

    if (modo == 1) {                    // Play "Minute" mode
      display.setBrightness(0);         // Turn "off" the display
      ultimoMinuto = minuto;
      myMP3.playMp3Folder (61 + idioma);
      delay(4000);
      bloqueio = 1;
    }

    if (modo == 2) {                    // Play "Hour" mode
      ultimaHora = hora;
      myMP3.playMp3Folder (62 + idioma);
      delay(4000);
      bloqueio = 1;
    }

    if (modo == 3) {                    // Play "Press to Talk" mode
      myMP3.playMp3Folder (63 + idioma);
      delay(4000);
      bloqueio = 1;
    }

    if (modo == 4) {                    // Setup Language (English or Portuguese)
      myMP3.playMp3Folder (64 + idioma);
      delay(4000);
      bloqueio = 1;
    }

  }

  switch (modo) {

    case 1:                             // Play All Minutes

      if (minuto != ultimoMinuto) {

        ultimoMinuto = minuto;

        display.setBrightness(10);

        display.setSegments(dataWithColon + uniHora, 1, 1);

        tipo = 1;                       // Tipo: (1 = Hour / 0 = Minute)

        fala(hora);

        if (hora > 1) {
          myMP3.playMp3Folder(22 + idioma);     // Play "hours" / "horas"
          delay(1000);
        }

        if (hora <= 1) {
          myMP3.playMp3Folder(21 + idioma);     // Play "hour" / "hora"
          delay(1000);
        }

        if (minuto > 0) {

          myMP3.playMp3Folder(23 + idioma);     // Play "and" / "e"
          delay(500);

          tipo = 0;                     // Tipo: (1 = hour / 0 = minute)

          fala(minuto);

          if (minuto > 1) {
            myMP3.playMp3Folder (25 + idioma);  // Play "minutes"
            delay(1000);
          } else {
            myMP3.playMp3Folder (24 + idioma);  // Play "minute"
            delay(1000);
          }

        }

        display.setBrightness(0);

      }

      break;


    case 2:                         // Play only o'clock Hours

      if (hora != ultimaHora) {
        ultimaHora = hora;

        display.setBrightness(10);

        display.setSegments(dataWithColon + uniHora, 1, 1);

        tipo = 1;                   // Tipo: (1 = hour / 0 = minute)

        fala(hora);

        myMP3.playMp3Folder(26 + idioma);      // Play "o'clock" / "em ponto"
        delay(2000);

        if (hora >= 8 && hora <= 18) {
          for (int k = 1; k <= hora % 12; k++) {
            myMP3.playMp3Folder(65 + idioma); // Play "Bell Church" between 08:00hs to 18:00hs
            delay(2500);
          }
        }

        display.setBrightness(0);

      }

      break;


    case 3:       // Press Button to Talk Mode

      if (digitalRead(ajustaMinuto) == LOW || digitalRead(ajustaHora) == LOW && bloqueio == 1) { // Press button

        display.setBrightness(10);

        display.setSegments(dataWithColon + uniHora, 1, 1);

        tipo = 1;                   // Tipo: (1 = hour / 0 = minute)
        fala(hora);

        if (minuto == 0) {
          myMP3.playMp3Folder(26 + idioma);
        }

        if (minuto != 0) {

          myMP3.playMp3Folder(23 + idioma);     // Play "and" / "e"
          delay(500);

          tipo = 0;                  // Tipo: (1 = hour / 0 = minute)
          fala(minuto);

        }

        display.setBrightness(0);

      }

      break;


    case 4:       // Setup the Language (0 = English / 100 = Portuguese)

      if (digitalRead(ajustaMinuto) == LOW && bloqueio == 1) {  // Setting to English language
        idioma = 0;
        delay(200);
      }

      if (digitalRead(ajustaHora) == LOW && bloqueio == 1) {    // Setting to Portuguese language
        idioma = 100;
        delay(200);
      }

      if (ultimoIdioma != idioma) {
        EEPROM.update(0, idioma);
        ultimoIdioma = idioma;
        myMP3.playMp3Folder (64 + idioma);
        delay(2000);
      }

      break;

  }

}


void fala(byte tempo) {                         // Speak the Time

  byte dezTempo = tempo / 10 * 10;
  byte uniTempo = tempo % 10;


  if (idioma == 0) {                            // English language

    if (tempo <= 19) {
      myMP3.playMp3Folder(tempo + idioma);
      delay(1000);
    }

    if (tempo >= 20) {

      myMP3.playMp3Folder(dezTempo + idioma);
      delay(1000);

      if (tempo % 10 != 0) {
        myMP3.playMp3Folder(uniTempo + idioma);
        delay(1000);
      }

    }

  }


  if (idioma == 100) {                          // Portuguese language

    if (tipo == 0) {                            // Play Minutes in Portuguese - Tipo: (1 = hour / 0 = minute)

      if (tempo <= 19) {
        myMP3.playMp3Folder(tempo + idioma);
        delay(1000);
      }

      if (dezTempo >= 20) {
        myMP3.playMp3Folder(dezTempo + idioma);
        delay(1000);

        if (tempo % 10 != 0) {                      // If language is Portuguese
          myMP3.playMp3Folder(123);                 // Play "e"
          delay(500);
          myMP3.playMp3Folder(uniTempo + idioma);
          delay(1000);
        }

      }

    }


    if (tipo == 1) {                                // Play Hours in Portuguese

      if (tempo > 2 && tempo <= 20 || tempo == 0) {
        myMP3.playMp3Folder(tempo + idioma);
        delay(1000);
      }

      if (tempo == 1 || tempo == 2) {               // Play "uma" - "duas"
        myMP3.playMp3Folder(126 + uniTempo);
        delay(1000);
      }

      if (tempo >= 21) {
        myMP3.playMp3Folder(dezTempo + idioma);
        delay(1000);

        myMP3.playMp3Folder(123);                   // Play "e"
        delay(500);

        if (tempo == 21 || tempo == 22) {
          myMP3.playMp3Folder(126 + uniTempo);
          delay(1000);
        } else {
          myMP3.playMp3Folder(uniTempo + idioma);
          delay(1000);
        }

      }

    }

  }

}

Credits

LAGSILVA

LAGSILVA

12 projects • 97 followers
I'm a Mechanical Engineer and an enthusiastic Maker. I like to create and code my projects using the Arduino.
Contact

Comments

Add projectSign up / Login