Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/oxlqyi/common_anode_rgb_led_control_with_qmk/
- * Code to include a specially wired button into the regular QMK keymap.
- * This should go into keymap.c
- */
- #ifdef ENC_BUTTON_PIN
- #include "matrix.h"
- #include "debounce.h"
- extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
- extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values
- #endif //ENC_BUTTON_PIN
- void keyboard_pre_init_user(void) {
- setPinInput(ENC_BUTTON_PIN); //set encoder pin as an input
- }
- void matrix_scan_user(void) {
- #ifdef ENC_BUTTON_PIN
- uint16_t prev_row_value = raw_matrix[ENC_ROW]; //save the current state of the row value
- if (readPin(ENC_BUTTON_PIN)) { //if encoder button is pressed (pin reads HIGH)
- raw_matrix[ENC_ROW] |= 1 << ENC_COL; // set encoder button state in matrix
- } else { //if encoder is not pressed (pin reads LOW)
- raw_matrix[ENC_ROW] &= ~(1 << ENC_COL); // clear encoder button state in matrix
- }
- if ((prev_row_value != raw_matrix[ENC_ROW])) { //if the encoder state was just changed
- debounce(raw_matrix, matrix, MATRIX_ROWS, true); // debounce the matrix
- }
- #endif //ENC_BUTTON_PIN
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement