daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest May 29th, 2016 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2. #define PIN 6
  3. Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800);
  4.  
  5. int x = 150; //change these values to fade between the two.
  6. int y = 220;
  7.  
  8. void setup() {
  9.   strip.begin();
  10.   strip.show(); // Initialize all pixels to 'off'
  11. }
  12.  
  13. void loop() {
  14.   fade(160); //change the number here to adjust the speed
  15. }
  16.  
  17. void fade(uint8_t wait) {
  18.   uint16_t i, j;
  19.  
  20.   //Adjust 60 and 90 to the starting and ending colors you want to fade between.
  21.   for(j=x; j<y; j++) {
  22.     for(i=0; i<strip.numPixels(); i++) {
  23.       strip.setPixelColor(i, Wheel((i+j) & 255));
  24.     }
  25.     strip.show();
  26.     delay(wait);
  27.   }
  28.     delay(wait);
  29.   for(j=y; j>x; j--) {
  30.     for(i=0; i<strip.numPixels(); i++) {
  31.       strip.setPixelColor(i, Wheel((i+j) & 255));
  32.     }
  33.     strip.show();
  34.     delay(wait);
  35.   }
  36. }
  37.  
  38. // Input a value 0 to 255 to get a color value.
  39. // The colours are a transition r - g - b - back to r.
  40. uint32_t Wheel(byte WheelPos) {
  41.   if(WheelPos < 85) {
  42.    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  43.   } else if(WheelPos < 170) {
  44.    WheelPos -= 85;
  45.    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  46.   } else {
  47.    WheelPos -= 170;
  48.    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  49.   }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top