Hello everyone,
I’m currently working on a project using an Arduino Micro that involves managing multiple “layers” of key mappings for a custom MIDI controller. Each layer has an array of key mappings, and each key can trigger either a keyboard press or a MIDI note.
My background is in web development, where I would typically manage such configurations using JSON files, which allows for easy scalability and configurability. However, since the Arduino Micro doesn’t have an SD card slot or built-in file storage, I’m looking for advice on the best practices for handling this kind of configuration in an Arduino environment.
My Requirements:
• Scalability: I want to be able to easily add, modify, or remove layers and key mappings.
• Configurability: Ideally, I would like to keep the configuration separate from the main logic to keep the code clean and modular.
• Memory Efficiency: Since the Arduino Micro has limited memory, I want to avoid consuming too much RAM.
• UX: In an ideal scenario, I'd create a web interface where the user could configure their own mappings and that config would be stored in the arduino.
Current Approach:
I am considering placing my configuration data (the layers and key mappings) in a separate header file (config.h). Here’s a simplified version of what I’m doing:
// config.h
#define MAX_TARGETS 6
#define NUM_LAYERS 2
struct KeyMap {
int pin;
const char* action;
int targets[MAX_TARGETS];
int targetCount;
const char* label;
};
struct Layer {
const char* name;
KeyMap keys[6];
};
Layer layer1 = {
"1.Keys",
{
{2, "keypress", {'a'}, 1, "A"},
{3, "keypress", {'b'}, 1, "B"},
// Other keys...
}
};
Layer layer2 = {
"2.Notes",
{
{2, "keypress", {65}, 1, "65"},
{3, "keypress", {66}, 1, "66"},
// Other keys...
}
};
Layer* layers[NUM_LAYERS] = {&layer1, &layer2};
My Questions:
-
Is using a header file to store configuration data a common and recommended approach for Arduino projects?
-
Are there any alternative or better approaches for managing such configurations in an Arduino environment?
-
What considerations should I keep in mind regarding memory usage and scalability when handling configurations this way?
-
Would there be any significant benefits to using something like EEPROM or PROGMEM for storing configurations, or would that add unnecessary complexity?
-
Is there a common pattern to be able to create the config files in a web app and deploy them to the arduino without having to install the arduino IDE and without the need of a SD card?
Any advice or insights you could provide would be greatly appreciated! Really all I'm trying to find is perspective and different approaches. I'm not looking for very precise answers, so anything helps.
Thanks in advance!