Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5.  
  6. #define PIN 6
  7. #define NUM_PIXELS 8
  8. #define RANDOM_CHANCE 50
  9. #define TOP 75
  10.  
  11. // Parameter 1 = number of pixels in strip
  12. // Parameter 2 = Arduino pin number (most are valid)
  13. // Parameter 3 = pixel type flags, add together as needed:
  14. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  15. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  16. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  17. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  18. // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  19. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
  20.  
  21. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  22. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  23. // and minimize distance between Arduino and first pixel. Avoid connecting
  24. // on a live circuit...if you must, connect GND first.
  25.  
  26. int vals[NUM_PIXELS] = {0};
  27.  
  28. void setup() {
  29. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  30. #if defined (__AVR_ATtiny85__)
  31. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  32. #endif
  33. // End of trinket special code
  34.  
  35. Serial.begin(9600);
  36. strip.begin();
  37. strip.show(); // Initialize all pixels to 'off'
  38. }
  39.  
  40. void loop() {
  41. for (int i = 0; i < NUM_PIXELS; i++) {
  42. int col = 0;
  43. if (vals[i] < 0) {
  44. //intentionally blank
  45. } else if (vals[i] == 0) {
  46. int r = random(RANDOM_CHANCE);
  47. if (random(r) != 1) {
  48. vals[i] = -10;
  49. }
  50. } else if (vals[i] <= TOP) {
  51. col = vals[i];
  52. } else if (vals[i] <= TOP + 10) {
  53. col = TOP;
  54. } else if (vals[i] <= TOP * 2 + 10) {
  55. col = TOP * 2 + 10 - vals[i];
  56. if (vals[i] == TOP * 2 + 10) {
  57. vals[i] = -1;
  58. }
  59. }
  60. strip.setPixelColor(i, 0, col, col);
  61. vals[i]++;
  62. }
  63. strip.show();
  64. delay(20);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement