If Statement HELP!

to measure distance.

and what i'd like to do is to add and if statement, can I do the following.

if (value of pin 7 < 50cm)
{
output pin 6 = high
}
.

how can I do the above in Arduino?

Bassam

if (value of pin 7 < 50cm)
{
output pin 6 = high
}

Try something like this:

if (analogRead(7) < 50)
{
digitalWrite(6, HIGH);
}

Lefty

thnx for the reply,

i'm trying to create now PWM using Adruino UNO.

any errors in the following if statement?

if (cm >= 0 && cm <= 280)
{
x = ((cm/300)*255); // x is int, and cm is long
else

x = 255;
}

analogWrite (ledPin, x);
delay (30);

PS: i'm adding this inside the void loop () of the following PING ))) code.

x = ((cm/300)*255);

If cm is an int, in the range 0 to 280, cm/300 will be 0.

You need to multiply by 255, first, then divide by 300, or cast the values to floats, so integer division is not performed.

any errors in the following if statement?

if (cm >= 0 && cm <= 280)
{
x = ((cm/300)*255); // x is int, and cm is long
else

x = 255;
}

analogWrite (ledPin, x);
delay (30);

basically yes!
the syntax is
IF (condition)
{
do this
}
ELSE
{
do this
}

you have your else inside your first "do this" !