Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. #include <Adafruit_NeoPixel.h>
  4. #ifdef __AVR__
  5. #include <avr/power.h>
  6. #endif
  7.  
  8. // Which pin on the Arduino is connected to the NeoPixels?
  9. // On a Trinket or Gemma we suggest changing this to 1
  10. #define PIN            6
  11.  
  12. // How many NeoPixels are attached to the Arduino?
  13. #define NUMPIXELS      16
  14.  
  15. // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
  16. // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
  17. // example for more information on possible values.
  18. Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  19.  
  20. int delayval = 500; // delay for half a second
  21.  
  22. const int buttonPin  = 2;     // the pin that the pushbutton is attached to
  23. const int ledPin     = 13;    // the pin that the LED is attached to
  24.  
  25. int buttonState      = 0;     // current state of the button
  26. int lastButtonState  = 0;     // previous state of the button
  27. int ledState         = 0;     // remember current led state
  28.  
  29. int inkrement = 1;
  30.  
  31. void setup() {
  32.   pinMode(buttonPin, INPUT);  // initialize the button pin as a input
  33.   pinMode(ledPin, OUTPUT);    // initialize the button pin as a output
  34.  
  35.  
  36.   ///////
  37. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  38. #if defined (__AVR_ATtiny85__)
  39.   if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  40. #endif
  41.   // End of trinket special code
  42.  
  43.   pixels.begin(); // This initializes the NeoPixel library.
  44.   //////
  45. }
  46.  
  47. void loop() {
  48.   buttonState = digitalRead(buttonPin);
  49.  
  50.   if (buttonState == 1){
  51.     // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  52.  
  53.   for(int i=0;i<NUMPIXELS;i++){
  54.  
  55.    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  56.    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
  57.  
  58.    pixels.show(); // This sends the updated pixel color to the hardware.
  59.  
  60.    delay(delayval); // Delay for a period of time (in milliseconds).
  61.    inkrement++;
  62.  }
  63.  if (buttonState == 2){
  64.    // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  65.  
  66.  for(int i=0;i<NUMPIXELS;i++){
  67.  
  68.    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  69.    pixels.setPixelColor(i, pixels.Color(0,20,0)); // Moderately bright green color.
  70.  
  71.    pixels.show(); // This sends the updated pixel color to the hardware.
  72.  
  73.    delay(delayval); // Delay for a period of time (in milliseconds).
  74.    inkrement++;
  75.  }
  76.  }
  77.  }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement