// NeoPixel Ring simple sketch (c) 2013 Shae Erisson // Released under the GPLv3 license to match the rest of the // Adafruit NeoPixel library // This sketch shows use of the "new" operator with Adafruit_NeoPixel. // It's helpful if you don't know NeoPixel settings at compile time or // just want to store this settings in EEPROM or a file on an SD card. #include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #endif // Which pin on the Arduino is connected to the NeoPixels? int pin = 6; // On Trinket or Gemma, suggest changing this to 1 // How many NeoPixels are attached to the Arduino? int numPixels = 16; // Popular NeoPixel ring size // NeoPixel color format & data rate. See the strandtest example for // information on possible values. int pixelFormat = NEO_GRB + NEO_KHZ800; // Rather than declaring the whole NeoPixel object here, we just create // a pointer for one, which we'll then allocate later... Adafruit_NeoPixel *pixels; #define DELAYVAL 500 // Time (in milliseconds) to pause between pixels void setup() { // These lines are specifically to support the Adafruit Trinket 5V 16 MHz. // Any other board, you can remove this part (but no harm leaving it): #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // END of Trinket-specific code. // Right about here is where we could read 'pin', 'numPixels' and/or // 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple // example and doesn't do that -- those variables are just set to fixed // values at the top of this code -- but this is where it would happen. // Then create a new NeoPixel object dynamically with these values: pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat); // Going forward from here, code works almost identically to any other // NeoPixel example, but instead of the dot operator on function calls // (e.g. pixels.begin()), we instead use pointer indirection (->) like so: pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED) // You'll see more of this in the loop() function below. } void loop() { pixels->clear(); // Set all pixel colors to 'off' // The first NeoPixel in a strand is #0, second is 1, all the way up // to the count of pixels minus one. for(int i=0; iColor() takes RGB values, from 0,0,0 up to 255,255,255 // Here we're using a moderately bright green color: pixels->setPixelColor(i, pixels->Color(0, 150, 0)); pixels->show(); // Send the updated pixel colors to the hardware. delay(DELAYVAL); // Pause before next pass through loop } }