Advertisement
Guest User

Untitled

a guest
May 25th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3. #include <avr/power.h>
  4. #endif
  5.  
  6. //sert out signal pin
  7. #define PIN 11 // whatever pin you plugged strip into
  8.  
  9. //create an instance of the library - call it "strip"
  10. //first parameter is number of lights
  11. //second parameter is pin plugged into
  12. Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, PIN, NEO_GRB + NEO_KHZ800);
  13.  
  14. int btnPin1 = 2;
  15. int btnPin2 = 4;
  16. int ledPin1 = 11;
  17.  
  18. void setup() {
  19.  
  20. pinMode(btnPin1, INPUT);
  21. pinMode(btnPin2, INPUT);
  22. pinMode(ledPin1, OUTPUT);
  23.  
  24. //start the strip
  25. strip.begin();
  26. //initialize all the pixels to off
  27. strip.show();
  28.  
  29. Serial.begin(9600);
  30. }
  31.  
  32. void loop() {
  33. if(digitalRead(2) == 1){
  34. // iterate through array of neopixels to set color and show
  35. for(uint16_t i = 0; i < strip.numPixels(); i++) {
  36. //always set color first, then show color
  37. strip.setPixelColor(i, 0, 150, 200);
  38. }
  39. }else if (digitalRead(4) == 1) {
  40. for(uint16_t i = 0; i < strip.numPixels(); i++) {
  41. strip.setPixelColor(i, 190, 0, 0);
  42. }
  43. }else {
  44. digitalWrite(ledPin1, LOW);
  45. for(uint16_t i = 0; i < strip.numPixels(); i++) {
  46. //always set color first, then show color
  47. strip.setPixelColor(i, 0, 0, 0);
  48. }
  49. }strip.show();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement