RGB LED with sound sensors

What's up team,

I am new to arduino and having trouble writing code for a project. My goal is to have a RGB LED that turns on when I make a sound and stays on until I make another sound and then switches to the next color. This pattern will continue until I run through all seven colors where it will then turn off after the 7th color. It is supposed to be a nightlight that turns on with a snap and switches colors with a snap.

this is my code so far, but I am pretty sure I am using the IF and IF ELSE statements incorrectly.

int soundSensor = 2;
int redPin = 11;
int greenPin = 10;
int bluePin = 9;

void setup() {
// put your setup code here, to run once:

pinMode (soundSensor, INPUT);
pinMode (redPin, OUTPUT);
pinMode (greenPin, OUTPUT);
pinMode (bluePin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

int statusSensor = digitalRead (soundSensor);

if (statusSensor == 1)
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
}
else if (statusSensor == 0)
{
else
{
setColor(0, 255, 0);
}
setColor(225, 225, 0);
}
else
{
setColor(80, 0, 80);
}
else
{
setColor(0, 225, 255);
}
}
else
{
setColor(0, 0, 225);
}
else
{

void setColor(int red, int green, int blue)
{
#ifdef COMMON_CATHODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}

thanks for the help

Alright I tried to learn more about IF statements but I am still really confused how to properly nest them. If I could see some code that uses them in the same way I am trying to in my project, it would be really helpful.

thanks

Awesome this is super helpful. The only thing I am still struggling with is that my condition for turning on the RGB LED, changing the color, and turning off the RGB LED all have the same condition which is (statusSensor == 0). So how do I use multiple IF statements if they all have the same condition?

thanks so much

You could set a variable to change every time you switch colors. So it would be (statusSensor == 0 && color == 1), then (statusSensor == 0 && color == 2), etc.

Every time the color went on, the variable could be incremented by 1, then you could use modulo arithmetic to loop through the numbers.