bluenrg-1 True random numbers to achieve holiday lighting effects[Copy link]
Use the true random number function of the RNG of bluenrg-1 to generate random colors, and then display them through the WS2812B colored lights. If you use a light strip and shorten the update delay, the effect will be better. Generate the code for random numbers, wait for the data to be ready before reading the data. The RNG module can read 16 bits of data at a time.
uint8_t rng_read(void) { uint8_t random; /* Loop until the RNG Data Ready is SET */ while (RNG_GetFlagStatus() != SET); random = (uint8_t)(RNG_GetValue() % 255); return random; }
复制代码
WS2812B uses 24 bits, so read 8 bits each time, and read 3 times in succession to fill an LED lamp bead.