Advertisement
Guest User

Neopixel LED Strip

a guest
Nov 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5.  
  6. #define LED_PIN 6
  7. const int buttonPin = 2;
  8.  
  9. #define LED_COUNT 60
  10. int buttonState = 0; //set button state LOW
  11.  
  12. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  13.  
  14.  
  15. void setup() {
  16. // put your setup code here, to run once:
  17. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  18. clock_prescale_set(clock_div_1);
  19. #endif
  20. strip.begin();
  21. strip.show();
  22. strip.setBrightness(50);
  23. pinMode(buttonPin, INPUT);
  24. }
  25.  
  26. void loop() {
  27. // put your main code here, to run repeatedly:
  28. buttonState = digitalRead(buttonPin); //read button state
  29. if (buttonState == HIGH){ //when button is pressed
  30. colorWipe(strip.Color(255, 0, 0), 15);//red
  31. colorWipe(strip.Color(0, 255, 0), 15);//green
  32. colorWipe(strip.Color(0, 0, 255), 15);//blue
  33. colorWipe(strip.Color(255,255,0), 15);//yellow
  34. colorWipe(strip.Color(255, 0,255), 15);//magenta
  35. colorWipe(strip.Color(0, 255,255), 15);//cyan
  36. colorWipe(strip.Color(255,255,255),15);//White
  37. }else { //when button is released
  38. colorWipe(strip.Color(0,0,0),50); //turn off
  39. }
  40. }
  41.  
  42. void colorWipe(uint32_t color, int wait) {
  43. for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  44. strip.setPixelColor(i, color); // Set pixel's color (in RAM)
  45. strip.show(); // Update strip to match
  46. delay(wait); // Pause for a moment
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement