user_neopixel.cpp
1 // SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #if 0 // Change to 1 to enable this code (must enable ONE user*.cpp only!) 6 7 #include <Adafruit_NeoPixel.h> 8 9 #define LED_PIN 8 10 #define LED_COUNT 4 11 Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); 12 13 void user_setup(void) { 14 strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) 15 strip.show(); // Turn OFF all pixels ASAP 16 strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) 17 } 18 19 long firstPixelHue = 0; 20 21 void user_loop(void) { 22 for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip... 23 // Offset pixel hue by an amount to make one full revolution of the 24 // color wheel (range of 65536) along the length of the strip 25 // (strip.numPixels() steps): 26 int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels()); 27 // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or 28 // optionally add saturation and value (brightness) (each 0 to 255). 29 // Here we're using just the single-argument hue variant. The result 30 // is passed through strip.gamma32() to provide 'truer' colors 31 // before assigning to each pixel: 32 strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue))); 33 } 34 strip.show(); // Update strip with new contents 35 firstPixelHue += 256; 36 } 37 38 #endif // 0