Problem Adding 3rd Condition Code for LED's

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);
}

You have three leds? You do have three resistors don't you?

What resistors are you using? How are the leds connected?

Please put your code in code tags. First icon, top, left ( </> ), so we can read it easier.

Sorry for leaving this out - I am using a single RGB LED with a common anode - works fine.

I have D2 (setup as input on my nano). D2 has a 1k resistor between D2 and ground. D3 is same setup as D3. I've tried switching to D4 ,5,6, and it's the same thing - no output from 3rd condition.

This is all just running form my laptop right now about 3v. Thanks.

Here it is in code view - sorry about that

 /*
    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;
    
    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);
     
    }
     
    void loop()
    {
      buttonState = digitalRead(buttonPin);
      buttonStatee = digitalRead(buttonPinn);
      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);}
       
    } 
      
      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);  
    }

On the led output side, do you have three resistors, one for each led (you have a module with three leds inside it),
If you switch the led pins red and green, does that give you any indication. Is the led not working, or the arduino output?

Quote:" have D2 (setup as input on my nano). D2 has a 1k resistor between D2 and ground. D3 is same setup as D3. "
in the code, it looks like you are using D2 and D4. Re-check that.

I can get all three LEDs to work no problem. The problem seems to be when I add the 3rd condition.

I've even taken the second condition and set it to a different pin (like pin 3) and it works fine. It seems to be the code. Argh....!

Yes I had changed to D4 D3 D anything. I had changed to the code to different things and tried different pins. Point being it doesn't work as is.

Ok, But please humor me. Do you have three 1k resistors, one to each colored led pin? I suspect so, but Have not heard it from you yet.

If someone only used one resistor for all three led colors, then it could cause a problem such as you describe.

Then we can move on to the code. [ step by step ]

Ah I see. Ok...So:

The 3 lead LED (and one anode) is not using any resistors. The LED uses pins 9, 10 and 11 for the individual colors. The resistors are only being used for the INPUT triggers (pins 2 and 3). I'm just using them to complete the circuit (from +v to ground). This little rig here is running off the USB 3volts system from my laptop. I hope this is what you're looking for as an answer.

Thanks so far for answering my query to this point.

"The 3 lead LED (and one anode) is not using any resistors. The LED uses pins 9, 10 and 11 for the individual colors. The resistors are only being used for the INPUT triggers (pins 2 and 3). I'm just using them to complete the circuit (from +v to ground). This little rig here is running off the USB 3volts system from my laptop. I hope this is what you're looking for as an answer."

NO, I may have not explained it well.
The led unit has three leds in it. you need a resistor for each led ( 3 resistors ). If you have 1k resistors, use three 1k, one on each pin (9, 10, 11).

I think your USB is providing 5volts, rather than 3volts.

Then so be it - it's 5v and it works fine. No resistor is needed. I can set the values to different values and I get different brightness just fine. I can get two different brightnesses, just not really bright. I can get really bright as long as I only have 2 conditions.

Then so be it- if you don't want to wire the LEDs with resistors, as it should be done, then you may be lucky, and not blow your arduino.

If you have further questions, let us know.

My Arduino cost me about $3.00. I have been overdriving LEDs for some time and I have yet to blow a single LED system, whether a 3v or a 12v strip. Call it lucky, call it what you want, but it's my personal choice and it works for me. What you are sir is an asshole.

#1. I had a question which you were not willing to answer (obviously)
#2. I repeatedly asked the question and you kept redirecting to the resistors - it doesn't matter right now.
#3. I wasted a couple hours now looking at you useless replies.
#4. Clearly you like to aggravate people by your last snappy reply.
#5. IF you are looking at what I wrote here, then you obviously are looking to start a conflict because you just blew me of at this point.
#5. If you reply to this then you definitely are an asshole (obviously again looking to start a fight)
#6. "Let us know" implies that you speak for everyone here. I would rather think there are some people here that are actually willing to help.

CLEARLY THIS PERSON IS NOT YOU! Thanks for wasting my time and for some reason wasting your own time as well.

I am sorry if my experience and advice did not help you. Maybe someone else on here can help you with driving three leds without resistors. Have a good day.

Anybody else willing to help? - as long as I don't have to jump through your hoops and then kiss you feet at your apparent godly like authority here in Arduino land?

Once again, this seems to be a coding discrepancy whereas the third condition is not being met.

STILL LOOKING FOR ANSWERS IF ANYONE CAN HELP.

No need to post your code twice. Go back to the first post, choose the "modify" option and mark the code section as code, then you can delete the re-post.

Just makes it easier to read.

Suspect you may not get too many answers if you actually aggravate well-respected advisers.

It may surprise you, but failure to use the correct resistors may actually be the very cause of your problem.

I have an RBG LED (but just testing red right now for this condition) and I get horrible flicker on the 3rd condition (highest brightness). I have 1k resistors on the INPUT pins 3 and 4. Having the resistors there, seems to give me the effect I'm looking for which is for the LED to go LOW right away if one of the HIGH conditions is not met. Anyway.....

When the loop starts it looks fine - very dim red color. Input D3 looks fine - slightly brighter, but input D4 looks terrible (brightest). It does go brighter than the other two conditions but I get this HORRIBLE flicker from the LED. Why? Anybody had this happen?

I've tried different resistors and different inputs but same thing. In fact, switching and putting the buttonState2 statement before the buttonState1 will switch the issue - then the LED will flicker when D3 goes HIGH. Why the Flicker!?

    int redPin = 11;
    int greenPin = 9;
    int bluePin = 10;
   
    
    const int buttonPin1 = 3;
    int buttonState1 = 0;
   const int buttonPin2 = 4;
    int buttonState2 = 0;
    
    
    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(buttonPin1, INPUT); 
      pinMode(buttonPin2, INPUT);
     
    }
     
    void loop()
    {
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      time = millis();
      
  if (time < 5000){
     if (buttonState1==LOW){setColor(10,0,0);} //red low brightness
     
     if(buttonState1== HIGH){setColor(70,0,0);} //higher brightness
     if (buttonState2 ==HIGH) {setColor(150,0,0);} //highest 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);  
    }

I don't give a hoot if he's well respected here - he obviously feels that he can speak for everyone here by saying "let us know". We all have a voice and nobody should speak for others unless they are specifically asked to. You said the lack of a resistor may in fact be the problem. Had the other guy said that it could be the problem, I would have absolutely tried that, but he didn't. Anyway, since YOU did in fact say it could be the problem, I just tried a couple different resistor values and they did not affect this. I have since gotten it do make three different brightness values, but I get a horrible flicker on the very high brightness. Again, I have put resistors to the LED and it didn't change anything with the flicker. Please see my new post about the flicker issue - I'm soooo close!

Well it is pretty obvious. When you press button2 you will set the color to 150. However, you also evaluate button 1, which will be low(high if you also press it). That means the first if statement will be true, which sets the color to 10. But the third statement will also be true, which sets the color to 150. Thus causing your led to switch from 10 to 150 each loop cycle.

So somehow you have to ignore the first two if statements when button2 is pressed. You try to figure it out how you can do that. If you dont understand it just ask:)

Cool ok thanks. That's what I was thinking but I didn't want to say and put ideas in people's heads until they look at the code themselves.

I was thinking something like:

if (buttonState2=HIGH){
setColor ( #,#,#);
buttonState1, LOW;
}

But with this code I'm not sure if I'm setting buttonstate1 low or just making a Statement.

So in the original code I'm getting a sort of toggle effect because both conditions are true and it's trying to satisfy both the same time? Is that right?