Advertisement
TopHatRaver

Adafruit_Version

Aug 12th, 2024
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3.  #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  4. #endif
  5.  
  6. // Which pin on the Arduino is connected to the NeoPixels?
  7. int pin         =  6; // On Trinket or Gemma, suggest changing this to 1
  8.  
  9. // How many NeoPixels are attached to the Arduino?
  10. int numPixels   = 722; // Popular NeoPixel ring size
  11.  
  12. // NeoPixel color format & data rate. See the strandtest example for
  13. // information on possible values.
  14. int pixelFormat = NEO_GRB + NEO_KHZ800;
  15.  
  16. // Rather than declaring the whole NeoPixel object here, we just create
  17. // a pointer for one, which we'll then allocate later...
  18. Adafruit_NeoPixel *pixels;
  19.  
  20. #define DELAYVAL 5 // Time (in milliseconds) to pause between pixels
  21.  
  22. void setup() {
  23.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  24.   // Any other board, you can remove this part (but no harm leaving it):
  25. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  26.   clock_prescale_set(clock_div_1);
  27. #endif
  28.   // END of Trinket-specific code.
  29.  
  30.   // Right about here is where we could read 'pin', 'numPixels' and/or
  31.   // 'pixelFormat' from EEPROM or a file on SD or whatever. This is a simple
  32.   // example and doesn't do that -- those variables are just set to fixed
  33.   // values at the top of this code -- but this is where it would happen.
  34.  
  35.   // Then create a new NeoPixel object dynamically with these values:
  36.   pixels = new Adafruit_NeoPixel(numPixels, pin, pixelFormat);
  37.  
  38.   // Going forward from here, code works almost identically to any other
  39.   // NeoPixel example, but instead of the dot operator on function calls
  40.   // (e.g. pixels.begin()), we instead use pointer indirection (->) like so:
  41.   pixels->begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  42.   // You'll see more of this in the loop() function below.
  43. }
  44.  
  45. void loop() {
  46.   // pixels->clear(); // Set all pixel colors to 'off'
  47.  
  48.   // The first NeoPixel in a strand is #0, second is 1, all the way up
  49.   // to the count of pixels minus one.
  50.   for(int i=0; i<numPixels; i++) { // For each pixel...
  51.  
  52.     // pixels->Color() takes RGB values, from 0,0,0 up to 255,255,255
  53.     // Here we're using a moderately bright green color:
  54.     pixels->setPixelColor(i, pixels->Color(0, 150, 0));
  55.  
  56.     pixels->show();   // Send the updated pixel colors to the hardware.
  57.  
  58.     delay(DELAYVAL); // Pause before next pass through loop
  59.   }
  60.   delay(10000);
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement