- int8_t direction = (delta % 2) ? -1 : 1;
- uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
- for (uint8_t i = 0; i < RGBLED_NUM; i++) {
- _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360;
- dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range);
- sethsv(_hue, sat, val, (LED_TYPE *)&led[i]);
+ bool direction = (delta % 2) == 0;
+#ifdef __AVR__
+ // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line
+ uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
+#else
+ uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2];
+#endif
+ for (uint8_t i = 0; i < effect_num_leds; i++) {
+ uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds;
+ if (direction) {
+ _hue = hue + _hue;
+ } else {
+ _hue = hue - _hue;
+ }
+ dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
+ sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]);