Advertisement
Guest User

Testing NeoPixel

a guest
May 19th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. //import good stuff to make the neopixel work
  2. #include <Adafruit_NeoPixel.h>
  3. #include <avr/power.h>
  4.  
  5. //define pin for neopixel
  6. #define PIN 6
  7.  
  8. //initialize the neopixel object (number of LEDs, pin number, color mode)
  9. Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
  10.  
  11. void setup() {
  12.   strip.begin();
  13.   strip.setBrightness(3);
  14.   strip.show(); // Initialize all pixels to 'off'
  15. }
  16.  
  17. void loop() {
  18.   int line = 11;
  19.   lineLoop(line);
  20.   lineStatic(line);
  21.   lineResize(line);
  22.   lineStatic(line);
  23. }
  24.  
  25. //creates a line that moves around the ring
  26. void lineLoop(int length) {
  27.   for (int i = 0; i < 24; i++) {  
  28.     for (int j = 0; j < length; j++) {
  29.       int light = i + j;
  30.       if (light > 23) {
  31.         light -= 24;
  32.       }
  33.       strip.setPixelColor(light, strip.Color(255, 0, 0));
  34.     }
  35.     strip.show();
  36.     delay(50);
  37.     for (int k = 0; k < 24; k++) {
  38.       strip.setPixelColor(k, 0);
  39.     }
  40.     strip.show();
  41.   }  
  42. }
  43.  
  44. //creates a line in place
  45. void lineStatic(int length) {
  46.   for (int i = 0; i < length; i++) {
  47.     strip.setPixelColor(i, strip.Color(255, 0, 0));
  48.   }
  49.   strip.show();
  50.   delay(500);
  51. }
  52.  
  53. //shrinks the line and expands it to its previous size
  54. void lineResize(int length) {
  55.   for (int j = 0; j < 3; j++) {
  56.     //shrinks
  57.     for (int i = 0; i < ((length-1)/2); i++) {
  58.       strip.setPixelColor(i, 0);
  59.       strip.setPixelColor(length-1-i, 0);
  60.       strip.show();
  61.       delay(75);
  62.     }
  63.    
  64.     //expands
  65.     for (int i = ((length-1)/2) - 1; i >= 0; i--) {
  66.       strip.setPixelColor(i, strip.Color(255, 0, 0));
  67.       strip.setPixelColor(length-1-i, strip.Color(255, 0, 0));
  68.  
  69.       strip.show();
  70.       delay(16);
  71.     }
  72.   }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement