KIR buttons.ino: Difference between revisions
(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...") |
mNo edit summary |
||
Line 1: | Line 1: | ||
These functions are related to the up-to 49 buttons on the KontroLIR remote control. In general only the last function below needs to be changed and only if you are changing the number of devices or modes supported from the default of 5. It is OK to leave as is even if you are using less than 5 devices. | |||
== initButtons == | == initButtons == | ||
This function is called during setup, to initialise the GPIOs for all of the row/col | This function is called during setup, to initialise the GPIOs for all of the row/col matrix pins. Each row/col combination represents one button on the remote. 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 on a col pin 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. | ''(Note: After a button is pressed the pinMode of the rows is temporarily changed to figure out which particular button has been pressed.)'' | ||
Line 11: | Line 12: | ||
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). | 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 | The first part of this function determines which button has been pressed by setting all ROW pins to INPUT and then setting each row 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 | If no 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. | Then the scanCode is calculated based on the Row, Col and Device Mode. Once the scanCode is set the function exits. | ||
Line 20: | Line 21: | ||
== doButtonPressed == | == doButtonPressed == | ||
In the main loop, if a button press is detected, the indicator | 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. Once this function is completed the LED is turned OFF. | ||
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. | |||
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 pointer entries. This array is laid out in blocks separated by comments for easy editing. There is one block for each configured device 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. ''(You will also need to add an additional mode file for the new mode)'' |
Revision as of 09:13, 24 October 2019
These functions are related to the up-to 49 buttons on the KontroLIR remote control. In general only the last function below needs to be changed and only if you are changing the number of devices or modes supported from the default of 5. It is OK to leave as is even if you are using less than 5 devices.
initButtons
This function is called during setup, to initialise the GPIOs for all of the row/col matrix pins. Each row/col combination represents one button on the remote. 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 on a col pin 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 been pressed by setting all ROW pins to INPUT and then setting each row 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 no 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. Once this function is completed the LED is turned OFF.
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 pointer entries. This array is laid out in blocks separated by comments for easy editing. There is one block for each configured device 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. (You will also need to add an additional mode file for the new mode)