New user simple Question

hi Guys , Just a simple question I have been using the Arduino just for a couple of days now and need to for a collage project.

what I am trying to do , but it doesn't like it , is to increment an integer(time) x 1 every time output 3 is high. I have declared time as an int at the start..

so if (digitalRead (3, HIGH);{ time = (time + 1) }

now when I compile its doesn't like it I know my brackets have to be incorrect and maybe my increment is incorrect any help for newbie would be much appreciated

if (digitalRead(3) == HIGH)
{
   time = time + 1;
}

increment an integer(time) x 1 every time output 3 is high.

This will increment time if pin 3 input (not output) is high. Is that what you meant?

what I am trying to do , but it doesn't like it , is to increment an integer(time) x 1 every time output 3 is high.

You need to look at the state change detection example, to learn how to do something when the pin BECOMES high, rather than when the pin IS high, as you are doing now.

Also

time = time + 1;

is more usually written as:

time++;

if (digitalRead (3, HIGH);{ time = (time + 1) }

if (digitalRead (3)) //check pin 3 { time = (time + 1); // increment variable }

or

if (digitalRead (3)) //check pin 3 { time++; // increment variable by one }

Notice / subjects to check / study: 1. conditional if 2. shorthand for increment 3. language syntax - terminate line by semicolon 4. code block ( if() {...} )

Good luck

[quote]Also 
Code: [Select]
time = time + 1;


is more usually written as:
Code: [Select]
time++;

Depends who’s writing it. I find
time = time +1;
to be a lot more clear as to what’s going on.
Then other variations such as
time -1;
time >>1;
time <<1;
time +2;
etc. all more easily follow.

Of course, if it’s needed “for a collage project” I imagine there will a lot of cut & pasting going on.

if (digitalRead (3, HIGH);{

How much can be wrong with just one simple if ?

I spy a semi-colon that should not be there, a missing bracket and no actual digitalRead() of pin 3

How much can be wrong with just one simple if ?

Well, OP could have misspelled digitalRead().

CrossRoads the shifts are not increments, The left shift will actually go in the sequence 0,1,2,4,8,16...

CrossRoads: Of course, if it's needed "for a collage project" I imagine there will a lot of cut & pasting going on.

He might get stuck on that.