Rotary encoder

This commit is contained in:
Dejvino
2026-02-27 06:33:46 +01:00
parent d30bac7ec5
commit 59b48c1ab3
4 changed files with 84 additions and 10 deletions
+2 -8
View File
@@ -17,12 +17,6 @@ const int16_t AMPLITUDE = 16383; // Use a lower amplitude to avoid clipping (max
I2S i2s(OUTPUT);
// --- Synthesizer State ---
// Frequencies for a C-Major scale to pick from
const float NOTE_FREQUENCIES[] = {
261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25
};
const int NUM_NOTES = sizeof(NOTE_FREQUENCIES) / sizeof(NOTE_FREQUENCIES[0]);
float currentFrequency = 440.0f;
double phase = 0.0;
unsigned long lastNoteChangeTime = 0;
@@ -50,8 +44,8 @@ void loopAudio() {
// Every 500ms, pick a new random note to play
if (now - lastNoteChangeTime > 500) {
lastNoteChangeTime = now;
int noteIndex = random(0, NUM_NOTES);
currentFrequency = NOTE_FREQUENCIES[noteIndex];
int noteIndex = random(0, SCALES[currentScaleIndex].numNotes);
currentFrequency = SCALES[currentScaleIndex].frequencies[noteIndex];
Serial.println("Playing note: " + String(currentFrequency) + " Hz");
}