Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. // NEOPIXEL BEST PRACTICES for most reliable operation:
  3. // - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
  4. // - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
  5. // - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
  6. // - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
  7. // connect GROUND (-) first, then +, then data.
  8. // - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
  9. // a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
  10. // (Skipping these may work OK on your workbench but can fail in the field)
  11.  
  12. #include <Adafruit_NeoPixel.h>
  13. #ifdef _AVR_
  14. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  15. #endif
  16.  
  17. // Which pin on the Arduino is connected to the NeoPixels?
  18. // On a Trinket or Gemma we suggest changing this to 1:
  19. #define LED_PIN 6
  20.  
  21. // How many NeoPixels are attached to the Arduino?
  22. #define LED_COUNT 60
  23.  
  24. // Declare our NeoPixel strip object:
  25. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  26. // Argument 1 = Number of pixels in NeoPixel strip
  27. // Argument 2 = Arduino pin number (most are valid)
  28. // Argument 3 = Pixel type flags, add together as needed:
  29. // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  30. // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  31. // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  32. // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  33. // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  34.  
  35.  
  36. // setup() function -- runs once at startup --------------------------------
  37.  
  38. void setup() {
  39. // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  40. // Any other board, you can remove this part (but no harm leaving it):
  41. #if defined(_AVR_ATtiny85_) && (F_CPU == 16000000)
  42. clock_prescale_set(clock_div_1);
  43. #endif
  44. // END of Trinket-specific code.
  45.  
  46. strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  47. strip.show(); // Turn OFF all pixels ASAP
  48. strip.setBrightness(20); // Set BRIGHTNESS to about 1/5 (max = 255)
  49. pinMode(2, INPUT);
  50. Serial.begin(9600);
  51. }
  52.  
  53.  
  54. // loop() function -- runs repeatedly as long as board is on ---------------
  55.  
  56. void loop() {
  57. Serial.println(analogRead(0));
  58. if(digitalRead(2) == HIGH){
  59.  
  60. strip.setPixelColor(0, strip.Color(255, 255, 255));
  61. strip.setPixelColor(1, strip.Color(0, 50, 250));
  62. strip.setPixelColor(2, strip.Color(255, 0, 255));
  63. strip.setPixelColor(3, strip.Color(255, 50, 50));
  64. strip.setPixelColor(4, strip.Color(255, 50, 50));
  65. strip.setPixelColor(5, strip.Color(255, 0, 255));
  66. strip.setPixelColor(6, strip.Color(0, 50, 250));
  67. strip.setPixelColor(7, strip.Color(255, 255, 255));
  68. strip.show();
  69. } else {
  70. strip.setPixelColor(0, strip.Color(0, 0, 0));
  71. strip.setPixelColor(1, strip.Color(0, 0, 0));
  72. strip.setPixelColor(2, strip.Color(0, 0, 0));
  73. strip.setPixelColor(3, strip.Color(0, 0, 0));
  74. strip.setPixelColor(4, strip.Color(0, 0, 0));
  75. strip.setPixelColor(5, strip.Color(0, 0, 0));
  76. strip.setPixelColor(6, strip.Color(0, 0, 0));
  77. strip.show();
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement