I want to store all settings (volume, mix input signals and frequency) in EEPROM so that all settings are saved in case of power failure and Teensy + Audio board will boot with the saved settings.
Volume = OKAY
Mix input signals = OKAY
Frequency = unfortunately no -> If I adjust the frequency with a filter setting (low pass, band pass or high pass) and reboot the Teensy, then some frequency comes but not which I have set.
Where do I have the error?
my sketch:
Volume = OKAY
Mix input signals = OKAY
Frequency = unfortunately no -> If I adjust the frequency with a filter setting (low pass, band pass or high pass) and reboot the Teensy, then some frequency comes but not which I have set.
Where do I have the error?
my sketch:
Code:
//
#include <EEPROM.h>
#include <Bounce.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// save setings to EEPROM
#define SETTING_VER "Helmut.V1.0" // Settings Version
typedef struct { // Setting Structure
int knobF; // int Frequence
int knobM; // int Mix White and Pink Noise
int knobV; // int Volume
char ver[sizeof(SETTING_VER)];
}
SettingType;
SettingType settings = { // Default settings
50,
125,
80,
SETTING_VER
};
bool loadConfiguration() {
char savedVersion[sizeof(SETTING_VER)];
int eepromVersionOffset = sizeof(settings) - sizeof(SETTING_VER); // Get the offset to the saved version
EEPROM.get(eepromVersionOffset,savedVersion); // Get the saved version, if it exist
if (strcmp(savedVersion,SETTING_VER) == 0) { // If version in EEPROM is correct, overwrite the default config with eeprom version
EEPROM.get(0, settings); // Overwrite the structure with EEPROM date
}
}
bool saveConfiguration() {
EEPROM.put(0,settings);
}
// end of save to EEPROM
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=224,278
AudioMixer4 mixer1; //xy=477,287
AudioFilterStateVariable filter1; //xy=719,289
AudioMixer4 mixer2; //xy=905,292
AudioOutputI2S i2s2; //xy=1139,295
AudioConnection patchCord1(i2s1, 0, mixer1, 0);
AudioConnection patchCord2(i2s1, 1, mixer1, 1);
AudioConnection patchCord3(mixer1, 0, filter1, 0);
AudioConnection patchCord4(filter1, 0, mixer2, 0);
AudioConnection patchCord5(filter1, 1, mixer2, 1);
AudioConnection patchCord6(filter1, 2, mixer2, 2);
AudioConnection patchCord7(mixer2, 0, i2s2, 0);
AudioConnection patchCord8(mixer2, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=721,385
// GUItool: end automatically generated code
// Bounce objects to read pushbuttons
Bounce button0 = Bounce(2, 15);
Bounce button1 = Bounce(3, 15); // 15 ms debounce time
Bounce button2 = Bounce(4, 15);
void setup() {
loadConfiguration();
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
Serial.begin(9600);
AudioMemory(30);
sgtl5000_1.enable();
}
void loop() {
// Update all the button objects
button0.update();
button1.update();
button2.update();
if (button0.fallingEdge()) {
Serial.println("Button (pin 2) Press");
Serial.println("Low Pass Signal");
mixer2.gain(0, 1.0); // hear low-pass signal
mixer2.gain(1, 0.0);
mixer2.gain(2, 0.0);
}
if (button1.fallingEdge()) {
Serial.println("Button (pin 3) Press");
Serial.println("Band Pass Signal");
mixer2.gain(0, 0.0);
mixer2.gain(1, 1.0); // hear band-pass signal
mixer2.gain(2, 0.0);
}
if (button2.fallingEdge()) {
Serial.println("Button (pin 4) Press");
Serial.println("High Pass Signal");
mixer2.gain(0, 0.0);
mixer2.gain(1, 0.0);
mixer2.gain(2, 1.0); // hear high-pass signal
}
// read the knobF and adjust the filter frequency
int knobF = analogRead(A3);
// quick and dirty equation for exp scale frequency adjust
float freq = expf((float)knobF / 150.0) * 10.0 + 80.0;
filter1.frequency(freq);
Serial.print("frequency = ");
Serial.println(freq);
delay(200);
settings.knobF = analogRead(A3);
// read the knobM postion for mixing input1 and input2
int knobM = analogRead(A6); // knob = 0 to 1023
float gain1 = (float)knobM / 1023.0;
float gain2 = 1.0 - gain1;
mixer1.gain(0, gain1);
mixer1.gain(1, gain2);
Serial.print("P_W-mix = ");
Serial.println(knobM);
settings.knobM = analogRead(A6);
// read the knobV position for setting volume (analog input A2)
int knobV = analogRead(A2);
float vol = (float)knobV / 1280.0;
sgtl5000_1.volume(vol);
Serial.print("volume = ");
Serial.println(vol);
settings.knobV = analogRead(A2);
saveConfiguration();
}