beginner's error

Hi guys,
I have a problem with brackets on a program that will allow me to manage the speed of a motor using a potentiometer so I would like to have help to finish this program:

char PWM_ENABLE = 3;
char D0_MOTOR_1 = 2;
char D0_MOTOR_2 = 4;
char AN_POTENTIOMETRE = A0;

int valeurPotentiometre = 0;
int vitesseDuMoteur = 0;

void setup() {

pinMode(D0_MOTOR_1, OUTPUT);
pinMode(D0_MOTOR_2, OUTPUT);
pinMode(PWM_ENABLE, OUTPUT);

digitalWrite(D0_MOTOR_1, LOW);
digitalWrite(D0_MOTOR_2, LOW);
analogWrite(PWM_ENABLE, OUTPUT);

Serial.begin(9600);

}

void loop() {
valeurPotentiometre = analogRead(AN_POTENTIOMETRE);
if(valeurPotentiometre > 512)
(
digitalWrite(D0_MOTOR_1, LOW);
digitalWrite(D0_MOTOR_2, HIGH);
vitesseDuMoteur = map(valeurPotentiometre, 512, 1023, 0, 255);
Serial.print("+");
)
else
(
digitalWrite(D0_MOTOR_2, LOW);
digitalWrite(D0_MOTOR_1, HIGH);
vitesseDuMoteur = map(valeurPotentiometre, 0, 512, 255, 0);
Serial.print("-");
)
analogWrite(PWM_ENABLE, vitesseDuMoteur);
Serial.println(vitesseDuMoteur);
delay(20);

}

I have this error message : “expected ‘)’ before ‘;’ token” for the first digitalWrite of the void loop

I have try different thing without success so i need your help :smiley:

  (
    ...
  )
  else
  (
    ...
  )

( and ) should be { and }

You put parentheses around your if and else blocks. Those should be brackets.
You can read all about it in the reference section: if - Arduino Reference

Firstly, compound statements in C++ use {}, not ().

Secondly, your pin number variables should probably be declared const. That way they will not occupy data memory at all.

Montmorency:
Secondly, your pin number variables should probably be declared const. That way they will not occupy data memory at all.

That is NOT the primary reason for using const. The primary reason is so that you don't accidentally use a variable containing a pin number on the left of an equal sign, where you meant to use a variable containing a pin state.

PaulS:
That is NOT the primary reason for using const. The primary reason is so that you don't accidentally use a variable containing a pin number on the left of an equal sign, where you meant to use a variable containing a pin state.

Theres no such thing as "primary" or "non primary" use of const. In general, it is always a good idea to follow the rules of const-correctness. And the benefits of that are numerous.

In C++ (as opposed to C) a major feature of const is that it produces compile-time constants: entities that are known at compile time and that don"t materialize as lvalues unless you really want them to. This is already a very nice and important feature.

In fact, since we are talking about C++ code specifically, a better fit for this context would be constexpr.