Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. //////////////////////////////
  2. // LED LIGHT SHOW PRESETS //
  3. //////////////////////////////
  4.  
  5. int showType = 0;
  6.  
  7. void startShow(int i) {
  8. switch(i){
  9. case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
  10. break;
  11. case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
  12. break;
  13. case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green
  14. break;
  15. case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue
  16. break;
  17. case 4: theaterChase(strip.Color(127, 127, 127), 50); // White
  18. break;
  19. case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red
  20. break;
  21. case 6: theaterChase(strip.Color( 0, 0, 127), 50); // Blue
  22. break;
  23. case 7: rainbow(20);
  24. break;
  25. case 8: rainbowCycle(20);
  26. break;
  27. case 9: theaterChaseRainbow(50);
  28. break;
  29. }
  30. }
  31.  
  32. uint32_t Wheel(byte WheelPos) {
  33. WheelPos = 255 - WheelPos;
  34. if(WheelPos < 85) {
  35. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  36. }
  37. if(WheelPos < 170) {
  38. WheelPos -= 85;
  39. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  40. }
  41. WheelPos -= 170;
  42. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  43. }
  44.  
  45. void colorWipe(uint32_t c, uint8_t wait) {
  46. for(uint16_t i=0; i<strip.numPixels(); i++) {
  47. strip.setPixelColor(i, c);
  48. strip.show();
  49. delay(wait);
  50. }
  51. }
  52.  
  53. void rainbow(uint8_t wait) {
  54. uint16_t i, j;
  55.  
  56. for(j=0; j<256; j++) {
  57. for(i=0; i<strip.numPixels(); i++) {
  58. strip.setPixelColor(i, Wheel((i+j) & 255));
  59. }
  60. strip.show();
  61. delay(wait);
  62. }
  63. }
  64.  
  65. void rainbowCycle(uint8_t wait) {
  66. uint16_t i, j;
  67.  
  68. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  69. for(i=0; i< strip.numPixels(); i++) {
  70. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  71. }
  72. strip.show();
  73. delay(wait);
  74. }
  75. }
  76.  
  77. void theaterChase(uint32_t c, uint8_t wait) {
  78. for (int j=0; j<10; j++) { //do 10 cycles of chasing
  79. for (int q=0; q < 3; q++) {
  80. for (int i=0; i < strip.numPixels(); i=i+3) {
  81. strip.setPixelColor(i+q, c); //turn every third pixel on
  82. }
  83. strip.show();
  84.  
  85. delay(wait);
  86.  
  87. for (int i=0; i < strip.numPixels(); i=i+3) {
  88. strip.setPixelColor(i+q, 0); //turn every third pixel off
  89. }
  90. }
  91. }
  92. }
  93.  
  94. void theaterChaseRainbow(uint8_t wait) {
  95. for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
  96. for (int q=0; q < 3; q++) {
  97. for (int i=0; i < strip.numPixels(); i=i+3) {
  98. strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
  99. }
  100. strip.show();
  101.  
  102. delay(wait);
  103.  
  104. for (int i=0; i < strip.numPixels(); i=i+3) {
  105. strip.setPixelColor(i+q, 0); //turn every third pixel off
  106. }
  107. }
  108. }
  109. }
  110.  
  111.  
  112.  
  113. // BUTTON CODE
  114. void bt10PushCallback(void *ptr)
  115. {
  116.  
  117. if (showType < 9) {
  118. showType++;
  119. if (showType > 9)
  120. showType=0;
  121. startShow(showType);
  122. }
  123.  
  124. }
Add Comment
Please, Sign In to add comment