There are many ints that can be an uint8_t that makes arrays shorter; loops faster etc as long as the range is 0..255 (e.g. pin numbers)
for (int i = numLEDnum; i < (numLEDnum + functLEDnum); i++) {
allLEDs[i] = functLED[i - numLEDnum];
}
can be better written with two indices in the for loop. removes an subtraction every loop.
for (uint8_t i = 0, uint8_t j = numLEDnum ; i < functLEDnum; i++, j++) { // there is a comma , twice !!
allLEDs[j] = functLED[i];
}
int WhatLED (int buttoni) {
if (buttoni >= 0 && buttoni < floors) {
return buttoni;
}
if (buttoni >= floors && buttoni < (floors + functButtons)) {
return (buttoni + 1);
}
if (buttoni >= (floors + functButtons) && buttoni < totalButtons) {
return (buttoni + 2);
}
return -1; //error code
}
can be shorter
int WhatLED (int buttoni)
{
if ( buttoni >= 0 && buttoni < floors) return buttoni;
if ( buttoni < (floors + functButtons)) return (buttoni + 1); // as the first test assures that buttoni >= floors
if ( buttoni < totalButtons) return (buttoni + 2);
return -1; //error code
}
boolean ButtonChange() { //returns HIGH if there has been a change in button state from last scan
for (int i = 0; i < totalButtons; i++) {
buttonMem[i] = buttonStates[i];
}
ScanButtons();
for (int i = 0; i < totalButtons; i++) {
if (buttonMem[i] != buttonStates[i]) {
return HIGH;
}
}
return LOW;
}
why not return the index of the button that is changed, is a flag and value in one
int ButtonChange()
{
for (uint8_t i = 0; i < totalButtons; i++) buttonMem[i] = buttonStates[i];
ScanButtons();
for (uint8_t i = 0; i < totalButtons; i++)
{
if (buttonMem[i] != buttonStates[i]) {
return i; // at least button i has changed (but there might be more)
}
}
return -1; // no button
}
your turn