Skip to content

Instantly share code, notes, and snippets.

@jackhumbert
Created March 16, 2018 21:40
Show Gist options
  • Save jackhumbert/1d9f9f16185bd28c61d662aaba411059 to your computer and use it in GitHub Desktop.
Save jackhumbert/1d9f9f16185bd28c61d662aaba411059 to your computer and use it in GitHub Desktop.
encoder
static uint8_t encoder_state = 0;
static int8_t encoder_value = 0;
static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
void matrix_init_user(void) {
encoder_state = PIND & 0x3;
}
void matrix_scan_user(void) {
encoder_state <<= 2;
encoder_state |= (PIND & 0x3);
encoder_value += encoder_LUT[encoder_state & 0xF];
if (encoder_value >= 4) {
register_code(KC_PGUP);
unregister_code(KC_PGUP);
}
if (encoder_value <= -4) {
register_code(KC_PGDN);
unregister_code(KC_PGDN);
}
encoder_value %= 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment