Digital or Analog input?

Hello!

I have a quite few questions but I'll start with 3 small ones.
keep in mind that i am Jon Snow when it comes to programming, I know nothing

  1. I modified the neopixel button cycle sketch from Adafruit to cycle from off, to Blue, to Orange. then loop (i'm making a portal gun). when i power up the Arduino or update the code it starts in cycle 1, Blue, instead of starting in the off position on cycle 0. code is below. How would i go about fixing that? should i just make cycle 1 the off position?

  2. I found this library called clickbutton. I'm still not sure how to use libraries or how to code an Arduino, or how to code. In the example sketch, the button is an analog input but in my code the button is a debounced digital input. Does it matter if its an analog or digital input?

  3. How would i go about using clickbutton in my sketch to control the neopixel ring?

#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN   2    // Digital IO pin connected to the button.  This will be
                          // driven with a pull-up resistor so the switch should
                          // pull the pin to ground momentarily.  On a high -> low
                          // transition the button press logic will execute.

#define PIXEL_PIN    6    // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 12

// Parameter 1 = number of pixels in strip,  neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState = HIGH;
int showType = 0;

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 2)
        showType=0;
      startShow(showType);
    }
  }

  // Set the last button state to the old state.
  oldState = newState;
}

void startShow(int i) {
  switch(i){
    case 0: colorWipe(strip.Color(0, 0, 0), 0);    // Black/off
            break;
    case 1: colorWipe(strip.Color(0, 0, 255), 0);  // Blue
            break;
    case 2: colorWipe(strip.Color(255, 25, 0), 0);  //Orange
            break;
  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(0);
  }
}

the code it starts in cycle 1, Blue, instead of starting in the off position on cycle 0.

That's because you increment showType from its initial value of 0 before calling the startShow() function. Either set showType to a value greater than 2 when you declare it and it will be set to zero before the call to startShow() or introduce a variables, say firstTime, and don't increment showType if this is the first time that startShow() has been called.

set showType to a value greater than 2 when you declare it and it will be set to zero before the call to startShow()

is this what you mean? its not working. it actually wont loop back to 0 now.

  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 2)
        showType=3;
      startShow(showType);

ntroduce a variables, say firstTime, and don't increment showType if this is the first time that startShow() has been called.

how would i go about doing such a thing?

OH, the showtype at the top of the code, i put a 3 in its place and it worked just fine! THANK YOU SO MUCH!!!!!!!!!

NEW QUESTION: i notice that the button doesn't work while the animation on the ring is playing, how would i make the button priority over the animation so it will always just go to the next case in the loop?

how would i make the button priority over the animation

Get rid of the for loop used for the animation. It is locking the program into the animation. Instead, increment a variable each time colorWipe() is called and use that as the index to the pixel. If you want the animation to run slower then only increment the variable if millis() has changed by the required amount since the last time.

Using these techniques, often known as BlinkWithoutDelay after the example in the IDE of the same name, you can read the button input each time through loop().