Feedback!

Heart Matrix Clock

Views: 4455 Difficulty: 3 Status: Development
Heart_rtc_clock_main

Connecting the MCP79410 real-time clock chip and our Heart Matrix you can show the time with love.

We turn our heart matrix LED display into a clock using an Arduino and the MCP79410 real time clock chip. This tutorial will show you how to read the time from the MCP79410 into an Arduino and send it out to the Heart Matrix. Don't worry if you don't have a heart matrix, you could use the code we provide to display the time on any kind of display you choose, or just to trigger other actions in your code. The MCP79410 requires an oscillator, a 3.3 volt coin-cell lithium battery, and it communicates with the Arduino over the I2C protocol. The I2C protocol calls for 2.2K Ohm pull-up resistors on the SDA and SCL lines. We provide a schematic and EAGLE board file for an SMD version of this circuit. We use the MCP79410 in a ton of projects see them all at the tag page: MCP79410 . We also sell clock-shaped a breakout board for the MCP79410. Or if you want to build it yourself, Adafruit has a nice through-hole soldering kit for this chip, as well as an awesome tutorial.

Heart Clock, Arduino and DS1307

Heart_rtc_clock
The heart clock hooked up using the Adafruit breakout board for the DS1307 and an Arduino.

Heart Clock Video

Using the DS1307 breakout board from adafruit we turn the Heart Matrix into a Love Clock! You can too, check out the code below...

Arduino Code for Real time clock MCP79410 chip and LED Heart Matrix

This code displays the time on our heart matrix LED Display using the MCP79410 chip. Because we are using the RTC chip we can power down without needing to set the time again on startup. (Sorta what we expect from a clock nowadays, but it wasn't always that way!) The heart of the program is this code:
 if (millis() - last_update > 1000){
    last_update = millis();
    stime = "  ";    
    byte a_hour = clock.hour24();
    String a_hour_s = String(a_hour);
    int hour_int = a_hour_s.toInt();
    String ampm = "am";
    if (!show_24_hours && hour_int > 12){
      ampm = "pm";
      hour_int -= 12;
      a_hour_s = String(hour_int);
    }
    if (a_hour == 0) stime += String(12); 
    else stime += a_hour_s;  
    stime += ":";
    byte a_min = clock.minute();
    if (a_min < 10) stime += String(0);
    stime += String(a_min);
    stime += ":";
    byte a_sec = clock.second();
    if (a_sec < 10) stime += String(0);
    stime += String(a_sec);
    if(!show_24_hours) stime += ampm;
    hm.set_message(stime);
  }
To talk to the RTC chip we use the standard Arduino wire library. You will also need libraries for the MCP79410, the Heart Matrix, and the MSTimer2 all downloadable below!
/* LucidTronix Heart Matrix.
 * A clock using the heart matrix's 
 * on board MCP79410 real time clock chip
 * See the tutorial at: 
 * http://lucidtronix.com/tutorials/36 */
 
#include <Wire.h>
#include <MsTimer2.h>
#include <HeartMatrix.h>
#include <MCP79410.h>

String stime = "";
unsigned long last_update = 0;
boolean show_24_hours = false;
HeartMatrix hm = HeartMatrix(5,6,7); // dataPin is on 5, Latch is on 6, and clock is on 7
MCP79410 clock = MCP79410();

void displayer2(){  
  hm.displayer();
}

void setup()
{
   Wire.begin(); 
   //clock.setDateTime(__DATE__,__TIME__);
   MsTimer2::set(1,displayer2); 
   MsTimer2::start(); 
   pinMode(10, INPUT);
}
 
void loop(){
 hm.on();
 hm.set_scroll_wait(max(30, analogRead(0)/6)); 

 if (millis() - last_update > 1000){
    last_update = millis();
    stime = "  ";    
    byte a_hour = clock.hour24();
    String a_hour_s = String(a_hour);
    int hour_int = a_hour_s.toInt();
    String ampm = "am";
    if (!show_24_hours && hour_int > 12){
      ampm = "pm";
      hour_int -= 12;
      a_hour_s = String(hour_int);
    }
    if (a_hour == 0) stime += String(12); 
    else stime += a_hour_s;  
    stime += ":";
    byte a_min = clock.minute();
    if (a_min < 10) stime += String(0);
    stime += String(a_min);
    stime += ":";
    byte a_sec = clock.second();
    if (a_sec < 10) stime += String(0);
    stime += String(a_sec);
    if(!show_24_hours) stime += ampm;
    hm.set_message(stime);
  }
  
  if(digitalRead(10) == HIGH && millis() - last_update > 500){
    last_update = millis();
    show_24_hours = !show_24_hours;
  }
}

Heart Matrix Arduino Library

MCP79410 Real Time Clock Arduino Library

MS Timer2 Library

Download the MSTimer2 Library. Unzip and place in your Arduino libraries folder.
Click Here to Download: MS Timer2 Library

Parts

Title Description # Cost Link Picture
Heart Matrix Kit The heart matrix kit. Shift register based wearable heart-shaped LED display. 1 $17.95 Link Heart_matrix_baggy
Clock IC RTC DS1307 Serial 512K 8-SOIC I²C, 2-Wire Serial Leap Year, NVSRAM, Square Wave Output Value: 4.5 V ~ 5.5 V 1 $3.53 Link 8-soic_751
Permalink: http://lucidtronix.com/tutorials/36
Combine an electret microphone, Arduino and a heart matrix for a sound-sensitive wearable device....
Two LED matrices give 70 LEDs to light up a necklace with messages....
Standalone programmable Heart-Shaped LED display....
The heartduino is a heart-shaped arduino clone complete with onboard sensors and a 70 pixel LED matri...
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Build your own clock with the MCP79410 chip and 4 7-Segment LED modules....
Wearable digital compass displays the direction in green LEDs....
A wearable real-time clock with vibrant color display....