Will this code work?

I wrote a code to turn an LED on after you press a button if it hasn't been 5 seconds since you last pressed it but my arduino arrives in october so i was wondering if someone else could tell me if it works...

The Code:

int LED = a3;

unsigned long time = 0 ;

void setup() { // put your setup code here, to run once: pinMode (led, OUTPUT); pinMode (time, INPUT); digitalWrite (time); digitalWrite (time, 0); }

void loop() { // put your main code here, to run repeatedly:

unsigned long digitalRead (time);

if(time > 5){ digitalWrite(LED, HIGH); digitalWrite(time, 0); }else{(LED, LOW};

}

The first thing to do is click the button in the Arduino IDE that looks like a check mark. That will cause the code to be compiled. If the code won't compile (which yours won't), then certainly it won't work.

When you get a compilation error, you need to examine the contents of the black console window at the bottom of the Arduino IDE window. This will contain the full compiler error, which will tell you what the problem was that caused the compilation to fail. You will need to scroll the console window up to see the full contents.

I have checked it and there is one thing i don't get. In the highlighted line in the code below it says I need a ) before } and then says I need a primary expression before ) what does this mean?

int LED = 3 ;

unsigned long time = 0 ;

void setup() { // put your setup code here, to run once: pinMode (LED, OUTPUT); pinMode (time, INPUT); digitalWrite (time, 0); }

void loop() { // put your main code here, to run repeatedly:

unsigned long digitalRead (time);

if(time > 5){ digitalWrite(LED, HIGH); digitalWrite(time, 0); }else{digitalWrite(LED, LOW};

}

It’s very unhelpful to paraphrase error messages. Just copy and paste the error message verbatim.

I think the error message is quite clear. You have a } where a ) is expected. The two are not interchangeable.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don’t want to be in the code tags. If your browser doesn’t show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the “How to use this forum” post. Please read it.

it says I need a ) before }

else{digitalWrite(LED, LOW};

Look carefully at that line of code. Compare it to others in your sketch. Do you not see what it’s talking about? Do you not see what you left out? It’s just exactly what it said, you need a ) before the }. Parenthesis always have to be closed.

I tried what you said and it still didn’t work know what to do?

Oh Thanks everyone sorry i will make sure to check properly next time

How do you expect the variable "time" will ever be anything other than 0? You assign zero to it, never change it, and then test if its greater than 5.

You appear to be using it as a pin number in some places, and as a variable that will hold a time in others.

In fact your sketch doesnt appear to do anything to try to track the passage of time.

Pins 0 and 1 are used for uploading code, dont use them for functionality of your sketch unless you understand the constraints this imposes.

You realize there is a built in led on most arduino boards, typically on pin 13. Probably easiest to start with using that pin for the led!

Click the button which looks like a checkmark in Arduino IDE. Code gets compiled.

Check the contents of the black console window present at the bottom of the Arduino IDE window. You will get to know what caused a compilation error.