FastLED 3.9.15
Loading...
Searching...
No Matches

◆ addmod8()

LIB8STATIC uint8_t addmod8 ( uint8_t a,
uint8_t b,
uint8_t m )

Add two numbers, and calculate the modulo of the sum and a third number, M.

In other words, it returns (A+B) % M. It is designed as a compact mechanism for incrementing a "mode" switch and wrapping around back to "mode 0" when the switch goes past the end of the available range. e.g. if you have seven modes, this switches to the next one and wraps around if needed:

mode = addmod8( mode, 1, 7);
LIB8STATIC uint8_t addmod8(uint8_t a, uint8_t b, uint8_t m)
Add two numbers, and calculate the modulo of the sum and a third number, M.
Definition math8.h:392
Parameters
adividend byte
bvalue to add to the dividend
mdivisor byte
Returns
remainder of (a + b) / m
See also
mod8() for notes on performance.
Examples
TwinkleFox.ino.

Definition at line 392 of file math8.h.

392 {
393#if defined(__AVR__)
394 asm volatile(" add %[a],%[b] \n\t"
395 "L_%=: sub %[a],%[m] \n\t"
396 " brcc L_%= \n\t"
397 " add %[a],%[m] \n\t"
398 : [a] "+r"(a)
399 : [b] "r"(b), [m] "r"(m));
400#else
401 a += b;
402 while (a >= m)
403 a -= m;
404#endif
405 return a;
406}

References LIB8STATIC.

Referenced by chooseNextColorPalette(), and fl::TwinkleFox::chooseNextColorPalette().

+ Here is the caller graph for this function: