Go Down

Topic: Coding RGBs wont turn OFF!!!  (Read 151 times) previous topic - next topic

tea123

Apr 17, 2019, 09:12 pm Last Edit: Apr 18, 2019, 01:53 am by tea123
Hi guys,

Stuck here, basically using my arduino uno. Using a button to turn two rgb leds on where they turn red then both green individually before turning off. Everything works great apart from at the end they wont turn off, instead they remain a yellowy colour.

Ive attached my code; any help would be great cheers!!!!!!

int buttonState = 0;

void setup()
{
 pinMode(13, INPUT);             // button
 pinMode(11, OUTPUT);          // rgb led 1
 pinMode(10, OUTPUT);           // rgb led 1
 pinMode(6, OUTPUT);            // rgb led 2
 pinMode(5, OUTPUT);            // rgb led 2
 
}

void loop()
{
 // read the state of the pushbutton
 buttonState = digitalRead(13);
 // check push button is pressed
 if (buttonState == HIGH) {
   analogWrite(11, 255);
   analogWrite(10, 0);
   analogWrite(6, 255);
   analogWrite(5, 0);
   delay(2000); // Wait for 2000 millisecond(s)
   analogWrite(11, 0);
   analogWrite(10, 153);
   delay(4000); // Wait for 4000 millisecond(s)
   analogWrite(6, 0);
   analogWrite(5, 153);
   delay(7000); // Wait for 7000 millisecond(s)
 } else {
   int buttonState = 0;
   digitalWrite(11, LOW);
   digitalWrite(10, LOW);
   digitalWrite(6, LOW);
   digitalWrite(5, LOW);
   }
}

groundFungus

Do you have a pulldown resistor from the button input to ground?
You will save everyone's time if you read and follow the forum guidelines.  https://forum.arduino.cc/index.php/topic,148850.0.html

tea123


tea123

its the fact that i thought LOW meant it would be turned off but instead it seems to mean that its a yellowish colour.

evanmars

Don't know if this is your problem, but get rid of
Code: [Select]
int buttonState = 0;
 in your else clause.

DVDdoug

It's odd that you're using 4 outputs for two 3-color LEDs...    I think we need to see a schematic.  And, you your comments don't define the colors.

How about if you simply write all-low, do the LEDs go off?   Do they go on when you write all-high?  (That's without the switch or any if-statements, etc.)

Can you control the colors individually without using the switch or if-statement?

tea123

Don't know if this is your problem, but get rid of
Code: [Select]
int buttonState = 0;
 in your else clause.
Cheers, changed it but it didn't make a difference :/

tea123

It's odd that you're using 4 outputs for two 3-color LEDs...    I think we need to see a schematic.  And, you your comments don't define the colors.

How about if you simply write all-low, do the LEDs go off?   Do they go on when you write all-high?  (That's without the switch or any if-statements, etc.)

Can you control the colors individually without using the switch or if-statement?
Hi there, Yeah I have attached a schematic at the top. basically I had it hooked up to all three but I couldn't get the correct colours or for it to turn off outside the "cycle" I have programmed. 

Go Up