Guest User

Untitled

a guest
Mar 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. float brightness = 1.0;
  2. uint32_t strip_state=0;
  3.  
  4. uint32_t Wheel(Adafruit_NeoPixel *strip, byte WheelPos) {
  5. WheelPos = 255 - WheelPos;
  6. if(WheelPos < 85) {
  7. return strip->Color((255 - WheelPos * 3)*brightness, 0, WheelPos * 3*brightness);
  8. }
  9. if(WheelPos < 170) {
  10. WheelPos -= 85;
  11. return strip->Color(0, WheelPos * 3 * brightness, (255 - WheelPos * 3)*brightness);
  12. }
  13. WheelPos -= 170;
  14. return strip->Color(WheelPos * 3 * brightness, (255 - WheelPos * 3)*brightness, 0);
  15. }
  16.  
  17. void fill_color(uint32_t color){
  18. byte r= ((color & 0xFF0000) >> 16) * brightness;
  19. byte g= ((color & 0xFF00) >> 8) *brightness;
  20. byte b= (color & 0xFF) * brightness;
  21. color = strip.Color(r,g,b);
  22. for(unsigned int i=0; i < strip.numPixels(); i++) {
  23. strip.setPixelColor(i, color);
  24. }
  25. strip.show();
  26. }
  27.  
  28. void fade_color(){
  29. for(unsigned int i=0;i<strip.numPixels();i++){
  30. strip.setPixelColor(i,Wheel(&strip,strip_state));
  31. }
  32. strip.show();
  33. strip_state++;
  34. if(strip_state>255) strip_state = 0;
  35. }
  36.  
  37. void moving_rainbow(){
  38. for(unsigned int i=0; i<strip.numPixels(); i++) {
  39. strip.setPixelColor(i, Wheel(&strip,((i * 256 / strip.numPixels()) + strip_state) & 255));
  40. }
  41. strip.show();
  42. strip_state++;
  43. }
  44.  
  45. void colorWipe(uint32_t color) {
  46. byte r= ((color & 0xFF0000) >> 16) * brightness;
  47. byte g= ((color & 0xFF00) >> 8) *brightness;
  48. byte b= (color & 0xFF) * brightness;
  49. color = strip.Color(r,g,b);
  50.  
  51. strip.setPixelColor(strip_state, color);
  52. strip.show();
  53. strip_state++;
  54. }
  55.  
  56. //Theatre-style crawling lights.
  57. void theaterChase(uint32_t c) {
  58. byte r= ((c & 0xFF0000) >> 16) * brightness;
  59. byte g= ((c & 0xFF00) >> 8) *brightness;
  60. byte b= (c & 0xFF) * brightness;
  61. c = strip.Color(r,g,b);
  62. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  63. strip.setPixelColor(i + strip_state % 3, c); //turn every third pixel on
  64. strip.setPixelColor(i + (strip_state +1) % 3, 0); // turn others off
  65. strip.setPixelColor(i + (strip_state +2) % 3, 0);
  66. }
  67. strip.show();
  68. strip_state++;
  69. }
  70.  
  71. //Theatre-style crawling lights with rainbow effect
  72. void theaterChaseRainbow() {
  73. for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
  74. strip.setPixelColor(i + strip_state % 3, Wheel(&strip, (i+strip_state) % 255)); //turn every third pixel on
  75. strip.setPixelColor(i + (strip_state +1) % 3, 0); // turn others off
  76. strip.setPixelColor(i + (strip_state +2) % 3, 0);
  77. }
  78. strip.show();
  79. strip_state++;
  80. }
Add Comment
Please, Sign In to add comment