Pages: [1]   Go Down
Author Topic: Drag Racing Practice Tree  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
CH3NO2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
Logged

What I do you need ear plugs, a gas mask and lots of money.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25732
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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)
« Last Edit: October 21, 2010, 04:05:53 pm by AWOL » Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
CH3NO2
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to make something like this http://goo.gl/29X4.  It's only some LEDs and a button.  
Logged

What I do you need ear plugs, a gas mask and lots of money.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: