Pages: [1]   Go Down
Author Topic: Reaction Test  (Read 646 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey.
Im new to this arduino stuff and i'm sitting on some code that i think should work. the idea is sort of a reaction tester where a red LED blinks on for one second with random intervals. if a button is pressed while the red LED is still on the red LED turns off and a green one goes on.

can anyone help and point out where i've gone wrong. :/
Code:
int Correct=12;
int LED=2;
int Button=4;

void setup()
{
 pinMode(Correct, OUTPUT);
 pinMode(LED, OUTPUT);
 pinMode(Button, INPUT);
}

void loop()
{
   if(digitalRead(LED,HIGH);
  {
     if(digitalRead(Button,HIGH))
  {
    digitalWrite(LED,LOW);
    digitalWrite(Correct,HIGH);
    delay(2000)
    digitalWrite(Correct,LOW);
  };
  };
 
 delay(random(2000,4000));
  digitalWrite(LED,HIGH);
  delay(1000);
  digitalWrite(LED,LOW);
};

when i go to compile it just points me at this line
if(digitalRead(LED, HIGH);
{
...
}


Any help would be appreciated  smiley


Moderator edit: [code] [/code] tags added.
« Last Edit: December 28, 2012, 03:56:47 pm by Coding Badly » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13848
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when you call delay(1000) the user can press any button as much as he wants but his button is never tested when the LED is on.

Check the blink without delay example (tutorials) to get an idea how this app should be solved.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27353
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fix the formatting of the line
Code:
if(digitalRead(LED) == HIGH){
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

Thanks il rectify the code and see if it works smiley ta
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27353
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Of course, you are reading an output pin there, and the last thing you do in void loop is write it Low, so I doubt you'd ever see it high.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: