'if' problem

Hi to everyone in arduino area. I am new to this world and as a handyman i am very facinated with all this.
*First of all is there any complete guide for learning arduino programming?
Now to the point. i have this issue (i want to control an ESC):
if (signal1 = HIGH); {
servo1.write(70);
}
else {
servo.write(defPos); //defPos is set at 40 degrees
}
and i get an error at the else part ('else' without a previous 'if')
IF it's already answered plese redirect this post.
Thanks in advance Mike

There should be no semicolon at the end of an if.
Also, you probably want ==

Hi Mike

Arduino programs are written in the C programming language. ( You can also use a more advanced language called C++ but, to begin with, C should be enough). So, part of the answer to your question is to find books or online tutorials about C.

However, the Arduino comes with specific functions built in to allow your C program code to access the hardware features of the Arduino, like the input and output pins. You won't find these mentioned in a generic C tutorial, but they are explained in the Reference part of this website.

A good place to begin, though, would be with the example programs in the Tutorial section http://arduino.cc/en/Tutorial/HomePage. Start with the easy ones and work through them to understand what each part does. You will start to pick up the C programming language.

The example programs are also contained in the Arduino IDE (integrated development environment - long name for the software you use to write Arduino programs and load them onto your Arduino) which you can download from this website.

Then, try making your own changes to the example programs. For example, if you have a program that flashes the onboard LED on the Arduino, try changing it to flash faster or slower, or to alternate long and slow flashes.

Hope that helps

Ray

You are the best. This litle details make the diferance.
It works great. so the part is like this just for others to learn from my mistakes:
if (signal1 == HIGH) {
servo1.write(70);
}
else {
servo1.write(defPos); //defPos is set at 40 degrees
}

Hackscribble:
Hi Mike

Arduino programs are written in the C programming language. ( You can also use a more advanced language called C++ but, to begin with, C should be enough). So, part of the answer to your question is to find books or online tutorials about C.

However, the Arduino comes with specific functions built in to allow your C program code to access the hardware features of the Arduino, like the input and output pins. You won't find these mentioned in a generic C tutorial, but they are explained in the Reference part of this website.

A good place to begin, though, would be with the example programs in the Tutorial section http://arduino.cc/en/Tutorial/HomePage. Start with the easy ones and work through them to understand what each part does. You will start to pick up the C programming language.

The example programs are also contained in the Arduino IDE (integrated development environment - long name for the software you use to write Arduino programs and load them onto your Arduino) which you can download from this website.

Then, try making your own changes to the example programs. For example, if you have a program that flashes the onboard LED on the Arduino, try changing it to flash faster or slower, or to alternate long and slow flashes.

Hope that helps

Ray

I read them and also viewed a 11 part turtorial on YOUTUBE but this litle details are very unlikely to trace a begginer.
Although thank you very much for the reply.

You can be more concise, and simply do

  if (signal1)
    servo1.write(70);
  else
    servo1.write(defPos);   //defPos is set at 40 degrees

(I am assuming it was a typo and there is only one servo object.)

There's no need to compare to HIGH as HIGH reads as true and LOW as false.
Also for single line statements the braces are optional - however if one arm of
the if is complicated its best to use braces on both so they visually match - easier
to see the structure then.

There is yet another way to do this, using a conditional expression:

  servo1.write (signal1 ? 70 : defPos) ;

In fact there are 2 esc's and one servo cause i am building a hover craft.
so in the proggram there are servo1,servo2 as esc and servoWings as actual servo.

Can you exlain to me the example you gave me?

]]servo1.write (signal1 ? 70 : defPos) ;[[

70 is the degrees if signal1 is true? (if signal is 5v)
the question mark what variable is? and the dual dot is something like else?

Mark is showing you an example of the ternary operator. It has the general form:

x = expression1 ? expression2 : expression3;

Expression1 is some form of conditional expression. In your example, it is a test on signal1. If signal1 evaluates to logic True, expression2 is evaluated. If expression1 is logic False, expression3 is evaluated. The result is assigned into x. Since your if-else statement is deciding whether to pass 70 (i.e., logic True) or defPos (i.e., logic False), Mark rewrote the ternary as:

servo1.write (expression1?expression2: expression3) ;

or

servo1.write (signal1 ? 70 : defPos) ;

Thank you very much, this was a very helpfull tip. i'll try it as soon as possible with a led at the beggining to see how it interacts.
this type of form its much better for digital inputs. i am getting more and more thrilled about the arduino automization and limitless ways to do the same thing.