int speakerPin = 8;
int length = 8; // Sesuaikan dengan jumlah karakter dalam array 'notes'
char notes[] = "doremisl"; // Gunakan huruf pertama dari setiap notasi solmisasi
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1};
int tempo = 400;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = {'d', 'r', 'm', 'f', 's', 'l', 'i', 'D'}; // Notasi solmisasi
int tones[] = {3822, 3405, 3034, 2864, 2551, 2273, 2025, 1911}; // Nilai ini didapat dari tabel frekuensi dalam microseconds
for (int i = 0; i < 8; i++) { // Sesuaikan dengan panjang array 'names'
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
pinMode(speakerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo);
} else {
playNote(notes[i], beats[i] * tempo);
}
delay(tempo / 2);
}
}