Advertisement
Matqux

blinking

May 25th, 2022
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. void blinking(WS2812B *strip, uint32_t delayTime, uint32_t currentTime) //Fill the ring with red color, and wait in each state for the specified time
  2. {
  3.     if (lastTimeTailLight + delayTime <= currentTime)   //If the given amount of time has elapsed
  4.     {
  5.         lastTimeTailLight = currentTime;    //Save the current time as the last time of update
  6.  
  7.         tailLightState += 1;    //Increment the state counter by one
  8.         tailLightState %= 2;    //As we will have 2 states, we use the modulo operator to get 0 or 1
  9.  
  10.         if (tailLightState == 0)    //If the state is 0
  11.         {
  12.             strip->fill(255, 0, 0); //Turn on the whole strip
  13.         }
  14.         else    //If the state is 1
  15.         {
  16.             strip->clear(); //Turn off the whole strip
  17.         }
  18.  
  19.         strip->update();    //Update the changes
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement