hakbraley

QMK Flash backlighting

Sep 14th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. /*  https://www.reddit.com/r/olkb/comments/po9skn/how_do_i_flash_the_leds_on_the_dz60_on_every/
  2.  *  Code to briefly flash backlighting on every keypress.
  3.  *  Every keypress will turn backlighting on.  
  4.  *  The backlighting will turn off BACKLIGHT_FLASH_TIME milliseconds after the most recent keypress.
  5.  *  This goes in keymap.c
  6.  *  
  7.  *  *Note 1: the number of backlight levels is defined in config.h, or defaults to 3.  31 is the max allowed number of levels.
  8.  *  Change '31' to below this value to flash the LEDs at a lower brightness.
  9.  */
  10.  
  11. #define BACKLIGHT_FLASH_TIME 200  //configure flash time in milliseconds
  12.  
  13. uint16_t last_keydown_time = 0;  //marks the time of last keydown event
  14.  
  15. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  16.     if (record->event.pressed) {           //when any key is pressed
  17.         last_keydown_time = timer_read();  //update last_keydown_time to now
  18.         backlight_level_noeeprom(31);      //set backlight level to 31 (max possible) *Note 1
  19.     }
  20.    
  21.     switch (keycode) {
  22.         //macro code
  23.     }
  24.     return true;
  25. }
  26.  
  27.  
  28. void matrix_scan_user(void) {
  29.     if (get_backlight_level()) {  //if backlight is on (level is not zero)
  30.         if (timer_elapsed(last_keydown_time) > BACKLIGHT_FLASH_TIME) {  //if last keydown was more than BACKLIGHT_FLASH_TIME ms ago
  31.             backlight_level_noeeprom(0);  //turn backlight off
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment