volume control added

This commit is contained in:
Sebastian
2025-06-06 02:07:30 +02:00
parent 8cd690edbd
commit 55bcb2c389
2 changed files with 123 additions and 15 deletions

View File

@ -152,8 +152,8 @@ void speaker(bool state){
}
void setup() {
//Serial.begin();
//delay(1000);
Serial.begin();
delay(1000);
i2s.setFrequency(48000);
@ -181,21 +181,18 @@ void setup() {
if(sdInitialized && SD.exists("/click.wav")) {
File click = SD.open("/click.wav");
click.seek(44, SeekSet);
int click_bytes = 0;
int16_t maxv = 0;
while (click.available() || click_bytes == UI_SAMPLERATE-1) {
int16_t sample = click.read() * 32;
if(abs(sample) > maxv) maxv = sample;
uint8_t samplebyte[2];
click.read(samplebyte, 2);
int16_t sample = (samplebyte[1] << 8) + samplebyte[0];
beep[click_bytes] = sample;
click_bytes++;
}
click.close();
click.close();
beep_length = click_bytes;
Serial.print("Read ");
Serial.print(beep_length);
Serial.print(" bytes from click.wav into beep array. maxV was ");
Serial.println(maxv);
} else {
for(int i = 0; i < UI_SAMPLERATE; i++){
float sine_pos = (2.0f * M_PI * 8000.0f * (float)i) / (float)UI_SAMPLERATE;
@ -295,8 +292,13 @@ void setup() {
// }
digitalWrite(6, HIGH);
delay(50);
delay(25);
digitalWrite(6, LOW);
delay(50);
digitalWrite(6, HIGH);
delay(25);
digitalWrite(6, LOW);
}
void loop() {
@ -367,11 +369,22 @@ void loop() {
if(active == 13) active = 0;
if(active == -1) active = 12;
if(buttons[CVINL]) {
Serial.println("vol down");
codec.volumeDown();
}
if(buttons[CVOUTL]) {
Serial.println("vol up");
codec.volumeUp();
}
if(buttons[DEBUG3]) {
speakerToggle = !speakerToggle;
speaker(speakerToggle);
}
Serial.println(codec.getVolumeL());
buttonChanged = false;
}