Need help with code to make an on/off switch work on my shield

Hello,
I am programming some lights and have a shield with 2 slide on, off switches.

The lights are only going to be on for 90 seconds at a time and are running on batteries.

I have all of the code to run the lights the way I need, but right now, they just start when I plug in the power source. I would rather be able to have them all plugged in, then flip a switch.

I am VERY novice.

This is the shield I have, with the switch.
http://shopping.coolneon.com/Store-Display-name

There are 2 switches available but I only need 1 to do anything, right now.

From my research, the switches are pin 6 and pin 7. I am not particular on which one is the on off.

Does anyone know the additional code I need for this? This is the sketch, as it exists now. (thanks to people on this forum :slight_smile:

#include <Adafruit_NeoPixel.h>

#define PIN 11

Adafruit_NeoPixel strip = Adafruit_NeoPixel(100, PIN, NEO_GRB + NEO_KHZ800);

#define COLOR(r,g,b) ( (uint32_t)r << 16) | ((uint32_t)g <<  8) | b

uint32_t BLACK = COLOR(0,0,0);
uint32_t WHITE = COLOR(255,255,255);
uint32_t RED = COLOR(255,0,0);
uint32_t GREEN = COLOR(0,255,0);
uint32_t BLUE = COLOR(0,0,255);

uint32_t PURPLE = COLOR(51,0,102);
uint32_t PINK = COLOR(204,0,204);
uint32_t YELLOW = COLOR(255,198,7);


uint32_t Wheel(byte WheelPos) 
{
  if(WheelPos < 85) 
  {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) 
  {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else 
  {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

class Pattern
{
  public:

  virtual void Init(void)
  {}  

  virtual void Run(long time)
  {}  

  static void SetAll (uint32_t color)
  {
    for (uint16_t i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, color);
    }
    strip.show();
  }

  static void SetSomeLeds (uint32_t color, int numberLeds)
  {
    for (uint16_t i=0; i<numberLeds; i++) {
        strip.setPixelColor(i, color);
    }
    strip.show();
  }

};

class Color : public Pattern
{
  public:
  uint32_t m_color;
    
  Color (uint32_t color)
  {
     m_color = color;
  }

  void Init (void)
  {
    Pattern::SetAll(m_color);
  }
};

class RGB : public Color
{
  public:
    
  RGB (byte red, byte green, byte blue) : 
    Color (COLOR (red, green, blue))
  {}
};


class FlashyRainbow : public Pattern
{
  byte base;

  void Run (long elapsed)
  {
    uint16_t j;

    elapsed = elapsed % 400;
    
    if (elapsed < 200)
    {
      for(j=0; j<strip.numPixels(); j++) 
      {
        int val = elapsed + j * 256 / strip.numPixels();
        strip.setPixelColor(j, Wheel(val % 256 ));
      }
      strip.show();
    }
    else
    {
      Pattern::SetAll(BLACK);
    }
  }
};

class FlashyYellow: public Pattern
{
  void Init (void)
  {
    Pattern::SetAll(YELLOW);
  }

  void Run (long elapsed)
  {
    elapsed = elapsed % 400;
    
    if (elapsed < 200)
    {
      Pattern::SetAll(YELLOW);
    } else {
      Pattern::SetAll(BLACK);
    }
  }
};


typedef struct {
  int time;
  Pattern *pattern;
} Effect;

Effect effects[] = {

  {6250, new FlashyRainbow()}, // 10 seconds of flashy rainbow
  {500, new Color(RED)},      // 1 seconds red
  {500, new Color(GREEN)},    // 1 seconds green
  {1500, new Color(PURPLE)},   // 1 seconds purple
  {500, new Color(PINK)},     // 1 seconds pink
  {500, new Color(BLUE)},     // 1 seconds blue
  {4000, new Color(YELLOW)},   // 3 seconds yellow
  {4500, new FlashyRainbow()}, // 6 seconds of flashy rainbow
  {1675, new Color(RED)},      // 2 seconds red
  {2750, new Color(GREEN)},    // 2 seconds green
  {950, new Color(RED)},      // 1 seconds red
  {2900, new Color(GREEN)},    // 3 seconds green
  {1000, new Color(RED)},      // 1 seconds red
  {2500, new RGB(0,255,0)},    // 3 seconds green
  {1000, new RGB(255,0,0)},    // 1 seconds red
  {3000, new Color(GREEN)},    // 3 seconds green
  {5000, new FlashyYellow()}, // 11 seconds of flashy yellow
  {5000, new FlashyYellow()}, // 10 seconds of flashy yellow
  {3000, new FlashyRainbow()}, // 10 seconds of flashy rainbow
  {0, NULL}
};

class EffectController 
{
  Effect *m_effects;

  int m_index = 0;
  long m_start;
  
  public:

  EffectController (Effect effects [])
  {
    m_effects = effects;
  }

  void Start (void)
  {
    Serial.print ("start ");
    Serial.println();

    strip.begin();
    strip.show(); // Initialize all pixels to 'off'

    m_index = 0;
  }

  void ShowStatus (void)
  {
      Serial.print ("time ");
      Serial.print ((long)(millis()-m_start));
      Serial.print (" track ");
      Serial.print (m_index);
      Serial.println();
  }
  
  void Run (void)
  {
    long elapsed;
    //long this_time = m_effects[m_index].time * 1000;
    long this_time = m_effects[m_index].time;
    
    if (m_index == 0)
      m_start = millis();
      
    if (this_time > 0)
    {
      ShowStatus();
      long track_start = millis();
      
      m_effects[m_index].pattern->Init();
      do
      {
         elapsed =  millis() - track_start;
         m_effects[m_index].pattern->Run(elapsed);
         
      } while (elapsed < this_time);
      m_index++;

      if (m_effects[m_index].time == 0)
      {
        // finished
        Serial.print ("time ");
        Serial.print ((long)(millis()-m_start));
        Serial.print (" finished");
        Serial.println();
        Pattern::SetAll(COLOR(0,0,0));
      }
    }
  }
  
};

EffectController controller (effects);

void setup() {
  int j;

  Serial.begin(115200);
  
  Pattern::SetSomeLeds (RED, 1);

  for (j=5; j>0; j--)
  {
    Pattern::SetSomeLeds (GREEN, j);
    delay (1000);
  }
  controller.Start();
}

void loop() {
  
  controller.Run();
}

Please edit your post and add code tags around the code.

Type
** **[code]** **
before the code
Type
** **[/code]** **
after the code

So it looks like

your code here

It makes it easier to read and copy and it prevents possibly corruption by the forum software.

Last 2 lines in setup()

pinMode(6,INPUT_PULLUP);
while(digitalRead(6)); // processor will loop here until button on pin 6 is pressed

HowToPostCode