Skip to content

Instantly share code, notes, and snippets.

@oesterle
Created July 5, 2018 00:00
Show Gist options
  • Save oesterle/69e4ebb0a5591bbf586564ee1dc72b58 to your computer and use it in GitHub Desktop.
Save oesterle/69e4ebb0a5591bbf586564ee1dc72b58 to your computer and use it in GitHub Desktop.
Test of Adafruit Feather M4 Express' built-in NeoPixel, with modified WheelDim() function.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// Modified by @erico to test Adafruit Feather M4 Express
// The NeoPixel pin is defined as 6 in examples.
// Adafruit Feather M4 Express uses pin 8 for its built-in NeoPixel.
#define PIN 8
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rainbow(5);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
uint8_t maxBright = 4;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, WheelDim((i+j) & 255, maxBright));
}
strip.show();
delay(wait);
}
}
// A version of Wheel that dims pixels down for photos/video
// maxBright is from 0 to 255; low numbers are dimmer.
// NeoPixel brightness is nonlinear, so play with the maxBright number. I used 4 for recent video.
uint32_t WheelDim(byte WheelPos, uint8_t maxBright){
WheelPos = 255 - WheelPos;
uint16_t r = 0, g = 0, b = 0;
if(WheelPos < 85) {
r = 255 - WheelPos * 3;
b = WheelPos * 3;
} else if(WheelPos < 170) {
WheelPos -= 85;
g = WheelPos * 3;
b = 255 - WheelPos * 3;
} else {
WheelPos -= 170;
r = WheelPos * 3;
g = 255 - WheelPos * 3;
}
r = r * maxBright / 255;
g = g * maxBright / 255;
b = b * maxBright / 255;
return strip.Color(r, g, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment