Please look at the code below: I have low brightness (default brightness), medium brightness (if pin 2 goes HIGH) and high brightness (if pin 3 goes high). Problem is the high brightness does not work. Also when I add the 3dr condition, it messes with the medium brightness too. I commented in the code all the places where I added the 3rd condition and related code. Please help if you can. Thanks! p.s. I only added the 3rd condition to the red LED for now.
/*
Adafruit Arduino - Lesson 3. RGB LED
*/
int redPin = 11;
int greenPin = 9;
int bluePin = 10;
const int buttonPin = 2;
const int buttonPinn = 4;
int buttonState = 0;
int buttonStatee = 0; //this is part of 3rd condition
unsigned long time;
//uncomment this line if using a Common Anode LED
#define COMMON_ANODE
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buttonPinn, INPUT);//this is part of 3rd condition
}
void loop()
{
buttonState = digitalRead(buttonPin);
buttonStatee = digitalRead(buttonPinn);//this is part of 3rd condition
time = millis();
if (time < 5000){
if (buttonState == LOW) {setColor(5, 0, 0);} //low brightness
else if (buttonState==HIGH) {setColor(50,0,0);}//high brightness
else if (buttonStatee== HIGH){setColor(200,0,0);}//this is the 3rd condition
}
if (time > 5000 && time <10000){
if (buttonState == LOW) {setColor(0, 5, 0);} //low brightness
else {setColor(0,50,0);}//high brightness
}
if (time > 10000){
if (buttonState == LOW) {setColor(0, 0, 5);} //low brightness
else {setColor(0,0,50);}//high brightness
}
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}