I would really appreciate if anyone told me how to make key-value pairs. I am trying to store button coordinates (for a screen) inside an array but I want them to be retrievable by a key instead of a number index.
I've tried a lot of googling, stack overflow, and digging on the arduino forums and couldn't find a solution. Is there any way to achieve my goal?
Also one thing, these values are not going to change, they will stay constant. So a workaround involving me being able to write values to the key-value array is not required.
This compiles and runs on wokwi, but that's as far as I'm going to go Don't recall if I ever used C++ tuples and the syntax looks different from C#, which I'm used to.
const int BUTTON_ONE_X_1 = 0;
const int BUTTON_ONE_Y_1 = 1;
const int BUTTON_ONE_X_2 = 2;
const int BUTTON_ONE_Y_2 = 3;
But the enum feature of C/C++ makes all those very much tidier. And indeed, anyone writing out those four lines would either quickly be pointed to enum if we saw them here, or realize herself that it's just numbers in order and an enum is the ticket.
There are subtle and not so subtle differences between the three ways, but logically in your code you will end up with… symbols that can be used instead of numbers that you knew and could associate them with at the time you wrote the code.