/* Chime Program Watermark2 Al 2/11/2016 Watermark by Enya Key of F Musical Scale Treble Clef Base Clef o Gh o B ------------o-- Fh ------------o-- A o Eh o G ----------o---- Dh ----------o---- F o Ch o E --------o------ B --------o------ D o A o C ------o-------- G ------o-------- B o F o A ----o---------- E ----o---------- G o D o F */ int latchPin = 5; //define the Arduino output pins int clockPin = 6; int dataPin = 4; long note = 0; // 16 bit word defining which solenoids to energize int beats=1; // number of beats until next note int tempo=350; // sets delay between notes int strikeTime=10; // length of time solenoid is energized (10< >50 100=LEDs int Key = 0; // Key transposition (0=no shift, +1 = shift higher 1 note, -1 = shift lower) // 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 Csh = 0b0000001000000000; unsigned int Ch = 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); delay(1000); } void goPlay(int note,int beats) { // adjust note for key signature if (Key != 0) { if (Key >0) // increment note { for (int x = Key; x > 0; x--) // loop up "Key" times { int y = bitRead(note,15); // read bit 15 note = note << 1; // shift notes left if (y==1) // if bit 15 was = 1 { bitSet (note,0); // add it to the note } } } //************** Problem here else //Decrement note { for (int x = Key; x <= 0; x++) // loop down "Key" times { int y = bitRead(note,0); // read bit 0 note = note >> 1; // shift notes right if (y>0) // if bit 0 was = 1 { bitSet (note,15); // add it to the note } //**************** to here } } } // 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); 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() { /* Watermark Key of F 6/6 time Measure order: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 22, 23, 24, 25, 26, 27, 28, 29, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32 */ //1 (measure number) goPlay (rest,6); //2 goPlay (rest,4); goPlay (Ch,1); goPlay (Eh,1); //3 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //4 goPlay (Eh,2); goPlay (Ch,2); goPlay (A,2); //5 goPlay (Fh,4); goPlay (Gh,2); //6 goPlay (Eh,2); goPlay (Ch,2); goPlay (A,2); //7 goPlay (Dh,6); //8 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //9 goPlay (Ch,6); //10 goPlay (A,4); goPlay (Ch,2); goPlay (Eh,2); //3 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //4 goPlay (Eh,2); goPlay (Ch,2); goPlay (A,2); //5 goPlay (Fh,4); goPlay (Gh,2); //6 goPlay (Eh,2); goPlay (Ch,2); goPlay (A,2); //7 goPlay (Dh,6); //8 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //9 goPlay (Ch,6); //11 goPlay (A,4); goPlay (Ch,1); goPlay (Fh,1); //12 goPlay (Dh+Eh+A,4); goPlay (Dh+Ch+A,1); goPlay (Gh,1); //13 goPlay (Eh+Ch+A,4); goPlay (Ch,2); //14 goPlay (Fh+As+A,2); goPlay (Dsh,2); goPlay (Dh,2); //15 goPlay (Ch+A+F,6); //16 goPlay (Fh+Dh+A,4); goPlay (Fh+Dh+A,1); goPlay (Gh,1); //17 goPlay (Eh+Ch+A,4); goPlay (Ch,2); //18 goPlay (Fh+As+G,2); goPlay (Dsh,2); goPlay (Dh,2); //19 goPlay (Dsh+Gs+F,2); goPlay (Csh,2); goPlay (Ch,2); //20 goPlay (Ch+G+E,6); //21 goPlay (Ch+G+E,3); goPlay (Ch,1); goPlay (Eh,2); //22 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //23 goPlay (Eh,2); goPlay (Ch,2); goPlay (Ch,1); goPlay (Fh,1); //24 goPlay (Fh,4); goPlay (Gh,2); //25 goPlay (Eh,2); goPlay (Ch,2); goPlay (A,2); //26 goPlay (Dh,6); //27 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //28 goPlay (Ch,6); //29 goPlay (A,4); goPlay (Ch,1); goPlay (Eh,1); //22 goPlay (Fh,4); goPlay (Gh,2); goPlay (Fh,2); //23 goPlay (Eh,2); goPlay (Ch,2); goPlay (Ch,1); goPlay (Fh,1); //24 goPlay (Fh,4); goPlay (Gh,2); //25 goPlay (Eh,2); goPlay (Ch,2); goPlay (A,2); //26 goPlay (Dh,6); //27 goPlay (Dh,2); goPlay (As,2); goPlay (G,2); //28 goPlay (Ch,6); //30 goPlay (A,6); //31 goPlay (F,8); //32 goPlay (F,4); delay(2000); }