Advertisement
joymonkey

LED_Tester.ino

May 13th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.97 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h> //Adafruit_Neopixel library is required
  2.                                // download from : https://github.com/adafruit/Adafruit_NeoPixel
  3.  
  4. #define PIN 1 //this is the digital pin number that will control the LEDs
  5.  
  6. ////////////////////////////////////////////////////////////////////////////////////////////////
  7. ////////////////////////////////////////////////////////////////////////////////////////////////
  8.  
  9. Adafruit_NeoPixel strip = Adafruit_NeoPixel(96, PIN, NEO_GRB + NEO_KHZ800);
  10.  
  11. void setup() {
  12.   strip.begin();
  13.   strip.show(); // Initialize all pixels to 'off'
  14.   strip.setBrightness(30);  // 0-255 , for testing keep this low to increase battery life and prevent blinding
  15. }
  16.  
  17. void loop() {
  18.   rainbow(2);
  19. }
  20.  
  21. // Fill the dots one after the other with a color
  22. void colorWipe(uint32_t c, uint8_t wait) {
  23.   for(uint16_t i=0; i<strip.numPixels(); i++) {
  24.       strip.setPixelColor(i, c);
  25.       strip.show();
  26.       delay(wait);
  27.   }
  28. }
  29.  
  30. void rainbow(uint8_t wait) {
  31.   uint16_t i, j;
  32.  
  33.   for(j=0; j<256; j++) {
  34.     for(i=0; i<strip.numPixels(); i++) {
  35.       strip.setPixelColor(i, Wheel((i+j) & 255));
  36.     }
  37.     strip.show();
  38.     delay(wait);
  39.   }
  40. }
  41.  
  42. // Slightly different, this makes the rainbow equally distributed throughout
  43. void rainbowCycle(uint8_t wait) {
  44.   uint16_t i, j;
  45.  
  46.   for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  47.     for(i=0; i< strip.numPixels(); i++) {
  48.       strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
  49.     }
  50.     strip.show();
  51.     delay(wait);
  52.   }
  53. }
  54.  
  55. // Input a value 0 to 255 to get a color value.
  56. // The colours are a transition r - g - b - back to r.
  57. uint32_t Wheel(byte WheelPos) {
  58.   if(WheelPos < 85) {
  59.    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  60.   } else if(WheelPos < 170) {
  61.    WheelPos -= 85;
  62.    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  63.   } else {
  64.    WheelPos -= 170;
  65.    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement