uint32_t musicData[] = { // Frequency ch0, Duty ch0, Frequency ch2, Duty ch2, Frequency ch4, Duty ch4, Frequency ch6, Duty ch6,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
440, 127, 0, 127, 0, 127, 0, 127,
440, 127, 0, 127, 0, 127, 0, 127,
440, 127, 0, 127, 0, 127, 0, 127,
440, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
0, 127, 0, 127, 0, 127, 0, 127,
220, 127, 0, 127, 0, 127, 0, 127,
0, 127, 0, 127, 0, 127, 0, 127,
};
double tickRateHz = 10;
uint32_t idx = 0;
void setup() {
ledcSetup(0, 0, 8);
ledcSetup(2, 0, 8);
ledcSetup(4, 0, 8);
ledcSetup(6, 0, 8);
ledcAttachPin(16, 0);
ledcAttachPin(17, 2);
ledcAttachPin(5, 4);
ledcAttachPin(18, 6);
// analogWrite(5, 5);
// analogWriteFrequency(440);
ledcWrite(0, 10);
//ledcWrite(2, 64);
//ledcWrite(4, 127);
// ledcWrite(6, 245);
ledcWriteNote(0, NOTE_C, 4); // Cmaj7
ledcWriteNote(2, NOTE_E, 4);
ledcWriteNote(4, NOTE_G, 4);
// ledcWriteNote(6, NOTE_B, 4);
}
uint32_t tickRateMicros = 1000000 / tickRateHz;
void loop() {/*
if (idx >= (sizeof(musicData) / sizeof(uint32_t))) idx = 0;
ledcWrite(0, musicData[idx + 1]);
ledcWriteTone(0, musicData[idx]);
ledcWrite(2, musicData[idx + 3]);
ledcWriteTone(2, musicData[idx + 2]);
ledcWrite(4, musicData[idx + 5]);
ledcWriteTone(4, musicData[idx + 4]);
ledcWrite(6, musicData[idx + 7]);
ledcWriteTone(6, musicData[idx + 6]);
idx += 4;
delayMicroseconds(tickRateMicros);*/
ledcWriteNote(0, NOTE_E, 4);
ledcWriteNote(2, NOTE_G, 4);
ledcWriteNote(4, NOTE_B, 4);
delay(433);
ledcWriteNote(4, NOTE_C, 5);
delay(433);
ledcWriteNote(4, NOTE_D, 5);
delay(433);
ledcWriteNote(4, NOTE_E, 5);
delay(433);
ledcWriteNote(0, NOTE_A, 4);
ledcWriteNote(2, NOTE_C, 5);
delay(2400);
ledcWriteNote(4, NOTE_F, 5);
delay(600);
ledcWriteNote(4, NOTE_E, 5);
delay(200);
ledcWriteNote(0, NOTE_G, 4);
ledcWriteNote(2, NOTE_B, 4);
delay(1600);
ledcWriteNote(4, NOTE_C, 5);
delay(800);
ledcWriteNote(4, NOTE_A, 4);
delay(800);
ledcWriteNote(0, NOTE_E, 4);
ledcWriteNote(2, NOTE_G, 4);
ledcWriteNote(4, NOTE_B, 4);
delay(3200);
ledcWriteNote(4, NOTE_C, 5);
delay(1600);
}