Guest User

Loop code without manually pressing the button

a guest
May 23rd, 2017
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2. #ifdef __AVR__
  3.   #include <avr/power.h>
  4. #endif
  5. #define PIN 6
  6. #define BUTTON_PIN 9
  7.  
  8.  
  9. Adafruit_NeoPixel strip = Adafruit_NeoPixel(120, PIN, NEO_GRB + NEO_KHZ800);
  10.  
  11. // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
  12. // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
  13. // and minimize distance between Arduino and first pixel.  Avoid connecting
  14. // on a live circuit...if you must, connect GND first.
  15.  
  16. bool oldState = HIGH;
  17. int showType = 0;
  18.  
  19. void(* resetFunc) (void) = 0; //declare reset function @ address 0
  20.  
  21. void setup() {
  22.   pinMode(BUTTON_PIN, INPUT_PULLUP);
  23.   strip.begin();
  24.   strip.show(); // Initialize all pixels to 'off'
  25. }
  26. void loop() {
  27.   // Get current button state.
  28.   bool newState = digitalRead(BUTTON_PIN);
  29.  
  30.   // Check if state changed from high to low (button press).
  31.   if (newState == LOW && oldState == HIGH) {
  32.     // Short delay to debounce button.
  33.     delay(20);
  34.     // Check if button is still low after debounce.
  35.     newState = digitalRead(BUTTON_PIN);
  36.     if (newState == LOW) {
  37.       showType++;
  38.       if (showType > 9)
  39.         showType=0;
  40.       startShow(showType);
  41.     }
  42.   }
  43.  
  44.   // Set the last button state to the old state.
  45.   oldState = newState;
  46. }
  47.  
  48. void startShow(int i) {  
  49.   colorWipe(strip.Color(75, 0, 0), 50); // Red
  50.   colorWipe(strip.Color(0, 75, 0), 50); // Green
  51.   colorWipe(strip.Color(0, 0, 75), 50); // Blue
  52.   theaterChase(strip.Color(75, 75, 75), 50); // White
  53.   theaterChase(strip.Color(75, 0, 0), 50); // Red
  54.   theaterChase(strip.Color(0, 0, 75), 50); // Blue
  55.   rainbow(20);
  56.   rainbowCycle(20);
  57.   theaterChaseRainbow(50);
  58.   resetFunc();  //call reset
  59. }
RAW Paste Data