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
- // Which pin on the Arduino is connected to the NeoPixels?
- // On a Trinket or Gemma we suggest changing this to 1
- #define PIN 6
- // How many NeoPixels are attached to the Arduino?
- #define NUMPIXELS 16
- // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
- // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
- // example for more information on possible values.
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- int delayval = 500; // delay for half a second
- const int buttonPin = 2; // the pin that the pushbutton is attached to
- const int ledPin = 13; // the pin that the LED is attached to
- int buttonState = 0; // current state of the button
- int lastButtonState = 0; // previous state of the button
- int ledState = 0; // remember current led state
- int inkrement = 1;
- void setup() {
- pinMode(buttonPin, INPUT); // initialize the button pin as a input
- pinMode(ledPin, OUTPUT); // initialize the button pin as a output
- ///////
- // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
- #if defined (__AVR_ATtiny85__)
- if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
- #endif
- // End of trinket special code
- pixels.begin(); // This initializes the NeoPixel library.
- //////
- }
- void loop() {
- buttonState = digitalRead(buttonPin);
- if (buttonState == 1){
- // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
- for(int i=0;i<NUMPIXELS;i++){
- // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
- pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
- pixels.show(); // This sends the updated pixel color to the hardware.
- delay(delayval); // Delay for a period of time (in milliseconds).
- inkrement++;
- }
- if (buttonState == 2){
- // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
- for(int i=0;i<NUMPIXELS;i++){
- // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
- pixels.setPixelColor(i, pixels.Color(0,20,0)); // Moderately bright green color.
- pixels.show(); // This sends the updated pixel color to the hardware.
- delay(delayval); // Delay for a period of time (in milliseconds).
- inkrement++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement