3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Lunchtime Clock

Step 7Program the chip

Program the chip

You will need to install the RTClib library for your code to work. Instructions to do this are on Ladyada's page.

Download lunchtime_clock.zip, uncompress it and then upload the lunchtime_clock.pde code onto your chip.

If you don't feel like downloading the file, here is the code:

// Lunchtime Clock
// by Randy Sarafan
//
// Slows down 20% at 11 and speeds up 20% at 11:48 until it hits 1.
// The rest of the time the clock goes at normal speed
//
// Do what you want with this code. Just make certain that whatever you do, it is awesome.
//

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

int clockpin = 9;
int clockpin1 = 10;

void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
}

void loop () {

DateTime now = RTC.now();

TurnTurnTurn(1000);


if (now.hour() == 11) {
for (int i = 0; i < 1800; i++) {
TurnTurnTurn(800);
}

for (int i = 0; i < 1800; i++) {
TurnTurnTurn(1200);
}
}
}

int TurnTurnTurn(int TimeToWait){

analogWrite(clockpin, 0);
analogWrite(clockpin1, 124); // sets the value (range from 0 to 255)
delay(TimeToWait);

analogWrite(clockpin, 124);
analogWrite(clockpin1, 0);
delay(TimeToWait);

}


« Previous StepDownload PDFView All StepsNext Step »
1 comment
Jan 18, 2011. 8:01 AMPedroDiogo says:
First of all, nice project.

However I was able to detect a flaw in your code. You are only using the RTC for checking the actual hour, however the delay between each second on the clock is controlled by the clock on the Arduino.

This could cause a mismatch between the time on the RTC and the actual wall clock.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
2353
Followers
200
Author:randofo(Randy Sarafan loves you!)
I am the Technology Editor here at Instructables. I am also the author of the books 'Simple Bots,' and '62 Projects to Make with a Dead Computer'. Subscribing to me = fun and excitement!