Members | Sign In
Legacy MOVI User Community Forum (readonly) > MOVI Projects
avatar

Clock Demo at Maker Faire

posted May 27, 2016 23:47:43 by BillSherman
I really liked the clock function demo that was used to demonstrate the MOVI at Maker Faire, SF Bay Area. I imagine a real time clock such as a DS1307 was used to keep time. Could someone post the sketch so we could build one?
page   1
2 replies
avatar
Bertrand said Jun 09, 2016 00:22:19
Hello Bill. I will post it shortly for everyone to enjoy. It indeed uses a DS1307 real time clock module.
avatar
Bertrand said Jun 10, 2016 19:39:02
Bill, as promised, here is the code for the talking clock. It can be used with or without RTC module. Let me know if you have any question.


#include <SoftwareSerial.h> // MOVI needs SoftwareSerial
#include <Wire.h>           // The RTC module is a 2-wire interface
#include "MOVIShield.h"     // Include MOVI library
#include "RTClib.h"         // Real Time Clock Library. Download at https://github.com/adafruit/RTClib
//
// This example implements a talking clock. 
// If you have a real time clock module such as a DS1307, connect:
//        DS1307       Uno R3
//          GND   ->    GND
//          5V    ->    5V
//          SDA   ->    SDA
//          SDC   ->    SDC 
//  AND Comment out the following line

// #define HARD_RTC  1         // 1 if hardware real time clock is present

// If you don't have an RTC clock, you can use the Uno internal clock BUT will have to upload the sketch at each power on 
// to get the exact time and date. 

MOVI recognizer(true);    // Get a MOVI object, true enables serial monitor interface, rx and tx can be passed as parameters for alternate communication pins
#ifdef HARD_RTC 
RTC_DS1307 rtc;           // Real Time Clock using the DS1307 Chip
#else
RTC_Millis rtc;        // Software only RTC. No hardware
#endif

char monthsOfTheYear[12][12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
short int Timer = 0; 
long      TimerEndTime;     // Timer end time when set

void setup()  
{
#ifdef HARD_RTC
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  // Comment out the first time to set the time and date on the RTC module. After this,
  // it will remember it via it non-volatile memory. 
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
#else
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
#endif

  recognizer.init();      // Initialize MOVI (waits for it to boot)

  recognizer.callSign("Arduino"); // Train callsign Arduino (may take 20 seconds)
  recognizer.addSentence(F("What time is it ?"));        // Add sentence 1
  recognizer.addSentence(F("What is the time ?"));        // Add sentence 2
  recognizer.addSentence(F("What is the date ?"));       // Add sentence 3
  recognizer.addSentence(F("What is today ?"));          // Add sentence 4
  recognizer.addSentence(F("Cancel timer"));             // Add sentence 5
  recognizer.addSentence(F("Is timer set ?"));           // Add sentence 6
  recognizer.addSentence(F("How much time remaining ?"));     // Add sentence 7
  recognizer.addSentence(F("Set Timer for 1 minute"));    // Add sentence 8
  recognizer.addSentence(F("Set Timer for 2 minutes"));   // Add sentence 9
  recognizer.addSentence(F("Set Timer for 3 minutes"));   // Add sentence 10
  recognizer.addSentence(F("Set Timer for 4 minutes"));   // Add sentence 11
  recognizer.addSentence(F("Set Timer for 5 minutes"));   // Add sentence 12

  recognizer.train();                          // Train (may take 20seconds) 

  recognizer.say("Real Time Clock Starting");
  // recognizer.setThreshold(10);			// uncomment and set to a higher value (valid range 2-95) if you have a problems due to a noisy environment.
}


void loop() // run over and over
{
  DateTime     now = rtc.now();         // Get real time
  
  signed int   res = recognizer.poll(); // Get result from MOVI, 0 denotes nothing happened, negative values denote events (see docs)

  // Tell current time
  if (res==1 | res==2) {                     // Sentence 1 & 2
    if ( now.hour() > 12) 
      recognizer.say("It's " + String(now.hour()-12) + " " + ( now.minute() < 10 ? "O" : "" ) + String(now.minute()) + "P M" ); // Speak the time
    else
      recognizer.say("It's " + String(now.hour())    + " " + ( now.minute() < 10 ? "O" : "" ) + String(now.minute()) + "A M" ); // Speak the time
  } 

  // Tell current date
  if (res==3 || res==4) {                    // Sentence 3 & 4
   recognizer.say("Today is" + String(monthsOfTheYear[now.month()-1]) + String(now.day()) + " " + String(now.year()));
  }

  // Cancel Timer
  if (res==5) {                    // Sentence 6
    Timer = 0; 
    recognizer.say("Timer was cancelled");
  }

  // Check Timer Status
  if (res==6 || res==7 ) { 
     if (Timer) {
      recognizer.say("Timer is set"); 
      long left = TimerEndTime - now.secondstime();
      if ( left < 60 ) 
        recognizer.say("There is " + String(left) + " seconds left");
      else
        recognizer.say("There is " + String((int) (left/60)) + "minutes and " + String(left%60) + "seconds left");
     }
     else
      recognizer.say("Timer is not set");
  }

  // Set timer
  if (res>=8 && res <=12) {
    Timer = 1; 
    TimerEndTime = now.secondstime() + (res-7)*60 ;
    recognizer.say("Timer set for " + String(res-7) + " minutes");    
  }

  if ( Timer  && ( now.secondstime() >= TimerEndTime) ) {
    Timer = 0; 
    recognizer.say("Time is up!");
  }

}


Login below to reply: