#include <EEPROM.h>
int potValues[5]; // Array to store potentiometer values
int presets[3][5]; // Array to store presets
int currentPreset = 0;
// Pin definitions
const int potPins[] = {A0, A1, A2, A3, A4};
const int buttonPins[] = {3, 4, 5, 6, 7}; // B1, B2, B3, Store
void setup() {
// Initialize potentiometer pins
for (int i = 0; i < 5; i++) {
pinMode(potPins[i], INPUT);
}
// Initialize button pins
for (int i = 0; i < 4; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
// Load presets from EEPROM
loadPresets();
// Set initial potentiometer values to zero
for (int i = 0; i < 5; i++) {
potValues[i] = 0;
analogWrite(potPins[i], potValues[i]);
}
}
void loop() {
// Read potentiometer values
for (int i = 0; i < 5; i++) {
potValues[i] = analogRead(potPins[i]) / 4;
analogWrite(potPins[i], potValues[i]);
}
// Check if any button is pressed
for (int i = 0; i < 4; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
delay(50); // Debounce delay
// Store Button pressed
if (i == 3) {
if (digitalRead(buttonPins[i]) == HIGH) {
storePreset();
}
}
// Preset Button pressed
else {
if (digitalRead(buttonPins[i]) == HIGH) {
recallPreset(i);
}
}
}
}
}
void storePreset() {
for (int i = 0; i < 5; i++) {
presets[currentPreset][i] = potValues[i];
}
// Save presets to EEPROM
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
EEPROM.write(i * 5 + j, presets[i][j]);
}
}
}
void loadPresets() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
presets[i][j] = EEPROM.read(i * 5 + j);
}
}
}
void recallPreset(int index) {
currentPreset = index;
for (int i = 0; i < 5; i++) {
potValues[i] = presets[index][i];
analogWrite(potPins[i], potValues[i]);
}
}