Neo Pixel with using multiple inputs/output logic

Hi, I am struggling to compile this likely simple code and was hoping someone could give me some tips on how to get to the goal. Basically, I have an Arduino nano and 4 Adafruit Neo Pixels. What I am trying to do is us 2 inputs to trigger 4 output states.

D12 & D13 are my inputs being triggered by a Maestro.
D2, D3, D4 & D5 are my outputs to the Neo Pixel rings

Logic would go:
D12 High & D13 Low = D2 - D5 ON (Red)
D12 Low & D13 High = D2 - D5 ON (White)
D12 High & D13 High = D2 & D3 ON (Red) & D4 & D5 (White)
D12 Low & D13 Low = D2 - D5 OFF

Here is what have so far, I haven't even got into the logic yet as I am just trying to get the code to turn on the rings with D12 high....any guidance is appreciated.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
int inputStateA = 0;
int inputStateB = 0; 

#define PIN 2 //Neo Pixel Ring 1
#define PIN 3 //Neo Pixel Ring 2
#define PIN 4 //Neo Pixel Ring 3
#define PIN 5 //Neo Pixel Ring 4

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 24 // Popular NeoPixel ring size

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels

void setup()
{
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT); 
  pinMode(12, INPUT);
  pinMode(13, INPUT);

pixels.begin(); 

}
void loop() {
  pixels.clear(); // Set all pixel colors to 'off'
  inputStateA = digitalRead(12);
  inputStateB = digitalRead(13);

  for(int i=0; i<NUMPIXELS; i++) { // For each pixel...
  if (inputStateB == HIGH) {
   digitalWrite(2, pixels.setPixelColor(i, pixels.Color(0, 150, 0)));
   digitalWrite(3, pixels.setPixelColor(i, pixels.Color(0, 150, 0)));
   digitalWrite(4, pixels.setPixelColor(i, pixels.Color(0, 150, 0)));
   digitalWrite(5, pixels.setPixelColor(i, pixels.Color(0, 150, 0)));
  
   pixels.show();

   delay(250);
 
  }
}. 

you need to add information.

Neopixel have a singlewire-databus. You can daisy-chain a thousand neopixels and still adress each single pixel to have its own color and brightness

How many neopixel-LED does each ring have? Is 24 the right number?

You are defining and then re-defining the word "PIN"

after that re-defining PIN will be replaced by 5
so nothing will happen on IO-pins 2,3,4

I'm not really familiar with the neopixel-functions but the basic logic is
all rings can be connected to a single "neopixel-databus"-pin
accessing the second ring is done through the neopixel-number
If one ring has 24 neopixels
if the numbers start at 0
accessing the first neopixel of ring 1 is done by number 0
accessing the second neopixel of ring 1 is done by number 1
...
accessing the 24th neopixel of ring 1 is done by number 23

accessing the first neopixel of ring 2 is done by number 24
which can be understood as
relative number 0 + (ringNr - 1) * Offset

if one ring has 24 pixes the offset has value 24

forth ring pixel 7

i = 7
ringNr = 4

i + (ringNr - 1) * Offset
7 + (4 - 1) * 24

You should use self-explaining named constants
instead of numbers

instead of

  pinMode(12, INPUT);
  pinMode(13, INPUT);
const byte Input1_Pin = 12;
const byte Input2_Pin = 13;

  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

same thing use constants for the values of colors.
I'm pretty sure that the values for colors are predefined in the libraries

You should start with a demo-code that is well known to be working with a single ring
and work up from there

changing one thing at a time test new
changing one thing at a time test new
changing one thing at a time test new
....

best regards Stefan

If all rings are the same size and use the same protocol (speed, type RGB sequence etc)
There is the possibility to make a small modification to the neopixel library which will give you the opportunity change the output pin used when you call show(), but with the library as is, what you need to do is create separate objects for each output pin.

#define PIN1 2 //Neo Pixel Ring 1
#define PIN2 3 //Neo Pixel Ring 2
#define PIN3 4 //Neo Pixel Ring 3
#define PIN4 5 //Neo Pixel Ring 4

Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

This is of course a little wasteful memory wise.
Regardless of that i suggest you first manage to control 1 ring properly using the functions from the library.

digitalWrite(2, pixels.setPixelColor(i, pixels.Color(0, 150, 0)));

This is not the way !, if you use a pin to write a signal to the ledstrip, you don't use digitalWrite() at all. Also setPixelColor() does not return a value. It may actually work, but that is coincidence. Check out the examples again and get that to work properly. Then first try to control a single ring through the buttons resulting in a different color on the button push.

It will take some time, but if you want to use Neopixels, then this is the tutorial: https://learn.adafruit.com/adafruit-neopixel-uberguide

With the Adafruit tutorial and the previous posts by StefanL38 and Deva_Rishi, it is not hard to control the four rings. This is a working example:

// For: https://forum.arduino.cc/t/neo-pixel-with-using-multiple-inputs-output-logic/1047809/
// This Wokwi project: https://wokwi.com/projects/347018670462992980
//
// There are two options:
//   1. Use one pin for Neopixels and concatenate all Neopixel rings
//   2. Use four pins for the four separate Neopixel rings.
// Both options are good.
// I used the second option, but did not put them in an array (yet).
//

#include <Adafruit_NeoPixel.h>

const byte Input1_Pin = 12;
const byte Input2_Pin = 13;

#define PIN1 2 //Neo Pixel Ring 1
#define PIN2 3 //Neo Pixel Ring 2
#define PIN3 4 //Neo Pixel Ring 3
#define PIN4 5 //Neo Pixel Ring 4

#define NUMPIXELS 24
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

int colorWalkRed;
int colorWalkGreen;
int colorWalkBlue;

void setup() 
{
//  Serial.begin(115200);
//  Serial.println( "The sketch has started");

  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
  pixels1.show();
  pixels2.show();
  pixels3.show();
  pixels4.show();

  colorWalkRed = random( 0, 256);
  colorWalkGreen = random( 0, 256);
  colorWalkBlue = random( 0, 256);
}

void loop() 
{
  pixels1.fill(pixels1.Color(colorWalkRed, colorWalkGreen, colorWalkBlue), 0, NUMPIXELS);
  pixels1.show();
  AdvanceColorWalk();
  delay(100);
  pixels2.fill(pixels2.Color(colorWalkRed, colorWalkGreen, colorWalkBlue), 0, NUMPIXELS);
  pixels2.show();
  AdvanceColorWalk();
  delay(100);
  pixels3.fill(pixels3.Color(colorWalkRed, colorWalkGreen, colorWalkBlue), 0, NUMPIXELS);
  pixels3.show();
  AdvanceColorWalk();
  delay(100);
  pixels4.fill(pixels4.Color(colorWalkRed, colorWalkGreen, colorWalkBlue), 0, NUMPIXELS);
  pixels4.show();
  AdvanceColorWalk();
  delay(100);
}

void AdvanceColorWalk()
{
  colorWalkRed += random(0,20);
  if( colorWalkRed > 255)
    colorWalkRed -= 255;
  colorWalkGreen += random(0,20);
  if( colorWalkGreen > 255)
    colorWalkGreen -= 255;
  colorWalkBlue += random(0,20);
  if( colorWalkBlue > 255)
    colorWalkBlue -= 255;
}

The sketch in the Wokwi simulator:

I am using 12 neo pixel rings. Also I am having them on separate pins vs being daisy chained due to how they are wired (which can't be changed)

I know this code is not efficient, but I am going for function over pretty for now anyway. Been working this for a few hours and here is where I am at. Pick it apart and let me know your thoughts. At this time the code loads but when I make input2 high, nothing happens....some how the code isn't registering that pin 13 is high or when it is high its not triggering the void Setpixels section...hoping when I get back to this tomorrow it comes to me or someone her can advise. Once I can get a single state to work, I can then add other statements that will equate to my true table provided before.

#include <Adafruit_NeoPixel.h>

const int Input1_Pin = 12; //Maestro PIN 23
const int Input2_Pin = 13; //Maestro PIN 22
int val1 = 0; //variable for reading the input1 pin status
int val2 = 0; //variable for reading the input2 pin status

#define PIN1 2 //Neo Pixel Ring 1
#define PIN2 3 //Neo Pixel Ring 2
#define PIN3 4 //Neo Pixel Ring 3
#define PIN4 5 //Neo Pixel Ring 4

#define NUMPIXELS 12
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
  }

void loop() {

  val1 = digitalRead(Input1_Pin); //read input 1 value
  val2 = digitalRead(Input2_Pin); //read input 2 value
  
  if (val2 == HIGH)  //Turn on Pixels
    {
      void SetPixels(); // Send the updated pixel colors to the hardware.
      }   
  else 
    {
      pixels1.show();  // set pixels to off
      pixels2.show();  // set pixels to off.
      pixels3.show();  // set pixels to off
      pixels4.show();  // set pixels to off
    }
    }


void SetPixels()
  {
  // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
  pixels1.setPixelColor(0, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(1, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(2, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(3, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(4, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(5, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(6, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(7, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(8, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(9, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(10, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(11, pixels1.Color(255, 0, 0));
  pixels1.setPixelColor(12, pixels1.Color(255, 0, 0));
  pixels1.show();  // Send the updated pixel colors to the hardware.
  delay(100); // Delay for a period of time (in milliseconds).

  // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
  pixels2.setPixelColor(0, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(1, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(2, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(3, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(4, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(5, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(6, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(7, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(8, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(9, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(10, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(11, pixels2.Color(255, 0, 0));
  pixels2.setPixelColor(12, pixels2.Color(255, 0, 0));
  pixels2.show();  // Send the updated pixel colors to the hardware.
  delay(100); // Delay for a period of time (in milliseconds).

  // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
  pixels3.setPixelColor(0, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(1, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(2, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(3, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(4, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(5, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(6, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(7, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(8, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(9, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(10, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(11, pixels3.Color(255, 0, 0));
  pixels3.setPixelColor(12, pixels3.Color(255, 0, 0));
  pixels3.show();  // Send the updated pixel colors to the hardware.
  delay(100); // Delay for a period of time (in milliseconds).

  // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
  pixels4.setPixelColor(0, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(1, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(2, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(3, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(4, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(5, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(6, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(7, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(8, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(9, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(10, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(11, pixels4.Color(255, 0, 0));
  pixels4.setPixelColor(12, pixels4.Color(255, 0, 0));
  pixels4.show(); // Send the updated pixel colors to the hardware.
  delay(100); // Delay for a period of time (in milliseconds).
  }

How many leds are there in a ring ?
Have you seen that I use the function "pixels.fill()" to set the color of the whole ring ?

12 per ring. No wasn't aware of the "fill" command. Will check into it

You should add serial debug-output to your code to see what is really going on in your code

1 Like

can you show us how you have wired it up ?

btw.

pixels1.show();  // set pixels to off

this doesn't actually do that, it shows what is in the buffer at the time, which is basically the last thing you have written to it. If you want to turn them off you have to fill the buffer with zeroes again.

so

#include <Adafruit_NeoPixel.h>

const int Input1_Pin = 12; //Maestro PIN 23
const int Input2_Pin = 13; //Maestro PIN 22
int val1 = 0; //variable for reading the input1 pin status
int val2 = 0; //variable for reading the input2 pin status

#define PIN1 2 //Neo Pixel Ring 1
#define PIN2 3 //Neo Pixel Ring 2
#define PIN3 4 //Neo Pixel Ring 3
#define PIN4 5 //Neo Pixel Ring 4

#define NUMPIXELS 12
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

void setup()  {
  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
  pixels1.fill(0x0000FF); // fill pixels1 with blue for testing
  pixels1.show(); // show them
  delay(3000); // wait 3 seconds
}

void loop() {

  val1 = digitalRead(Input1_Pin); //read input 1 value
  val2 = digitalRead(Input2_Pin); //read input 2 value
  
  if (val2 == HIGH)   {
    void SetPixels(); // Send the updated pixel colors to the hardware.
  }   
  else   {     
     pixels1.fill(0);  // set pixels to off
     pixels2.fill(0);  // set pixels to off.
     pixels3.filll(0);  // set pixels to off
     pixels4.filll(0);  // set pixels to off
  }
  pixels1.show();  
  pixels2.show();  
  pixels3.show();  
  pixels4.show();  
  delay(100);  // very rough debounce.
}


void SetPixels()  {
  // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255 and returns a 32-bit value
  pixels1.fill(pixels1.Color(255, 0, 0));
  pixels2.fill(pixels2.Color(255, 0, 0));
  pixels3.fill(pixels3.Color(255, 0, 0));
  pixels4.fill(pixels4.Color(255, 0, 0));
}

it's fine, with the amount of leds you are controlling there is not much issue, though you will also lose some flash memory for using the same function (fill() in this case, Color is declared 'static' ) with a different object, but let's not worry about it for now. btw, there is just the function setPin() which allows you change the output pin of an object on the fly. Again that will mean you should turn the leds off before you would do that or they will just keep showing what data they have received last.

1 Like

Just a bread board setup for code development. Usb powered. Neo pixel ring connected to pos and neg and signal to pin 2.

Yellow wires are D12 and D13, based on current code connecting D13 to high when triggering.

...and yes I know the ring pictured is a 24 count, I just used what I had ready to go for testing.

ok this code works. When I make D13 high, the lights show red for all 4 outputs. So now I need to figure out how to code so that it responds to the input/output logic I outlined initially in this thread.

#include <Adafruit_NeoPixel.h>

const int Input1_Pin = 12; //Maestro PIN 23
const int Input2_Pin = 13; //Maestro PIN 22
int val1 = 0; //variable for reading the input1 pin status
int val2 = 0; //variable for reading the input2 pin status

#define PIN1 2 //Neo Pixel Ring 1
#define PIN2 3 //Neo Pixel Ring 2
#define PIN3 4 //Neo Pixel Ring 3
#define PIN4 5 //Neo Pixel Ring 4

#define NUMPIXELS 12
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
  delay(3000); // wait 3 seconds
}

void loop() {

  val1 = digitalRead(Input1_Pin); //read input 1 value
  val2 = digitalRead(Input2_Pin); //read input 2 value
  
  if (val2 == HIGH)   {
    pixels1.fill(0xFF0000);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xFF0000);
    pixels4.fill(0xFF0000);
    pixels1.show(); // show them
    pixels2.show(); // show them
    pixels3.show(); // show them
    pixels4.show(); // show them
    }   
  else   {     
     pixels1.fill(0);  // set pixels to off
     pixels2.fill(0);  // set pixels to off.
     pixels3.fill(0);  // set pixels to off
     pixels4.fill(0);  // set pixels to off
  }
  pixels1.show();  
  pixels2.show();  
  pixels3.show();  
  pixels4.show();  
  delay(0);  // very rough debounce.
}

I figured it out, here is the final code. Thanks everyone!!

#include <Adafruit_NeoPixel.h>

const int Input1_Pin = 12; //Maestro PIN 23
const int Input2_Pin = 13; //Maestro PIN 22
int val1 = 0; //variable for reading the input1 pin status
int val2 = 0; //variable for reading the input2 pin status

#define PIN1 2 //Left Neo Pixel Ring Pin D3 (PCB Connector J4)
#define PIN2 3 //Left Neo Pixel Ring Iris Pin D2 (PCB Connector J3)
#define PIN3 4 //Right Neo Pixel Ring Pin D5 (PCB Connector J4)
#define PIN4 5 //Right Neo Pixel Ring Iris Pin D4 (PCB Connector J3)

#define NUMPIXELS 16
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

  pixels1.setBrightness (1000);
  pixels2.setBrightness (1000);
  pixels3.setBrightness (1000);
  pixels4.setBrightness (1000);
  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
  delay(3000); // wait 3 seconds
}

void loop() {

  val1 = digitalRead(Input1_Pin); //read input 1 value
  val2 = digitalRead(Input2_Pin); //read input 2 value
  
  if (val1 == HIGH & val2 ==LOW)  {  //White
    pixels1.fill(0xFFFFFF);
    pixels2.fill(0xFFFFFF);
    pixels3.fill(0xFFFFFF);
    pixels4.fill(0xFFFFFF);
    pixels1.show(); // show them
    pixels2.show(); // show them
    pixels3.show(); // show them
    pixels4.show(); // show them
    }   
  if (val1 == LOW & val2 == HIGH)  {  //Red
    pixels1.fill(0xFF0000);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xFF0000);
    pixels4.fill(0xFF0000);
    pixels1.show(); // show them
    pixels2.show(); // show them
    pixels3.show(); // show them
    pixels4.show(); // show them
  }
  if (val1 == HIGH & val2 == HIGH)  { //Red & White
    pixels1.fill(0xFFFFFF);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xFFFFFF);
    pixels4.fill(0xFF0000);
    pixels1.show(); // show them
    pixels2.show(); // show them
    pixels3.show(); // show them
    pixels4.show(); // show them
  }
 else   {     
     pixels1.fill(0);  // set pixels to off
     pixels2.fill(0);  // set pixels to off.
     pixels3.fill(0);  // set pixels to off
     pixels4.fill(0);  // set pixels to off
      }
     pixels1.show();  
     pixels2.show();  
     pixels3.show();  
     pixels4.show();  
     delay(0);  // very rough debounce.
      }
  

Any time you resort to adding numerical indexes after variable names, it's time to consider an array. Here you can make an array of Adafruit_NeoPixel objects.

1 Like

Thanks, i am sure i will continue to tweak on it no doubt but its working and i can continue with other parts of the build. Here is what this is for those that are curious.



Ok, so firstly get rid of the delay(3000); in setup(), that was just for testing the ring connection.
secondly, the reason i removed the show() from the 'if; statement was because they are called at the end of loop(), so :

#include <Adafruit_NeoPixel.h>

const int Input1_Pin = 12; //Maestro PIN 23
const int Input2_Pin = 13; //Maestro PIN 22
int val1 = 0; //variable for reading the input1 pin status
int val2 = 0; //variable for reading the input2 pin status

#define PIN1 2 //Left Neo Pixel Ring Pin D3 (PCB Connector J4)
#define PIN2 3 //Left Neo Pixel Ring Iris Pin D2 (PCB Connector J3)
#define PIN3 4 //Right Neo Pixel Ring Pin D5 (PCB Connector J4)
#define PIN4 5 //Right Neo Pixel Ring Iris Pin D4 (PCB Connector J3)

#define NUMPIXELS 16
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);
  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
}

void loop() {

  val1 = digitalRead(Input1_Pin); //read input 1 value
  val2 = digitalRead(Input2_Pin); //read input 2 value
  
  if (val1 == HIGH & val2 ==LOW)  {  //White
    pixels1.fill(0xFFFFFF);
    pixels2.fill(0xFFFFFF);
    pixels3.fill(0xFFFFFF);
    pixels4.fill(0xFFFFFF);
    }   
  else if (val1 == LOW & val2 == HIGH)  {  //Red
    pixels1.fill(0xFF0000);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xFF0000);
    pixels4.fill(0xFF0000);
  }
  else if (val1 == HIGH & val2 == HIGH)  { //Red & White
    pixels1.fill(0xFFFFFF);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xFFFFFF);
    pixels4.fill(0xFF0000);
  }
 else   {     
     pixels1.fill(0);  // set pixels to off
     pixels2.fill(0);  // set pixels to off.
     pixels3.fill(0);  // set pixels to off
     pixels4.fill(0);  // set pixels to off
      }
   pixels1.show();  
   pixels2.show();  
   pixels3.show();  
   pixels4.show();  
}

and you actually mean to do an 'else if' for the other switch options or you will trigger the final 'else' for options 1 & 2 unintentionally, which will result in the LED's flashing really fast.

And this part will not work they way you intended

  pixels1.setBrightness (1000);
  pixels2.setBrightness (1000);
  pixels3.setBrightness (1000);
  pixels4.setBrightness (1000);

from Adafruit_NeoPixel.h

void setBrightness(uint8_t);

it takes an 8-bit value. that would convert your '1000' into '222' whereas i suspect you are going for the maximum level, which is 255, but also the default value, so you can leave those lines out.
If you do want to adjust the brightness use a value between 0 - 255.

1 Like

Thanks!!

#include <Adafruit_NeoPixel.h>

const int Input1_Pin = 12; //Maestro PIN 23
const int Input2_Pin = 13; //Maestro PIN 22
int val1 = 0; //variable for reading the input1 pin status
int val2 = 0; //variable for reading the input2 pin status

#define PIN1 2 //Left Neo Pixel Ring Pin D3 (PCB Connector J4)
#define PIN2 3 //Left Neo Pixel Ring Iris Pin D2 (PCB Connector J3)
#define PIN3 4 //Right Neo Pixel Ring Pin D5 (PCB Connector J4)
#define PIN4 5 //Right Neo Pixel Ring Iris Pin D4 (PCB Connector J3)

#define NUMPIXELS 16
Adafruit_NeoPixel pixels1(NUMPIXELS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels3(NUMPIXELS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels4(NUMPIXELS, PIN4, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(Input1_Pin, INPUT);
  pinMode(Input2_Pin, INPUT);

  pixels1.begin();
  pixels2.begin();
  pixels3.begin();
  pixels4.begin();
 }

void loop() {

  val1 = digitalRead(Input1_Pin); //read input 1 value
  val2 = digitalRead(Input2_Pin); //read input 2 value
  
  if (val1 == HIGH & val2 ==LOW)  {  //White
    pixels1.fill(0xd1a641);
    pixels2.fill(0xd1a641);
    pixels3.fill(0xd1a641);
    pixels4.fill(0xd1a641);
    }   
  else if (val1 == LOW & val2 == HIGH)  {  //Red
    pixels1.fill(0xFF0000);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xFF0000);
    pixels4.fill(0xFF0000);
    }
  else if (val1 == HIGH & val2 == HIGH)  { //Red & White
    pixels1.fill(0xd1a641);
    pixels2.fill(0xFF0000);
    pixels3.fill(0xd1a641);
    pixels4.fill(0xFF0000);
    }
 else   {     
     pixels1.fill(0);  // set pixels to off
     pixels2.fill(0);  // set pixels to off.
     pixels3.fill(0);  // set pixels to off
     pixels4.fill(0);  // set pixels to off
      }
     pixels1.show();  
     pixels2.show();  
     pixels3.show();  
     pixels4.show();  
      }
  

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.