2 #ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
4 #ifndef RGB_DIGITAL_RAIN_DROPS
5 // lower the number for denser effect/wider keyboard
6 #define RGB_DIGITAL_RAIN_DROPS 24
9 bool rgb_matrix_digital_rain(effect_params_t* params) {
10 // algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
11 const uint8_t drop_ticks = 28;
12 const uint8_t pure_green_intensity = 0xd0;
13 const uint8_t max_brightness_boost = 0xc0;
14 const uint8_t max_intensity = 0xff;
16 static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}};
17 static uint8_t drop = 0;
20 rgb_matrix_set_color_all(0, 0, 0);
21 memset(map, 0, sizeof map);
24 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
25 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
26 if (row == 0 && drop == 0 && rand() < RAND_MAX / RGB_DIGITAL_RAIN_DROPS) {
27 // top row, pixels have just fallen and we're
28 // making a new rain drop in this column
29 map[col][row] = max_intensity;
31 else if (map[col][row] > 0 && map[col][row] < max_intensity) {
32 // neither fully bright nor dark, decay it
35 // set the pixel colour
36 uint8_t led[LED_HITS_TO_REMEMBER];
37 uint8_t led_count = rgb_matrix_map_row_column_to_led(row, col, led);
39 // TODO: multiple leds are supported mapped to the same row/column
41 if (map[col][row] > pure_green_intensity) {
42 const uint8_t boost = (uint8_t) ((uint16_t) max_brightness_boost * (map[col][row] - pure_green_intensity) / (max_intensity - pure_green_intensity));
43 rgb_matrix_set_color(led[0], boost, max_intensity, boost);
46 const uint8_t green = (uint8_t) ((uint16_t) max_intensity * map[col][row] / pure_green_intensity);
47 rgb_matrix_set_color(led[0], 0, green, 0);
52 if (++drop > drop_ticks) {
55 for (uint8_t row = MATRIX_ROWS - 1; row > 0; row--) {
56 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
57 // if ths is on the bottom row and bright allow decay
58 if (row == MATRIX_ROWS - 1 && map[col][row] == max_intensity) {
61 // check if the pixel above is bright
62 if (map[col][row - 1] == max_intensity) {
63 // allow old bright pixel to decay
65 // make this pixel bright
66 map[col][row] = max_intensity;
74 #endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN