Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. // Simple strand test for Adafruit Dot Star RGB LED strip.
  2. // This is a basic diagnostic tool, NOT a graphics demo...helps confirm
  3. // correct wiring and tests each pixel's ability to display red, green
  4. // and blue and to forward data down the line. By limiting the number
  5. // and color of LEDs, it's reasonably safe to power a couple meters off
  6. // the Arduino's 5V pin. DON'T try that with other code!
  7.  
  8. #include <Adafruit_DotStar.h>
  9. // Because conditional #includes don't work w/Arduino sketches...
  10. #include <SPI.h> // COMMENT OUT THIS LINE FOR GEMMA OR TRINKET
  11. //#include <avr/power.h> // ENABLE THIS LINE FOR GEMMA OR TRINKET
  12.  
  13. #define NUMPIXELS 144 // Number of LEDs in strip
  14.  
  15. // Here's how to control the LEDs from any two pins:
  16. // #define DATAPIN 4
  17. // #define CLOCKPIN 5
  18. // Adafruit_DotStar strip = Adafruit_DotStar(
  19. // NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);
  20. // The last parameter is optional -- this is the color data order of the
  21. // DotStar strip, which has changed over time in different production runs.
  22. // Your code just uses R,G,B colors, the library then reassigns as needed.
  23. // Default is DOTSTAR_BRG, so change this if you have an earlier strip.
  24.  
  25. // Hardware SPI is a little faster, but must be wired to specific pins
  26. // (Arduino Uno = pin 11 for data, 13 for clock, other boards are different).
  27. Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);
  28.  
  29. void setup() {
  30.  
  31. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
  32. clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
  33. #endif
  34.  
  35. strip.begin(); // Initialize pins for output
  36. strip.show(); // Turn all LEDs off ASAP
  37. }
  38.  
  39. // Runs 10 LEDs at a time along strip, cycling through red, green and blue.
  40. // This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel.
  41.  
  42. int head = 0, tail = -10; // Index of first 'on' and 'off' pixels
  43. uint32_t color = 0xFF0000; // 'On' color (starts red)
  44.  
  45. void loop() {
  46.  
  47. strip.setPixelColor(head, color); // 'On' pixel at head
  48. strip.setPixelColor(tail, 0); // 'Off' pixel at tail
  49. strip.show(); // Refresh strip
  50. delay(20); // Pause 20 milliseconds (~50 FPS)
  51.  
  52. if(++head >= NUMPIXELS) { // Increment head index. Off end of strip?
  53. head = 0; // Yes, reset head index to start
  54. if((color >>= 8) == 0) // Next color (R->G->B) ... past blue now?
  55. color = 0xFF0000; // Yes, reset to red
  56. }
  57. if(++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement