Completly stumped on why this will not work

SOLVED I went back over it and it was really quite simple after like two days of trouble shooting i realized that i was not resetting the leds after each time the loop went around so once it turned on it had no reason to turn back off. Thank you to everyone that helped me get though this. Well this is a great start for me apparently and man do i hate seeing two of my post on the front page but i have an issue. While i just got over my last problem i finished my little program to get three little lights to blink randomly. The problem is the fact that there are not turning off as soon as the program loads into the uno all of the leds just light up and no matter what i do they stay on if i press the button or unplug it change the delay in the loop i can not figure out what i have gone wrong with in this code.

int first_red_LED = 0;
int second_red_LED = 0;
int green_LED = 0;
int button = 0;
void setup()
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(2, INPUT);
    button = digitalRead(13);
  button = LOW;

void loop(){
  first_red_LED = 0;
  second_red_LED = 0;
  if (true == true){
    first_red_LED = random(2);
    second_red_LED = random(8);
  if ( button == LOW) {
    if ( first_red_LED  == 1 && (second_red_LED  == 2 || second_red_LED  == 4)) 
      digitalWrite(3, HIGH); 
    if ( first_red_LED == 1) 
      digitalWrite(5, HIGH);
    if ( second_red_LED == 2 || second_red_LED  == 4) 
      digitalWrite(4, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);

well i just checked and everything is in the right place and it does compile and run so that was not the problem.

i can not figure out what i have gone wrong with in this code.

You have not put each { on a new line. You have not used Tools + Auto Format to properly indent your code. You really should do both. As an experienced programmer, you might want to revert to putting the { on the line with the statement (I do not). As a newbie, the { goes on a line by itself. Trust me, it will make your code structure a lot more obvious.

Hi, could you post a circuit diagram, or pic of hand drawn circuit, and a pic of your project. This will help greatly to locate a solution to this problem.

Tom.... :)

Tell us (a lot) more.

How is the button connected, to the +5V or to GND ? Do you use a resistor ?

I hope you do have resistors with those leds and they are connected to the GND.

What is the goal ? You have a sketch that (randomly) turns leds on, while a button is pressed. As long as the button is pressed, they will not turn off. Since the delay is 110ms, I guess that all three leds are on after 1 to 3 seconds. Do you want each led to blink randomly independent, or is there some special reason for the linked-together randomness ?

You could try a different kind of led blinking (not tested):

analogWrite (first_red_LED, random (256));
analogWrite (second_red_LED, random (256));
analogWrite (green_LED, random (256));

OK i will be uploading picture as soon as my phone uploads it but is the picture is not the best it is the same design as the 2nd project in arduino project book all that is different is the code. So the point is that it is random and when the two red leds light up they are too make the gree one light up only when the other two ones are on and just for fun i am defently using resitors,d.eW0&psig=AFQjCNGwZkZOz9M42ki_2QwLZ8UWS36EDw&ust=1388459314627912

even if i do not press the the button they do not turn off.

Why not eliminate the possibility of hardware error and replace ONE of the LED's with build in one on pin 13?" Than set the "button" to LOW in Setup - thus bypassing the button hardware in Loop. Than add some Serial prints in places, right now you are just flying blindfolded.

OK i just moved the button stuff to the setup part and i changed it to port 13 and nothing happened differently i would like to add with my first out of the book setup it worked with the book codes so i believe it is my code i managed to mess up

Read my reply again.

i am still confused

Assuming you use a normal Arduino like a uno or so, there is a led and a resistor connected to PIN 13 on the pcb. This makes it harder to use as input. I usually avoid using pin 13 as an input.

First thing i would do is move the button to another pin, define the new pin as input with pullup and have the button switch to ground (As you detect button == LOW).

See if that fixes things. (I did not look in detail at the rest of the code).

Thanks, Guido

Ok so i have done all of those fixes that have been stated before non of them have worked i am starting to think it is either is that random is always making the value true or that the numbers do eventuly find the right number but it does not reset each time the loop comes around the way i want it to it also could be a combination fo these two things. Some more info on what it is doing the first red lights up then comes the second one imidiatly followed by the green led light it supposed to do that but it never resets and starts over.

Some more info

that would be useful would be your latest code. We don't guess what you changed.

You are reading your button state only in setup, not in your loop. So it looks just once to its state and then never ever looks at your switch again. Good luck!

Hi, sorry, see POST #3.

Thanks Tom.... :)