Advertisement
Guest User

Untitled

a guest
May 28th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #define PIN 6
  3.  
  4. Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800);
  5.  
  6. void setup() {
  7. strip.begin();
  8. strip.show(); // Initialize all pixels to 'off'
  9. }
  10.  
  11. void loop() {
  12. rainbow(20); //change the value to change speed
  13. }
  14.  
  15. void rainbow(uint8_t wait) {
  16. uint16_t i, j;
  17.  
  18. for(j=0; j<256; j++) {
  19. for(i=0; i<strip.numPixels(); i++) {
  20. strip.setPixelColor(i, Wheel((i+j) & 255));
  21. }
  22. strip.show();
  23. delay(wait);
  24. }
  25. }
  26. // Input a value 0 to 255 to get a color value.
  27. // The colours are a transition r - g - b - back to r.
  28. uint32_t Wheel(byte WheelPos) {
  29. WheelPos = 255 - WheelPos;
  30. if(WheelPos < 85) {
  31. return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  32. }
  33. if(WheelPos < 170) {
  34. WheelPos -= 85;
  35. return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  36. }
  37. WheelPos -= 170;
  38. return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement