Neopixel Arduino Button Control - Programming Advice

Hi all! First time poster, first time Arduino user, first time adafruit user!

I've got myself a set of 1m 144pixel Neopixels as well as recommended capacitors, resistors on a breadboard setup. All is working well and I can sort of get my head around the sample programming in order to change some colours etc. However I'm at a loss on where to start with learning the code in order to make it do what I want. If I outline what I'd like to achieve can someone point me towards some relevant tutorials or examples, or if this is in the totally wrong place (my apologies) some pointers in the right direction would be most helpful.

I've built a perspex box which I would like to back-light, it has "sections" which I would like to illuminate each changing on a button press. I would like to use a 2m length of neopixels that are masked off within the box, eg pixels 0-40 would be one section, 41-80 another, and 80-144 the final, when the button is pressed each section along the chain lights up.

If I can get that going I'm a happy chappy, I would love to then build upon this code in order to use a nice fade between sections and then into differing colours etc.

As an example see this image: http://1.bp.blogspot.com/-us71iH6VW0o/TcOfMH6ouGI/AAAAAAAABGM/Ic05GbScVig/s1600/BBC_TVC_Studio_Rehersal.jpg where rehearsal is lit, when the button is pressed it would cycle down to audience entrance etc, then up to transmission.

I hope you get what I'm trying to do and someone knows of some tutorials or alternate projects that may help. It's being able to control certain sections of the string that I can't seem to find much guidance on. Many thanks in advance.

So, the basic requirement is that when the button becomes depressed the current section of LEDs turn off and the next 40 turn on. Is that right ?

If so, get that going before you move on to fading between sections and/or fading.

Do you know how to turn on a number of consecutive LEDs out of 144 ?

lazyorange: I've built a perspex box which I would like to back-light, it has "sections" which I would like to illuminate each changing on a button press. I would like to use a 2m length of neopixels that are masked off within the box, eg pixels 0-40 would be one section, 41-80 another, and 80-144 the final, when the button is pressed each section along the chain lights up.

Easiest solution would be one button and a sequential stepping though the lit sections one after the other:

initially: nothing lit 1st button press: 1st section lit 2nd button press: 2nd section lit 3rdbutton press: 3rd section lit 4th button press: 4th section lit next button press: restart from beginning

In that case the program would be simple: You just need to count the number the button was pressed.

Disadvantages: - Only one (or none) section can be lit at the same time - the sequence of lit sections after pressing the button is fixed

If that is enough, the program sketch would be easy to create.

Also easy would be a 4 button solution: One button for switching each section on or off. Advantage: - several sections can be lit at the same time - the button pressed decides about wich section on/off state is to be changed

Hello UKHeliBob, jurs,

UKHeliBob you are correct in what I am trying to do, I have the basic demo code for using a button press to switch between “shows” in order to move between sections, but how I control/use only certain pixels/leds is where I get stuck

jurs, your “easy” solution is essentially what I am after, the basic stepping along the sting in order to illuminate single sections is all I need for now. As has been said I’ll work on fading/doing more later. I’ve got control of certain pixels sorted.

Here’s the demo code I’ve got so far which is working with a button press to advance cycles. Now the fade and exact control…

// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin.  When you
// press the button it will change to a new pixel animation.  Note that you need to press the
// button once to start the first animation!

#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 60

// 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);

const int A_start = 0;
const int A_end = 19;

const int B_start = 19;
const int B_end = 39;

const int C_start = 39;
const int C_end = 60;

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 > 7)
        showType=0;
      startShow(showType);
    }
  }

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

void startShow(int i) {
  switch(i){

    case 0: colorWipe(A_start, C_end, strip.Color(255, 0, 0), 10 ); // section A to C is Red
            break;
    case 1: colorWipe(A_start, C_end, strip.Color(0, 255, 0), 10 ); // section A to C is Green
            break;
    case 2: colorWipe(A_start, C_end, strip.Color(0, 0, 255), 10 ); // section A to C is Blue
            break;
    case 3: colorWipe(A_start, C_end, strip.Color(255, 255, 255), 10 ); // section A to C is White
            break;
    case 4: colorWipe(A_start, A_end, strip.Color(255, 0, 0), 10 ); // section A is Red
            break;
    case 5: colorWipe(B_start, B_end, strip.Color(0, 255, 0), 10 ); // section B is Green
            break;
    case 6: colorWipe(C_start, C_end, strip.Color(0, 0, 255), 10 ); // section C is Blue
            break;
    case 7: colorWipe(A_start, C_end, strip.Color(0, 0, 0), 10 ); // section A to C is off/black
            break;
  }
}

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

Did you ever get the fade and additional controls working?

medpixman: Did you ever get the fade and additional controls working?

As the OP only ever made 2 posts, both in this thread, I think it unlikely that you will get an answer.

If you have a problem I suggest that you start a new thread describing the problem and posting any code that you have a problem with