Step 7Program 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);
}
lunchtime_clock.zip822 bytes| « Previous Step | Download PDFView All Steps | Next Step » |

















































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.
Basing it on the RTC probably isn't as ideal as counting rotations, as the clock's motor has to do a precise amount of rotations to hit 1 o'clock. Once the RTC hits 11, it doesn't really matter what the real time is and even should there be a slight discrepancy, speeding or slowing the motor based on the RTC will probably just make things worse as it might not do the right number of rotations.