Advertisement
Guest User

Untitled

a guest
Jan 7th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. int i = 0;
  3. int t = 0;
  4. #define PIN 9
  5.  
  6. //Original Code by Adafruit (adafruit.com), Edited by PerfectPixel, 2016 (instructables.com/member/perfectpixel)
  7. //Code is public domain, Enjoy!
  8. Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
  9.  
  10. // An important announcement from Adafruit:
  11. // To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  12. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  13. // and minimize distance between Arduino and first pixel. Avoid connecting
  14. // on a live circuit...if you must, connect GND first.
  15.  
  16. void setup() {
  17. pinMode(3, INPUT);
  18. //Serial.begin(9600); //Debugging
  19. strip.begin();
  20. strip.show(); // Initialize all pixels to 'off'
  21. }
  22.  
  23. void loop() {
  24. switch(i) { //Change the RGB values in the colorWipe functions to change the colors that the redstone cube becomes.
  25. case 0: colorWipe(strip.Color(0, 0, 0), 5);
  26. break;
  27. case 1:colorWipe(strip.Color(255, 0, 0), 5);
  28. break;
  29. case 2:colorWipe(strip.Color(0, 255, 0), 5);
  30. break;
  31. case 3:colorWipe(strip.Color(0, 0, 255), 5);
  32. break;
  33. case 4:colorWipe(strip.Color(0, 255, 255), 5);
  34. break;
  35. case 5:colorWipe(strip.Color(255, 0, 255), 5);
  36. break;
  37. case 6:colorWipe(strip.Color(255, 255, 0), 5);
  38. break;
  39. case 7:colorWipe(strip.Color(255, 35, 97), 5);
  40. break;
  41. case 8:colorWipe(strip.Color(13, 73, 216), 5);
  42. break;
  43. case 9:colorWipe(strip.Color(248, 60, 49), 5);
  44. break;
  45. case 10:colorWipe(strip.Color(191, 84, 229), 5);
  46. break;
  47. case 11:colorWipe(strip.Color(76, 255, 5), 5);
  48. break;
  49. case 12:colorWipe(strip.Color(0, 240, 80), 5);
  50. break;
  51. case 13:colorWipe(strip.Color(7, 234, 233), 5);
  52. break;
  53. case 14:colorWipe(strip.Color(73, 10, 61), 5);
  54. break;
  55. case 15:colorWipe(strip.Color(63, 184, 175), 5);
  56. break;
  57. case 16:colorWipe(strip.Color(196, 77, 88), 5);
  58. break;
  59. }
  60. if(analogRead(3) < 600){ //by default, 600 is the threshhold for detecting if the tap sensor has been activated.
  61. i++;
  62. delay(250);
  63. if(i > 16) i = 0;
  64. }
  65.  
  66. t++;
  67. delay(25);
  68. //Serial.println(analogRead(3)); //Debugging
  69.  
  70. if(t > 1000){ //this will automatically turn off the LED's after some time.
  71. t = 0;
  72. i = 0;
  73. }
  74. }
  75.  
  76. // Fill the dots one after the other with a color
  77. void colorWipe(uint32_t c, uint8_t wait) {
  78. for(uint16_t i=0; i<strip.numPixels(); i++) {
  79. strip.setPixelColor(i, c);
  80. strip.show();
  81. delay(wait);
  82. }
  83. }
  84.  
  85. void rainbow(uint8_t wait) {
  86. uint16_t i, j;
  87.  
  88. for(j=0; j<256; j++) {
  89. for(i=0; i<strip.numPixels(); i++) {
  90. strip.setPixelColor(i, Wheel((i+j) & 255));
  91. }
  92. strip.show();
  93. delay(wait);
  94. }
  95. }
  96.  
  97. // Slightly different, this makes the rainbow equally distributed throughout
  98. void rainbowCycle(uint8_t wait) {
  99. uint16_t i, j;
  100.  
  101. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  102. for(i=0; i< strip.numPixels(); i++) {
  103. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  104. }
  105. strip.show();
  106. delay(wait);
  107. }
  108. }
  109.  
  110. //Theatre-style crawling lights.
  111. void theaterChase(uint32_t c, uint8_t wait) {
  112. for (int j=0; j<10; j++) { //do 10 cycles of chasing
  113. for (int q=0; q < 3; q++) {
  114. for (int i=0; i < strip.numPixels(); i=i+3) {
  115. strip.setPixelColor(i+q, c); //turn every third pixel on
  116. }
  117. strip.show();
  118.  
  119. delay(wait);
  120.  
  121. for (int i=0; i < strip.numPixels(); i=i+3) {
  122. strip.setPixelColor(i+q, 0); //turn every third pixel off
  123. }
  124. }
  125. }
  126. }
  127.  
  128. //Theatre-style crawling lights with rainbow effect
  129. void theaterChaseRainbow(uint8_t wait) {
  130. for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
  131. for (int q=0; q < 3; q++) {
  132. for (int i=0; i < strip.numPixels(); i=i+3) {
  133. strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
  134. }
  135. strip.show();
  136.  
  137. delay(wait);
  138.  
  139. for (int i=0; i < strip.numPixels(); i=i+3) {
  140. strip.setPixelColor(i+q, 0); //turn every third pixel off
  141. }
  142. }
  143. }
  144. }
  145.  
  146. // Input a value 0 to 255 to get a color value.
  147. // The colours are a transition r - g - b - back to r.
  148. uint32_t Wheel(byte WheelPos) {
  149. WheelPos = 255 - WheelPos;
  150. if(WheelPos < 85) {
  151. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  152. }
  153. if(WheelPos < 170) {
  154. WheelPos -= 85;
  155. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  156. }
  157. WheelPos -= 170;
  158. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement