Advertisement
Guest User

Programme

a guest
Apr 25th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <avr/power.h>
  3.  
  4. #define PIN 6
  5.  
  6. // Parameter 1 = number of pixels in strip
  7. // Parameter 2 = Arduino pin number (most are valid)
  8. // Parameter 3 = pixel type flags, add together as needed:
  9. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  10. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  11. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  12. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  13. Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
  14.  
  15. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  16. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  17. // and minimize distance between Arduino and first pixel. Avoid connecting
  18. // on a live circuit...if you must, connect GND first.
  19.  
  20. void setup() {
  21. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  22. #if defined (__AVR_ATtiny85__)
  23. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  24. #endif
  25. // End of trinket special code
  26.  
  27.  
  28. strip.begin();
  29. strip.show(); // Initialize all pixels to 'off'
  30. }
  31.  
  32. void loop() {
  33. // Some example procedures showing how to display to the pixels:
  34. colorWipe(strip.Color(255, 0, 0), 50); // Red
  35. colorWipe(strip.Color(0, 255, 0), 50); // Green
  36. colorWipe(strip.Color(0, 0, 255), 50); // Blue
  37. // Send a theater pixel chase in...
  38. theaterChase(strip.Color(127, 127, 127), 50); // White
  39. theaterChase(strip.Color(127, 0, 0), 50); // Red
  40. theaterChase(strip.Color( 0, 0, 127), 50); // Blue
  41.  
  42. rainbow(20);
  43. rainbowCycle(20);
  44. theaterChaseRainbow(50);
  45. }
  46.  
  47. // Fill the dots one after the other with a color
  48. void colorWipe(uint32_t c, uint8_t wait) {
  49. for(uint16_t i=0; i<strip.numPixels(); i++) {
  50. strip.setPixelColor(i, c);
  51. strip.show();
  52. delay(wait);
  53. }
  54. }
  55.  
  56. void rainbow(uint8_t wait) {
  57. uint16_t i, j;
  58.  
  59. for(j=0; j<256; j++) {
  60. for(i=0; i<strip.numPixels(); i++) {
  61. strip.setPixelColor(i, Wheel((i+j) & 255));
  62. }
  63. strip.show();
  64. delay(wait);
  65. }
  66. }
  67.  
  68. // Slightly different, this makes the rainbow equally distributed throughout
  69. void rainbowCycle(uint8_t wait) {
  70. uint16_t i, j;
  71.  
  72. for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  73. for(i=0; i< strip.numPixels(); i++) {
  74. strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  75. }
  76. strip.show();
  77. delay(wait);
  78. }
  79. }
  80.  
  81. //Theatre-style crawling lights.
  82. void theaterChase(uint32_t c, uint8_t wait) {
  83. for (int j=0; j<10; j++) { //do 10 cycles of chasing
  84. for (int q=0; q < 3; q++) {
  85. for (int i=0; i < strip.numPixels(); i=i+3) {
  86. strip.setPixelColor(i+q, c); //turn every third pixel on
  87. }
  88. strip.show();
  89.  
  90. delay(wait);
  91.  
  92. for (int i=0; i < strip.numPixels(); i=i+3) {
  93. strip.setPixelColor(i+q, 0); //turn every third pixel off
  94. }
  95. }
  96. }
  97. }
  98.  
  99. //Theatre-style crawling lights with rainbow effect
  100. void theaterChaseRainbow(uint8_t wait) {
  101. for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
  102. for (int q=0; q < 3; q++) {
  103. for (int i=0; i < strip.numPixels(); i=i+3) {
  104. strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
  105. }
  106. strip.show();
  107.  
  108. delay(wait);
  109.  
  110. for (int i=0; i < strip.numPixels(); i=i+3) {
  111. strip.setPixelColor(i+q, 0); //turn every third pixel off
  112. }
  113. }
  114. }
  115. }
  116.  
  117. // Input a value 0 to 255 to get a color value.
  118. // The colours are a transition r - g - b - back to r.
  119. uint32_t Wheel(byte WheelPos) {
  120. WheelPos = 255 - WheelPos;
  121. if(WheelPos < 85) {
  122. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  123. } else if(WheelPos < 170) {
  124. WheelPos -= 85;
  125. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  126. } else {
  127. WheelPos -= 170;
  128. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement