Solved Sound Reactive RGB with arduino Nano

So I have build myself a sound reactive RGB led light. It al works, however I want to change a thing which will not change.

The things I used:
Arduino nano
2 x 2 RGB led
Microphone module
(some cables and solder)

Currently the device indeed does react to sound, however the RGB module is 2 x 2, and only 1 led is lighted up. It cycles clockwise.

I want that all 4 leds are "alive" and it does not cycle through them. This is how to code looks like. If someone could please explain me what am I missing and how do I correct it. Or pointing me to a online document would also work :). (I also uploaded the code, I never used this forum before so pardon me if my thread looks messy)

#include <Adafruit_NeoPixel.h>

// LED
#include <Adafruit_NeoPixel.h>

#define PIN 2

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


//MIC

const int inputPin = A2;
const int inputWindow = 5;
unsigned int inputSample;

unsigned int diff;
unsigned int is;

float proc;


unsigned int R;
unsigned int G;
unsigned int B;

unsigned int x;
unsigned int y;
unsigned int z;
unsigned int w;

unsigned int X = 0;
unsigned int revR = 0;
unsigned int revG;
unsigned int revB;

unsigned int H;
unsigned int t;


unsigned int sample;


unsigned long cs;
unsigned long I = 1;

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  pinMode(inputPin, INPUT);
  Serial.begin(9600);
}

void loop() {

strip.show();

  unsigned int inputMax = 0;
  unsigned int inputMin = 1000;

  for (unsigned int i = 0; i < inputWindow; i++) {
    inputSample = analogRead(inputPin);
    if (inputSample < inputMin){
      inputMin = inputSample;
    }
    if (inputSample > inputMax){
      inputMax = inputSample;
    }
    
    diff = inputMax - inputMin; 

 Serial.println (diff);
  }

if (diff > 17) {
  R = 200;
  G = G-50;
  B = B - 50;
}



cs = millis();
if (cs != I) {
  cs == I; 
  H++; 
  t++;
}

if (H == 2) {
  if (revR == 1) {
    R = R - 6;
    if (R <= 5){ R = 0; revR = 0;}
  }
  else {
  R = R + 6;
  if (R >= 255){ R = 255; revR = 1;}
  }

}

if (H == 4) {
  if (revG == 1) {
    G = G - 4;
    if (G <= 5){ G = 0; revG = 0;}
  }
  else {
  G = G + 4;
  if (G >= 255){ G = 255; revG = 1;}
  }
  
}

if (H == 6) {
  if (revB == 1) {
    B = B - 2;
    if (B <= 5){ B = 0; revB = 0;}
  }
  else {
  B = B + 2;
  if (B >= 255){ B = 255; revB = 1;}
  }
  H = 0;

}


if (t==50) {
 X++;
 if (X > 3) X = 0;
 t=0;
}



 strip.setPixelColor(0, x, 0, 0);
 strip.setPixelColor(1, y, 0, 0);
 strip.setPixelColor(2, z, 0, 0);
 strip.setPixelColor(3, w, 0, 0);
 strip.setPixelColor(X, R, G, B);

 strip.show();



}

morgalo.ino (2.71 KB)

I want that all 4 leds are "alive" and it does not cycle through them.

So, change the code to make that happen. Do you know what part of the code does that?

I also uploaded the code

But incorrectly... Use code tags (the </> icon), not quote tags.

PaulS:
So, change the code to make that happen. Do you know what part of the code does that?

Thanks for your reply!

This part of the code cycles the leds, if I am not mistaking. (I also changed the code instead of quotes)

if (diff > 17) {
  R = 200;
  G = G-50;
  B = B - 50;
}



cs = millis();
if (cs != I) {
  cs == I; 
  H++; 
  t++;
}

if (H == 2) {
  if (revR == 1) {
    R = R - 6;
    if (R <= 5){ R = 0; revR = 0;}
  }
  else {
  R = R + 6;
  if (R >= 255){ R = 255; revR = 1;}
  }

}

if (H == 4) {
  if (revG == 1) {
    G = G - 4;
    if (G <= 5){ G = 0; revG = 0;}
  }
  else {
  G = G + 4;
  if (G >= 255){ G = 255; revG = 1;}
  }
  
}

if (H == 6) {
  if (revB == 1) {
    B = B - 2;
    if (B <= 5){ B = 0; revB = 0;}
  }
  else {
  B = B + 2;
  if (B >= 255){ B = 255; revB = 1;}
  }
  H = 0;

}


if (t==50) {
 X++;
 if (X > 3) X = 0;
 t=0;
}



 strip.setPixelColor(0, x, 0, 0);
 strip.setPixelColor(1, y, 0, 0);
 strip.setPixelColor(2, z, 0, 0);
 strip.setPixelColor(3, w, 0, 0);
 strip.setPixelColor(X, R, G, B);

 strip.show();

This part of the code cycles the leds

What "cycles" is the values in R, G, B, and X.

The color of the LED that moves are defined by R, G, and B.

The LED to apply the color to is defined by X. If you want to apply the same color to all 4 LEDs, change

 strip.setPixelColor(0, x, 0, 0);
 strip.setPixelColor(1, y, 0, 0);
 strip.setPixelColor(2, z, 0, 0);
 strip.setPixelColor(3, w, 0, 0);
 strip.setPixelColor(X, R, G, B);

to

 strip.setPixelColor(0, R, G, B);
 strip.setPixelColor(1, R, G, B);
 strip.setPixelColor(2, R, G, B);
 strip.setPixelColor(3, R, G, B);

PaulS:
What "cycles" is the values in R, G, B, and X.

The color of the LED that moves are defined by R, G, and B.

The LED to apply the color to is defined by X. If you want to apply the same color to all 4 LEDs, change

 strip.setPixelColor(0, x, 0, 0);

strip.setPixelColor(1, y, 0, 0);
strip.setPixelColor(2, z, 0, 0);
strip.setPixelColor(3, w, 0, 0);
strip.setPixelColor(X, R, G, B);



to


strip.setPixelColor(0, R, G, B);
strip.setPixelColor(1, R, G, B);
strip.setPixelColor(2, R, G, B);
strip.setPixelColor(3, R, G, B);

Thanks, this was exactly what I needed. I feel rather stupid that I over saw this, so again thanks for your time!