// passive buzzer musical scale
// keyboard scale: https://i.pinimg.com/originals/cf/72/9a/cf729ae2213a849fe6b8cc527a0e7471.png
#include "freqs.h" // adapted from pitches.h: https://gist.github.com/mikeputnam/2820675
int duration, dur = 500, spkr_pin = 3;
const int notes = 10;
const int scales = 12;
const int scale[scales][notes] = {
// N = natural S = sharp
// O- W W H W W H W W S // Octave lower, (W)hole-step, (H)alf-step
{ CN3, CN4, DN4, EN4, FN4, GN4, FN4, EN4, DN4, CN4 }, // C
{ CS3, CS4, DS4, FN4, FS4, GS4, FS4, FN4, DS4, CS4 }, // C#
{ DN3, DN4, EN4, FS4, GN4, AN4, GN4, FS4, EN4, DN4 }, // D
{ DS3, DS4, FN4, GN4, GS4, AS4, GS4, GN4, FN4, DS4 }, // D#
{ EN3, EN4, FS4, GS4, AN4, BN4, AN4, GS4, FS4, EN4 }, // E
{ FN3, FN4, GN4, AN4, AS4, CN5, AS4, AN4, GN4, FN4 }, // F
{ FS3, FS4, GS4, AS4, BN4, CS5, BN4, AS4, GS4, FS4 }, // F#
{ GN3, GN4, AN4, BN4, CN5, DN5, CN5, BN4, AN4, GN4 }, // G
{ GS3, GS4, AS4, CN5, CS5, DS5, CS5, CN5, AS4, GS4 }, // G#
{ AN3, AN4, BN4, CS5, DN5, EN5, DN5, CS5, BN4, AN4 }, // A
{ AS3, AS4, CN5, DN5, DS5, FN5, DS5, DN5, CN5, AS4 }, // A#
{ BN3, BN4, CS5, DS5, EN5, FS5, EN5, DS5, CS5, BN4 } // B
};
void setup() {
Serial.begin(115200);
Serial.println();
delay(3000); // I do not know why Arduino needs a long pause here
for (byte j = 0; j < scales; j++) {
// Serial.print(scale[scales][0]);
if (j < 11)
Serial.print(" "); // alignment
Serial.print(j + 1);
Serial.print(" of ");
Serial.print(scales);
Serial.print(" scales in fifths: ");
for (byte i = 0; i < notes; i++) {
Serial.print(i);
if (i == 0 || i == 9) // first and last note in scale
duration = dur * 2; // double note duration
else
duration = dur;
tone(spkr_pin, scale[j][i], duration);
delay(duration);
}
noTone(spkr_pin); // end tone
Serial.println();
}
}
void loop() {}