Flora - Programming standalone Neopixels and Rings, with But

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
williamwrockwell
 
Posts: 32
Joined: Thu May 24, 2018 12:39 am

Flora - Programming standalone Neopixels and Rings, with But

Post by williamwrockwell »

Hi guys,

I could really use your help. I am working on a project which has two 12 pixel neopixel rings which I have wired in sequence, and 14 individual neopixels, wired in sequence. I have wired two separate buttons. They are wired to a flora board.

My goal is to be able to program the rings to do a simple chase animation (one green pixel going in a circle, similar to color wipe but unending) which on button press would go to solid green or solid white. I can drop this if its adding too much complication and would honestly be super happy to just have it animating in that circle animation. The goal of the pixels would be to have them change color on click from green to white and that's it.

My dilemma is that I am unfamiliar with programming multiple things at once, and am having a heck of a time finding information regarding this. In the libraries I've found, all I can see is how to do a single action (say only rings, or only neopixels) but I am unsure of how to structure my code to do both things. Do you just find the code for both, and stack them, and it will work?

I know you are all very busy and the obvious answer here is "figure it out" but if you'd be willing to help, I'd sure be grateful. I would be happy to pay one of you to help me and teach me a bit about how to do this if any of you would be willing to go that route.

Here's the current button code that I have set up (and I understand that the animation here is rainbow, I just haven't yet found the right code for the chase animation yet), just for the ring, and only for the one action. Thanks in advance for any help you might have.

Code: Select all

// 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   6    // 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    3    // 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 > 9)
        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), 1);    // Black/off
            break;
    case 1: colorWipe(strip.Color(0, 0, 255), 1);  // BLUE
            break;
    case 2: 
      for (int x = 0; x < 50; x++) {
        rainbow(2);
      }
      

User avatar
williamwrockwell
 
Posts: 32
Joined: Thu May 24, 2018 12:39 am

Re: Flora - Programming standalone Neopixels and Rings, with

Post by williamwrockwell »

Not the best photo, but I wanted to share the wiring setup I've done to better illustrate what I'm trying to do. This is for a mask project.
Attachments
thumbnail_image1.jpg
thumbnail_image1.jpg (424.67 KiB) Viewed 172 times

User avatar
williamwrockwell
 
Posts: 32
Joined: Thu May 24, 2018 12:39 am

Re: Flora - Programming standalone Neopixels and Rings, with

Post by williamwrockwell »

Honestly for this project as well, it would be okay if I couldn't get the button cycle to work, but rather just had the animation running and even the standalone neopixels as a solid color. I'm just really struggling at this point to find out how to make two things happen at once if that makes sense. I know this is a topic that has been discussed, and I recall seeing it a few months ago but I can't seem to find it this morning.

User avatar
williamwrockwell
 
Posts: 32
Joined: Thu May 24, 2018 12:39 am

Re: Flora - Programming standalone Neopixels and Rings, with

Post by williamwrockwell »

In case anyone else struggles to find this... Multi-tasking is the keyword I was failing to use XD

here's a link to the information: https://learn.adafruit.com/multi-taskin ... g-the-loop

User avatar
kcl1s
 
Posts: 1512
Joined: Tue Aug 30, 2016 12:06 pm

Re: Flora - Programming standalone Neopixels and Rings, with

Post by kcl1s »

Looks like you found what you needed. Happy learning.

Fellow hobbyist
Keith

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”