Advertisement
Guest User

Untitled

a guest
Nov 12th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. //CODE ORIGINALLY AS AN EXAMPLE ON ADAFRUIT'S NEOPIXEL LIBRARY
  2. //Editied by PerfectPixel for the GLOWPAD project on instructables.com
  3. //http://www.instructables.com/member/perfectpixel/
  4.  
  5.  
  6. #include <Adafruit_NeoPixel.h>
  7. #ifdef __AVR__
  8.   #include <avr/power.h>
  9. #endif
  10.  
  11. #define PIN 9
  12.  
  13. // Parameter 1 = number of pixels in strip
  14. // Parameter 2 = Arduino pin number (most are valid)
  15. // Parameter 3 = pixel type flags, add together as needed:
  16. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  17. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  18. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  19. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  20. Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
  21.  
  22. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  23. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  24. // and minimize distance between Arduino and first pixel.  Avoid connecting
  25. // on a live circuit...if you must, connect GND first.
  26.  
  27. void setup() {
  28.   // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  29.   #if defined (__AVR_ATtiny85__)
  30.     if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  31.   #endif
  32.   // End of trinket special code
  33.  
  34.  
  35.   strip.begin();
  36.   strip.show(); // Initialize all pixels to 'off'
  37. }
  38.  
  39. void loop() {
  40.   rainbowCycle(20);
  41. }
  42.  
  43. // Slightly different, this makes the rainbow equally distributed throughout
  44. void rainbowCycle(uint8_t wait) {
  45.   uint16_t i, j;
  46.  
  47.   for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  48.     for(i=0; i< strip.numPixels(); i++) {
  49.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  50.     }
  51.     strip.show();
  52.     delay(wait);
  53.   }
  54. }
  55.  
  56. // Input a value 0 to 255 to get a color value.
  57. // The colours are a transition r - g - b - back to r.
  58. uint32_t Wheel(byte WheelPos) {
  59.   WheelPos = 255 - WheelPos;
  60.   if(WheelPos < 85) {
  61.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  62.   }
  63.   if(WheelPos < 170) {
  64.     WheelPos -= 85;
  65.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  66.   }
  67.   WheelPos -= 170;
  68.   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement