Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- //sert out signal pin
- #define PIN 11 // whatever pin you plugged strip into
- //create an instance of the library - call it "strip"
- //first parameter is number of lights
- //second parameter is pin plugged into
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, PIN, NEO_GRB + NEO_KHZ800);
- int btnPin1 = 2;
- int btnPin2 = 4;
- int ledPin1 = 11;
- void setup() {
- pinMode(btnPin1, INPUT);
- pinMode(btnPin2, INPUT);
- pinMode(ledPin1, OUTPUT);
- //start the strip
- strip.begin();
- //initialize all the pixels to off
- strip.show();
- Serial.begin(9600);
- }
- void loop() {
- if(digitalRead(2) == 1){
- // iterate through array of neopixels to set color and show
- for(uint16_t i = 0; i < strip.numPixels(); i++) {
- //always set color first, then show color
- strip.setPixelColor(i, 0, 150, 200);
- }
- }else if (digitalRead(4) == 1) {
- for(uint16_t i = 0; i < strip.numPixels(); i++) {
- strip.setPixelColor(i, 190, 0, 0);
- }
- }else {
- digitalWrite(ledPin1, LOW);
- for(uint16_t i = 0; i < strip.numPixels(); i++) {
- //always set color first, then show color
- strip.setPixelColor(i, 0, 0, 0);
- }
- }strip.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement