/* Chime Program scale Al Brendel 2/20/2016 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=100; // sets delay between notes int strikeTime=120; // 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) // This is the subroutine that does all the work. { // This first part allows the entire scale to be shifted up or down in steps // It is a routine that performs a circular shift and must be used with an unsigned integer // The number of steps is set by the Key declaration at the beginning of the program 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 } } } else //Decrement note { for (int x = Key; x < 0; x++) // loop down "Key" times { int y = bitRead(note,1); // 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 } else { bitClear (note,15); } } } } // 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 } // Here is where the song goes; Really simple... specify the note and the number of beats to wait until the next note // to play chords, send several notes .. example to play a C major chord,and delay for 4 beats use goPlay (Ch+Eh+Gh,4) void loop() { //All notes (up and down) goPlay (E,1); goPlay (F,1); goPlay (Fs,1); goPlay (G,1); goPlay (Gs,1); goPlay (A,1); goPlay (As,1); goPlay (B,1); goPlay (Ch,1); goPlay (Csh,1); goPlay (Dh,1); goPlay (Dsh,1); goPlay (Eh,1); goPlay (Fh,1); goPlay (Fsh,1); goPlay (Gh,1); goPlay (Gh,1); goPlay (Fsh,1); goPlay (Fh,1); goPlay (Eh,1); goPlay (Dsh,1); goPlay (Dh,1); goPlay (Csh,1); goPlay (Ch,1); goPlay (B,1); goPlay (As,1); goPlay (A,1); goPlay (Gs,1); goPlay (G,1); goPlay (Fs,1); goPlay (F,1); goPlay (E,1); delay(1000); // Scale notes (up and down) goPlay (E,1); goPlay (F,1); goPlay (G,1); goPlay (A,1); goPlay (B,1); goPlay (Ch,1); goPlay (Dh,1); goPlay (Eh,1); goPlay (Fh,1); goPlay (Gh,1); goPlay (Gh,1); goPlay (Fh,1); goPlay (Eh,1); goPlay (Dh,1); goPlay (Ch,1); goPlay (B,1); goPlay (A,1); goPlay (G,1); goPlay (F,1); goPlay (E,1); delay(1000); }