/* Chime Clock Al Brendel 3/1/2016 */ #include #include "RTClib.h" RTC_DS1307 RTC; int latchPin = 5; //define the Arduino output pins int clockPin = 6; int dataPin = 4; unsigned int note = 0; // 16 bit word defining which solenoids to energize int beats=1; // number of beats until next note int tempo=400; // sets delay between notes int strikeTime=15; // length of time solenoid is energized (10< >50 100=LEDs // Define the notes... organized from high to low... Nomenclature is (Note)(s for sharp)(h is for high) unsigned int Gh = 0b1000000000000000; unsigned int Fsh = 0b0100000000000000; unsigned int Fh = 0b0010000000000000; unsigned int Eh = 0b0001000000000000; unsigned int Dsh = 0b0000100000000000; unsigned int Dh = 0b0000010000000000; unsigned int Cs = 0b0000001000000000; unsigned int C = 0b0000000100000000; unsigned int B = 0b0000000010000000; unsigned int As = 0b0000000001000000; unsigned int A = 0b0000000000100000; unsigned int Gs = 0b0000000000010000; unsigned int G = 0b0000000000001000; unsigned int Fs = 0b0000000000000100; unsigned int F = 0b0000000000000010; unsigned int E = 0b0000000000000001; unsigned int rest = 0b0000000000000000; // no solenoids void setup () { //Set the hardware pinMode(latchPin, OUTPUT); // set the pins to be outputs pinMode(dataPin, OUTPUT); pinMode(clockPin, OUTPUT); // set all solenoids off digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, 0b00000000); shiftOut(dataPin, clockPin, MSBFIRST, 0b00000000); digitalWrite(latchPin, HIGH); Wire.begin(); RTC.begin(); } void goPlay(int note,int beats) // This is the subroutine that does all the work. { // load the shift registers, first with the note, then with zeros digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, highByte(note)); shiftOut(dataPin, clockPin, MSBFIRST, lowByte(note)); digitalWrite(latchPin, HIGH); delay (strikeTime); // set the length of time that the strikers are actuated digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, 0b00000000); shiftOut(dataPin, clockPin, MSBFIRST, 0b00000000); digitalWrite(latchPin, HIGH); delay (beats*tempo); // adjust delay between notes for tempo } void loop () { delay(30000); //read the clock every 30 seconds DateTime now = RTC.now(); int gong=now.minute(); //if minutes = 0, play the melody if (gong == 0){ //1 (measure number) goPlay (rest,6); //2 goPlay (rest,4); goPlay (C,1); goPlay (Eh,1); //3 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //4 goPlay (Eh,2); goPlay (C,2); goPlay (A,2); //5 goPlay (Fh,4); goPlay (Gh,2); //6 goPlay (Eh,2); goPlay (C,2); goPlay (A,2); //7 goPlay (Dh,6); //8 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //9 goPlay (C,6); //10 goPlay (A,4); goPlay (C,2); goPlay (Eh,2); //3 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //4 goPlay (Eh,2); goPlay (C,2); goPlay (A,2); //5 goPlay (Fh,4); goPlay (Gh,2); //6 goPlay (Eh,2); goPlay (C,2); goPlay (A,2); //7 goPlay (Dh,6); //8 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //9 goPlay (C,6); //11 goPlay (A,4); goPlay (C,1); goPlay (Fh,1); //12 goPlay (Dh+Eh+A,4); goPlay (Dh+C+A,1); goPlay (Gh,1); //13 goPlay (Eh+C+A,4); goPlay (C,2); //14 goPlay (Fh+As+A,2); goPlay (Dsh,2); goPlay (Dh,2); //15 goPlay (C+A+F,6); //16 goPlay (Fh+Dh+A,4); goPlay (Fh+Dh+A,1); goPlay (Gh,1); //17 goPlay (Eh+C+A,4); goPlay (C,2); //18 goPlay (Fh+As+G,2); goPlay (Dsh,2); goPlay (Dh,2); //19 goPlay (Dsh+Gs+F,2); goPlay (Cs,2); goPlay (C,2); //20 goPlay (C+G+E,6); //21 goPlay (C+G+E,3); goPlay (C,1); goPlay (Eh,2); //22 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //23 goPlay (Eh,2); goPlay (C,2); goPlay (C,1); goPlay (Fh,1); //24 goPlay (Fh,4); goPlay (Gh,2); //25 goPlay (Eh,2); goPlay (C,2); goPlay (A,2); //26 goPlay (Dh,6); //27 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //28 goPlay (C,6); //29 goPlay (A,4); goPlay (C,1); goPlay (Eh,1); //22 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //23 goPlay (Eh,2); goPlay (C,2); goPlay (C,1); goPlay (Fh,1); //24 goPlay (Fh,4); goPlay (Gh,2); //25 goPlay (Eh,2); goPlay (C,2); goPlay (A,2); //26 goPlay (Dh,6); //27 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //28 goPlay (C,6); //30 goPlay (A,6); //31 goPlay (F,8); //32 goPlay (F,4); delay (60000); // wait a minute so the song wont repeat too soon. } }