refactor: let encoder modify frequency in tone generator

This commit is contained in:
Fritz Heiden 2025-05-24 19:04:45 +02:00
parent 16cec914f8
commit 8c3b5a0134

View File

@ -2,6 +2,7 @@
#include <Versatile_RotaryEncoder.h> #include <Versatile_RotaryEncoder.h>
#include <ui/display.hpp> #include <ui/display.hpp>
#include <audio/tone_generator.hpp>
#ifndef ENCODER_A_PIN #ifndef ENCODER_A_PIN
#define ENCODER_A_PIN 12 #define ENCODER_A_PIN 12
@ -23,7 +24,6 @@ namespace Encoder
void handleRotate(int8_t rotation); void handleRotate(int8_t rotation);
Versatile_RotaryEncoder *encoder; Versatile_RotaryEncoder *encoder;
int frequency = 220; // A4
void init() void init()
{ {
@ -63,6 +63,7 @@ namespace Encoder
{ {
Serial.print("Encoder rotated by "); Serial.print("Encoder rotated by ");
Serial.println(rotation); Serial.println(rotation);
int frequency = ToneGenerator::getFrequency();
if (rotation > 0) if (rotation > 0)
{ {
frequency += 10; frequency += 10;
@ -71,6 +72,7 @@ namespace Encoder
{ {
frequency -= 10; frequency -= 10;
} }
ToneGenerator::setFrequency(frequency);
Serial.print("Frequency: "); Serial.print("Frequency: ");
Serial.println(frequency); Serial.println(frequency);