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:408
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 408 of file math8.h.

408 {
409#if defined(__AVR__)
410 asm volatile(" add %[a],%[b] \n\t"
411 "L_%=: sub %[a],%[m] \n\t"
412 " brcc L_%= \n\t"
413 " add %[a],%[m] \n\t"
414 : [a] "+r"(a)
415 : [b] "r"(b), [m] "r"(m));
416#else
417 a += b;
418 while (a >= m)
419 a -= m;
420#endif
421 return a;
422}

References LIB8STATIC.

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

+ Here is the caller graph for this function: