jsmirnio

Arduino G35 Color Effects CandyCane Pattern 2015

Dec 24th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.65 KB | None | 0 0
  1. /*
  2.   G35: An Arduino library for GE Color Effects G-35 holiday lights.
  3.   Copyright © 2011 The G35 Authors. Use, modification, and distribution are
  4.   subject to the BSD license as described in the accompanying LICENSE file.
  5.  
  6.   See README for complete attributions.
  7. */
  8.  
  9. #include <MyG35String.h>
  10.  
  11. // Total # of lights on string (usually 25 - 50). Maximum is 63, because
  12. // the protocol uses 6-bit addressing and bulb #63 is reserved for broadcast
  13. // messages.
  14. #define LIGHT_COUNT (25)
  15.  
  16. // Arduino pin number. Pin 13 will blink the on-board LED.
  17. #define G35_PIN (13)
  18.  
  19. G35String lights(G35_PIN, LIGHT_COUNT);
  20.  
  21. void setup() {
  22.   lights.enumerate();
  23.   lights.do_test_patterns();
  24.   delay(1000);
  25.  
  26.   candycane();
  27.   delay(5000);
  28.  
  29.   pileup();
  30.   delay(5000);
  31. }
  32.  
  33. void loop() {
  34.   lights.fill_color(0, LIGHT_COUNT, G35::MAX_INTENSITY, COLOR_RED);
  35.   delay(1000);
  36.  
  37.   lights.fill_color(0, LIGHT_COUNT, G35::MAX_INTENSITY, COLOR_GREEN);
  38.   delay(1000);
  39.  
  40.   candycane();
  41.   delay(5000);
  42.  
  43.   pileup();
  44.   delay(5000);
  45.  
  46.   static uint16_t c;
  47.   lights.fill_color(0, LIGHT_COUNT, G35::MAX_INTENSITY, G35::rainbow_color(c++));
  48.   delay(1000);
  49.  
  50. }
  51.  
  52.  
  53. void test_pattern() {
  54.   // Tickle the ends. You should see three reds at the start, and three greens
  55.   // at the end. This confirms that you've properly configured the strand
  56.   // lengths and directions.
  57.   uint8_t last_light = LIGHT_COUNT - 1;
  58.   uint8_t BROADCAST_BULB = 63;
  59.   uint8_t MAX_INTENSITY = 255;
  60.   for (int i = 0; i < 8; ++i) {
  61.     for (int j = 0; j < 3; ++j) {
  62.       lights.set_color(BROADCAST_BULB, 0, COLOR_BLACK);
  63.       lights.set_color(j, MAX_INTENSITY, COLOR_RED);
  64.       lights.set_color(last_light - j, MAX_INTENSITY, COLOR_GREEN);
  65.       delay(250);
  66.     }
  67.   }
  68. }
  69.  
  70. void pileup() {
  71.   // LEDs Converge on the center from both ends
  72.   uint8_t last_light = LIGHT_COUNT - 1;
  73.   uint8_t BROADCAST_BULB = 63;
  74.   uint8_t MAX_INTENSITY = 255;
  75.  
  76.   for (int sequence = 0; sequence < 30; ++ sequence) {
  77.     lights.set_color(BROADCAST_BULB, 0, COLOR_BLACK);
  78.     for (int frame = 0; frame < last_light; ++frame) {
  79.       lights.set_color(BROADCAST_BULB, 0, COLOR_BLACK);
  80.       for (int j = 0; j < last_light / 2; ++j) {
  81.         //        lights.set_color(BROADCAST_BULB, 0, COLOR_BLACK);
  82.         lights.set_color(j, MAX_INTENSITY, COLOR_GREEN); // SET COLOR FROM BEGINNING;
  83.         lights.set_color(last_light - j, MAX_INTENSITY, COLOR_RED); // SET COLOR FROM THE END;
  84.         delay (100); // PAUSE BETWEEN ITEMS;
  85.       }
  86.       lights.set_color(last_light / 2, MAX_INTENSITY, COLOR_WHITE); // SET COLOR IN MIDDLE;
  87.       delay(500); // PAUSE BETWEEN FRAMES;
  88.     }
  89.   } // COUNT NUMBER OF SEQUENCES;
  90. }
  91.  
  92. void candycane() {
  93.   // LED Movine Stripes
  94.   uint8_t last_light = LIGHT_COUNT - 1;
  95.   uint8_t BROADCAST_BULB = 63;
  96.   uint8_t MAX_INTENSITY = 255;
  97.  
  98.   uint8_t numPixels = LIGHT_COUNT;
  99.   int num_sets = 30;
  100.   int Width = 4;
  101.   int L = 0;
  102.  
  103.   for (int set = 0; set < num_sets; ++ set) {
  104.     //    lights.set_color(BROADCAST_BULB, 0, COLOR_BLACK);// RESET ALL LEDs OFF
  105.  
  106.     for (int frame = 0; frame < last_light; ++frame) {
  107.       //      lights.set_color(BROADCAST_BULB, 0, COLOR_BLACK);
  108.  
  109.       for (int i = 0; i < numPixels; i++) {
  110.         L = numPixels - i - 1; // Which Pixel to Update;
  111.         if ( ((frame + i) % ((Width * 2)) ) < (Width) ) {
  112.           lights.set_color(L, MAX_INTENSITY, COLOR_RED); // SET PIXEL L COLOR TO RED
  113.         } else {
  114.           lights.set_color(L, MAX_INTENSITY, COLOR_GREEN); // SET PIXEL L COLOR TO WHITE
  115.         }
  116.         delay (10); // PAUSE BETWEEN ITEMS;
  117.       }
  118.       delay(10); // PAUSE BETWEEN FRAMES;    }
  119.     }
  120.   } // COUNT NUMBER OF SETS;
  121. } // END FUNCTION CANDYCANE
Advertisement
Add Comment
Please, Sign In to add comment