I've analyzed the signal of a remote consisting of 4 buttons, each can be on or off. All buttons produce a signal that starts with a common 12 bits of data. Following that is 8 bits that identifies which button was pressed. Lastly, there are 4 bits which can be a command for either on or off. The signal ends with a 0 that seems a bit out of place, which I'm pretty sure is a stop bit, making 25 bits in total. (It seems out of place because the 'on' code: 0011, is the inverse of the 'off' code: 1100. With the 0 they would no longer be inverses of each other.) I'm using this to reproduce these signals to replace the remote.
For now I'm just storing these as global constants:
const bool COM[12] = {0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1};
const bool OUT1[8] = {0, 1, 0, 1, 0, 0, 1, 1};
const bool OUT2[8] = {0, 1, 0, 1, 1, 1, 0, 0};
const bool OUT3[8] = {0, 1, 1, 1, 0, 0, 0, 0};
const bool OUT4[8] = {1, 1, 0, 1, 0, 0, 0, 0};
const bool ON[5] = {0, 0, 1, 1, 0}; // I've added the last 0 bit because why store it separate
const bool OFF[5] = {1, 1, 0, 0, 0};
It works, but I've learned in my CS courses that the use of global constants is generally bad practice. I need to keep my code neat because I have a lot of features to add. I'm also aware that the 8 bool array could be a byte. I'm not using the byte data type because making it a different data type from the rest would mead writing multiple functions for transmitting the data. Is there anything better than a bool array to store these values? If I could store them as bytes of varying sizes that would allow me to do bitwise operations, like replacing OFF with ~ON.
As for encapsulating this data, I'm not sure how to do that. It seems too small to bother saving in a .txt file on an SD card, but that is doable. I will have an SD card connected to the arduino for other parts of the project. Eventually I plan to write it all into its own library, and requiring an SD card to use it wouldn't be very practical.
