Go Down

Topic: Drag Racing Practice Tree (Read 1 time) previous topic - next topic

dragracer28

I'm trying to make a drag race practice tree.  It has a stage light that turns on when you press a button then, a timer that runs and turns on a yellow when it's done. Then it will show a red light if you let off the button early or a green light if you were on time

Code: [Select]
int stage = 1;        //the switch for stage will go here
int stageLight = 12;  //stage light output
int yellowLight = 11;  //tree amber light output
int greenLight = 10;  //tree green light output
int redLight = 9;    //tree red light output

void setup()
{

 pinMode(stage, INPUT);
 pinMode(stageLight, OUTPUT);
 pinMode(yellowLight, OUTPUT);
 pinMode(greenLight, OUTPUT);
 pinMode(redLight, OUTPUT);
}

void loop()
{
    if(analogRead(stage) == HIGH);
     {
       digitalWrite(stageLight, HIGH);
       delay(500);
       digitalWrite(yellowLight, HIGH);
     }
}


 I need someway to know if I'm letting go of the button to soon which would turn the red light on or at the correct time which would turn the green light on.
What I do you need ear plugs, a gas mask and lots of money.

AWOL

#1
Oct 21, 2010, 10:35 pm Last Edit: Oct 21, 2010, 11:05 pm by AWOL Reason: 1
Code: [Select]
if(analogRead(stage) == HIGH);

A couple of things wrong here.
First is the semicolon.
Second is the "analogRead() == 1", which is pretty unlikely.
And (stretching the definition of "couple" a tad) thirdly is the "analogRead".

(though, to be fair, I know practically nothing about drag racing)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

dragracer28

I want to make something like this http://goo.gl/29X4.  It's only some LEDs and a button.  
What I do you need ear plugs, a gas mask and lots of money.

PaulS

If you are reading the state of a pushbutton, you should be using digitalRead. Unless you have plugged the switch into an analog pin. If that is the case, you should move the switch to a digital pin AND use digitalRead.

The ; on the end of the if statement forms the body of the if statement. If the conditional clause is true, the body of the if statement is executed. With the ; as the body of the if statement, it acts like a NO-OP (i.e. it does nothing - no operation).

Remove the ; to make the code between the { and the } the body of the if statement.

Go Up