KIR buttons.ino

From AnalysIR WiKi
Revision as of 09:04, 24 October 2019 by AnalysIR (talk | contribs) (Created page with " == initButtons == This function is called during setup, to initialise the GPIOs for all of the row/col matric pins. There are 7 rows and 7 columns for a total of up to 49 b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


initButtons

This function is called during setup, to initialise the GPIOs for all of the row/col matric pins. There are 7 rows and 7 columns for a total of up to 49 buttons on the KontroLIR remote control. COLs are set to INPUT_PULLUP which presents a HIGH on these pins. Rows are set to OUTPUT/LOW such that when a button is pressed a PCINT interrupt is generated which wakes the MCU from sleep to allow processing of the functionality programmed for that button press. (Note: After a button is pressed the pinMode of the rows is temporarily changed to figure out which particular button has been pressed.


isButtonPressed

When the MCU wakes from sleep this function is called to determine if a button has been pressed. The logic as written sets the first button detected as the only button that has been pressed and ignores other buttons when multiple buttons have been pressed. (Users could extend the logic to support multiple simultaneous button presses if desired).

The first part of this function determines which button has benn pressed by setting all ROW pins to INPUT and then setting each individually to LOW to determine which ROW/Col combination (i.e. button) has been pressed. Once detected the ROWS are reset to OUTPUT/LOW for the next button press. If not button press is detected then it is ignored. (Theoretically this could occur if a brief press occurred, of the order of uSecs or less). Under normal circumstances this should not occur. Then the scanCode is calculated based on the Row, Col and Device Mode. Once the scanCode is set the function exits.


doButtonPressed

In the main loop, if a button press is detected, the indicator Led is turned ON and this function is called to process the button press. Inside this function we define an array of function pointers, pointing to the function to be called for each button press in each of the configured modes. So for the default 5 modes we have 5*49 entries. This array is laid out in blocks separated by comments. There is one block for each configured mode (49 entries each). The block for mode1 uses FN1, mode 2 uses FN2 etc. If you want to add a 6th block then add in an extra block using FN6 etc. Also, make sure to define FN6 etc. for any additional blocks.