# Use Doomsday Clock Shield as a Clock ?

I’ve put together the first stage of a permanent project using a Doomsday Clock Shield (TMP36 analog temperature sensor installed to use as a digital thermometer) and a Arduino Uno R3 but now would like to use the clock shield as a digital thermometer and digital clock if possible (display switching back from one to the other at a set time). I have a DS1307 Real Time Clock breakout board kit that I assume could be used with the clock shield for the digital clock I require.

If it’s only possible to have the project running as a 12HR format clock thats fine. Here is the sketch I’m using for Doomsday Clock Shield as a digital thermometer -

/* Sensor test sketch
2012 Aug 06 Man 21:49 HKT Devon hack for Samurai Circuits Doomsday clock
*/

#include <Doomsday.h>

Doomsday doom;

#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!

//TMP36 Pin Variables
int tempPin = 0; //the analog pin the TMP36’s Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

// compute temperature T = D / P R + C - Z
// e = 1 / P R
// f = C - Z
// T = D * e + f
//
// K Kelvins = temperature unit
// dK deci Kelvins = Kelvins / 10
// V Volts = voltage unit
// mV milli Volts = Volts / 1000
//
// TMP36 Analog Temperature sensor
// R TMP36 analog response = 10 mV / ? = 10 mV / Kelvin = 1 mV / dK
// Z TMP36 analog offset = 0.5 V = 500 mV = 500 dK
// C Kelvins - degrees Celsius = 273.15 K = 2731.5 dK
//
// ADC Analog to Digital Converter
// Dref ADC digital output for Vref = exclusive upper bound = 1024
// P ADC digital precision = Dref / Vref = 1024 U / 3.3 V = 1024 U / 3300 mV
// U ADC digital output native unit = 1
// D ADC digital output data in native units = an integer 0…1023
// T temperature in dK = D * e + f = an integer 0000…9999
//
// fixed point 32-bit unsigned integer arithmetic
// 1000000 scale six decimal places
// 3222656 scale * Vref / Dref
// 2731500000 = scale * C = Celsius to Kelvin
// -500000000 = scale * Z = TMP36 analog offset
// +500000 = scale / 2 = add half to round instead of floor
// ==========
// 2232000000 scale * (+ 2731.5 - 500 + 0.5)
//
#define SCALE 1000000
#define E 3222656
#define F 2232000000
//
#define ANALOG_TO_DECI_KELVIN(D) ((((D) * E) + F) / SCALE)
//
// Analog Devices’ Low Voltage Temperature Sensors TMP35/TMP36/TMP37 data sheet at
// http://www.Analog.com/static/imported-files/data_sheets/TMP35_36_37.pdf
// … TMP36 … -40°C to +125°C … 750 mV output at 25°C …
// … Temp °C = 100*(reading in V) - 50 …

void setup(void) {
#if 0
// We’ll send debugging information via the Serial monitor
Serial.begin(9600);
#else
doom.begin (500);
#endif

// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);

}

void loop(void) {
#if 0

// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;

// now convert to Fahrenheight
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");

delay(10);
#else
static char phase = 0;
static unsigned long old_millis = millis (), new_millis;
new_millis = millis ();
if ((old_millis ^ new_millis) & 2048)
phase = (phase + 1) % 3;
old_millis = new_millis;
switch (phase) {

case 2: doom.printd ("%F\33F"); break;
}
#endif
}

This is my code for a simple RTC integration. How does one get the photo resister to work?

// Doomsday clock example - Ticking HH:MM:SS
// Copyright (c) 2012 Devon Sean McCullough
//
// This example is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
//
// See file LICENSE.txt for further informations on licensing terms.

#include <Doomsday.h>
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t

Doomsday doom;

void setup ()
{

doom.begin (72); // 72 ms ~~ 14 Hz
Serial.begin(9600);
while (!Serial) ; // wait until Arduino Serial Monitor opens
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
Serial.println(“Unable to sync with the RTC”);
else
Serial.println(“RTC has set the system time”);
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" “);
Serial.print(day());
Serial.print(” “);
Serial.print(month());
Serial.print(” ");
Serial.print(year());
Serial.println();
doom.setClock (second() , minute(), hour(), day(), month(), year());

}

void loop ()
{
static unsigned int dots = 0;
dots = (dots << 1) | !(dots & 4);
doom.secondsTick ();
//doom.printd ("%H:%M:%S", dots);
doom.printd ("%H%(:%)%M%(:%)%S", dots);
//doom.printd (":H:E:%[L%]LO%(O%)", dots);

}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print(‘0’);
Serial.print(digits);
}