Advertisement
Szerelo

Christmas tree top decoration

Nov 13th, 2022 (edited)
1,036
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.90 KB | None | 0 0
  1. // Christmas tree top decoration
  2. // https://youtu.be/clKjGI5lEXQ
  3.  
  4. #include <Adafruit_NeoPixel.h>
  5.  
  6. #define LED_PIN    6
  7.  
  8. #define LED_COUNT 24
  9.  
  10. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  11.  
  12. uint16_t villDelay=300;
  13.  
  14. void setup() {
  15.   Serial.begin(115200);
  16.   Serial.println("Start ...");
  17.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  18.   strip.show();            // Turn OFF all pixels ASAP
  19.   strip.setBrightness(30); // Set BRIGHTNESS to about 1/5 (max = 255)
  20. }
  21.  
  22. void loop() {
  23.   commo();
  24.   colorWipe(strip.Color(255,   0,   0), 50); // Red
  25.   colorWipe(strip.Color(  0, 255,   0), 50); // Green
  26.   colorWipe(strip.Color(  0,   0, 255), 50); // Blue
  27.   theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
  28.   theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  29.   theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness
  30.   commo();
  31.   rainbow(10);             // Flowing rainbow cycle along the whole strip
  32.   commo();
  33.   theaterChaseRainbow(100); // Rainbow-enhanced theaterChase variant
  34. }
  35.  
  36. void colorWipe(uint32_t color, int wait) {
  37.   for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  38.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  39.     strip.show();                          //  Update strip to match
  40.     delay(wait);                           //  Pause for a moment
  41.   }
  42. }
  43.  
  44. void theaterChase(uint32_t color, int wait) {
  45.   for(int a=0; a<10; a++) {  // Repeat 10 times...
  46.     for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
  47.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  48.       // 'c' counts up from 'b' to end of strip in steps of 3...
  49.       for(int c=b; c<strip.numPixels(); c += 3) {
  50.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  51.       }
  52.       strip.show(); // Update strip with new contents
  53.       delay(wait);  // Pause for a moment
  54.     }
  55.   }
  56. }
  57.  
  58. void rainbow(int wait) {
  59.   for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
  60.     strip.rainbow(firstPixelHue);
  61.     strip.show(); // Update strip with new contents
  62.     delay(wait);  // Pause for a moment
  63.   }
  64. }
  65.  
  66. void theaterChaseRainbow(int wait) {
  67.   int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  68.   for(int a=0; a<30; a++) {  // Repeat 30 times...
  69.     for(int b=0; b<3; b++) { //  'b' counts from 0 to 2...
  70.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  71.       for(int c=b; c<strip.numPixels(); c += 3) {
  72.         int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
  73.         uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
  74.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  75.       }
  76.       strip.show();                // Update strip with new contents
  77.       delay(wait);                 // Pause for a moment
  78.       firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
  79.     }
  80.   }
  81. }
  82.  
  83. void commo(){
  84.   strip.clear();
  85.   strip.show();
  86.   villDelay=50;
  87.   for(int i=24; i>16; i--) {        // !
  88.     strip.setPixelColor(i, strip.Color(255, 0, 0));
  89.     strip.show();
  90.     delay(villDelay);    
  91.   }
  92.   strip.setPixelColor(15, strip.Color(255, 0, 0));
  93.   strip.show();
  94.   delay(villDelay*10);    
  95.   for(int i=0; i<7; i++) {    // Kör 2 oldalt le
  96.     strip.setPixelColor(7+i, strip.Color(255, 0, 0));
  97.     strip.setPixelColor(7-i, strip.Color(255, 0, 0));
  98.     strip.show();
  99.     delay(villDelay);    
  100.   }
  101.  
  102.   delay(villDelay*10);    
  103.    for(int i=24; i>16; i--) {
  104.     strip.setPixelColor(i, strip.Color(0, 255, 0));
  105.     strip.show();
  106.     delay(villDelay);    
  107.   }
  108.   strip.setPixelColor(15, strip.Color(0, 255, 0));
  109.   strip.show();
  110.  
  111.   delay(villDelay*10);    
  112.   for(int i=7; i>0; i--) {
  113.     strip.setPixelColor(6+i, strip.Color(0, 0, 0));
  114.     strip.setPixelColor(7-i, strip.Color(0, 0, 0));
  115.     strip.show();
  116.     delay(villDelay);    
  117.   }
  118.  
  119.   delay(villDelay*10);    
  120.   for(int i=24; i>16; i--) {
  121.     strip.setPixelColor(i, strip.Color(255, 0, 0));
  122.     strip.show();
  123.     delay(villDelay);    
  124.   }
  125.   strip.setPixelColor(15, strip.Color(255, 0, 0));
  126.   strip.show();
  127.  
  128.   delay(villDelay*10);    
  129.   for(int i=1; i<14; i++) {
  130.     strip.setPixelColor(i, strip.Color(255, 0, 0));
  131.     strip.show();
  132.     delay(villDelay);    
  133.   }
  134.   delay(villDelay*10);    
  135.   for(int i=1; i<14; i++) {
  136.     strip.setPixelColor(i, strip.Color(0, 0, 0));
  137.     strip.show();
  138.     delay(villDelay);    
  139.   }
  140.  
  141.   delay(villDelay*10);    
  142.   for(int i=24; i>16; i--) {
  143.     strip.setPixelColor(i, strip.Color(0, 255, 0));
  144.     strip.show();
  145.     delay(villDelay);    
  146.   }
  147.   strip.setPixelColor(15, strip.Color(0, 255, 0));
  148.   strip.show();
  149.  
  150.  
  151.   delay(villDelay*10);    
  152.   for(int i=1; i<14; i++) {
  153.     strip.setPixelColor(14-i, strip.Color(255, 0, 0));
  154.     strip.show();
  155.     delay(villDelay);    
  156.   }
  157.  
  158.  
  159.  
  160.   delay(villDelay*10);    
  161.   for(int i=1; i<14; i++) {
  162.     strip.setPixelColor(14-i, strip.Color(0, 0, 0));
  163.     strip.show();
  164.     delay(villDelay);    
  165.   }
  166.  
  167.   villDelay=200;
  168.   for(int j=0; j<3; j++) {
  169.     strip.clear();
  170.     strip.show();
  171.     delay(villDelay);    
  172.     for(int i=24; i>16; i--) {
  173.       strip.setPixelColor(i, strip.Color(0, 255, 0));
  174.     }
  175.     strip.setPixelColor(15, strip.Color(0, 255, 0));
  176.     strip.show();
  177.     delay(villDelay);    
  178.     strip.clear();
  179.     strip.show();
  180.     delay(villDelay);    
  181.     for(int i=24; i>16; i--) {
  182.       strip.setPixelColor(i, strip.Color(0, 0, 255));
  183.     }
  184.     strip.setPixelColor(15, strip.Color(0, 0, 255));
  185.     strip.show();
  186.     delay(villDelay);    
  187.     strip.clear();
  188.     strip.show();
  189.     delay(villDelay);    
  190.     for(int i=24; i>16; i--) {
  191.       strip.setPixelColor(i, strip.Color(255, 0, 0));
  192.     }
  193.     strip.setPixelColor(15, strip.Color(255, 0, 0));
  194.     strip.show();
  195.     delay(villDelay);    
  196.   }  
  197.   strip.clear();
  198.   strip.show();
  199.   delay(1000);    
  200. }
  201.  
  202.  
  203. // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement