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