/* Westminster Chime Clock Al Brendel 3/4/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=1200; // sets delay between notes int strikeTime=18; // 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(); //melody every 15 minutes if (gong == 15){ //quarter hour // set 1 goPlay(Dh,1); goPlay(C,1); goPlay(As,1); goPlay(F,1); delay(90000); } else if(gong==30){ //half hour //set 2 goPlay(As,1); goPlay(Dh,1); goPlay(C,1); goPlay(F,1); // set 3 goPlay(As,1); goPlay(C,1); goPlay(Dh,1); goPlay(As,1); delay(90000); } else if(gong==45){ // 3/4 Hour // set 4 goPlay(Dh,1); goPlay(As,1); goPlay(C,1); goPlay(F,1); //set 5 goPlay(F,1); goPlay(C,1); goPlay(Dh,1); goPlay(As,1); // set 1 goPlay(Dh,1); goPlay(C,1); goPlay(As,1); goPlay(F,1); delay(90000); } else if(gong==0){ //Hour //set 2 goPlay(As,1); goPlay(Dh,1); goPlay(C,1); goPlay(F,1); // set 3 goPlay(As,1); goPlay(C,1); goPlay(Dh,1); goPlay(As,1); //set 4 goPlay(Dh,1); goPlay(As,1); goPlay(C,1); goPlay(F,1); //set 5 goPlay(F,1); goPlay(C,1); goPlay(Dh,1); goPlay(As,1); delay(90000); } // } }