Advertisement
Drakkheen

Untitled

May 9th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  4. #endif
  5.  
  6. // Which pin on the Arduino is connected to the NeoPixels?
  7. // On a Trinket or Gemma we suggest changing this to 1:
  8. #define LED_PIN  1
  9.  
  10. // How many NeoPixels are attached to the Arduino?
  11. #define LED_COUNT 5
  12.  
  13. // Declare our NeoPixel strip object:
  14. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  15. // Argument 1 = Number of pixels in NeoPixel strip
  16. // Argument 2 = Arduino pin number (most are valid)
  17. // Argument 3 = Pixel type flags, add together as needed:
  18. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  19. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  20. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  21. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  22. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  23.  
  24.  
  25. // setup() function -- runs once at startup --------------------------------
  26.  
  27. void setup() {
  28.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  29.   // Any other board, you can remove this part (but no harm leaving it):
  30. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  31.   clock_prescale_set(clock_div_1);
  32. #endif
  33.   // END of Trinket-specific code.
  34.  
  35.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  36.   strip.show();            // Turn OFF all pixels ASAP
  37.   strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  38. }
  39.  
  40.  
  41. // loop() function -- runs repeatedly as long as board is on ---------------
  42.  
  43. void loop() {
  44.   redPulse(30); // Red
  45.  
  46.   greenPulse(30); // green
  47.  
  48.   bluePulse(30); // blue
  49.  
  50.   colorWipe(strip.Color(  255,   0, 0), 300); // red
  51.  
  52.   colorWipe_r(strip.Color(  0, 255,   0), 300); // Green
  53.  
  54.   colorWipe(strip.Color(0,   0,   255), 300); // Blue
  55.  
  56.   rainbow(50);             // Flowing rainbow cycle along the whole strip
  57. }
  58.  
  59.  
  60. // Some functions of our own for creating animated effects -----------------
  61.  
  62. // Fill strip pixels one after another with a color. Strip is NOT cleared
  63. // first; anything there will be covered pixel by pixel. Pass in color
  64. // (as a single 'packed' 32-bit value, which you can get by calling
  65. // strip.Color(red, green, blue) as shown in the loop() function above),
  66. // and a delay time (in milliseconds) between pixels.
  67.  
  68. void colorWipe(uint32_t color, int wait) {
  69.   for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  70.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  71.     strip.show();                          //  Update strip to match
  72.     delay(wait);                           //  Pause for a moment
  73.   }
  74. }
  75.  
  76. void colorWipe_r(uint32_t color, int wait) {
  77.   for (int i = strip.numPixels() + 1; i > 0; i--) { // For each pixel in strip...
  78.     strip.setPixelColor(i - 1, color);   //  Set pixel's color (in RAM)
  79.     strip.show();                          //  Update strip to match
  80.     delay(wait);                           //  Pause for a moment
  81.   }
  82. }
  83.  
  84. void redPulse(int wait) {
  85.   for (int c = 0; c < 255; c++) {
  86.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  87.       strip.setPixelColor(i, c, 0, 0);     //  Set pixel's color (in RAM)
  88.       strip.show();                          //  Update strip to match
  89.     }
  90.     delay(wait);
  91.   }
  92.  
  93.   for (int c = 255; c > 0; c--) {
  94.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  95.       strip.setPixelColor(i, c, 0, 0);     //  Set pixel's color (in RAM)
  96.       strip.show();                          //  Update strip to match
  97.     }
  98.     delay(wait);
  99.   }
  100. }
  101.  
  102. void greenPulse(int wait) {
  103.   for (int c = 0; c < 255; c++) {
  104.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  105.       strip.setPixelColor(i, 0, c, 0);     //  Set pixel's color (in RAM)
  106.       strip.show();                          //  Update strip to match
  107.  
  108.     }
  109.     delay(wait);
  110.   }
  111.   for (int c = 255; c > 0; c--) {
  112.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  113.       strip.setPixelColor(i, 0, c, 0);     //  Set pixel's color (in RAM)
  114.       strip.show();                          //  Update strip to match
  115.     }
  116.     delay(wait);
  117.   }
  118. }
  119.  
  120. void bluePulse(int wait) {
  121.   for (int c = 0; c < 255; c++) {
  122.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  123.       strip.setPixelColor(i, 0, 0, c);     //  Set pixel's color (in RAM)
  124.       strip.show();                          //  Update strip to match
  125.  
  126.     }
  127.     delay(wait);
  128.   }
  129.   for (int c = 255; c > 0; c--) {
  130.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  131.       strip.setPixelColor(i, 0, 0, c);     //  Set pixel's color (in RAM)
  132.       strip.show();                          //  Update strip to match
  133.     }
  134.     delay(wait);
  135.   }
  136. }
  137.  
  138.  
  139.  
  140. // Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
  141. void rainbow(int wait) {
  142.   // Hue of first pixel runs 5 complete loops through the color wheel.
  143.   // Color wheel has a range of 65536 but it's OK if we roll over, so
  144.   // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  145.   // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  146.   for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
  147.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  148.       // Offset pixel hue by an amount to make one full revolution of the
  149.       // color wheel (range of 65536) along the length of the strip
  150.       // (strip.numPixels() steps):
  151.       int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  152.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  153.       // optionally add saturation and value (brightness) (each 0 to 255).
  154.       // Here we're using just the single-argument hue variant. The result
  155.       // is passed through strip.gamma32() to provide 'truer' colors
  156.       // before assigning to each pixel:
  157.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  158.     }
  159.     strip.show(); // Update strip with new contents
  160.     delay(wait);  // Pause for a moment
  161.   }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement