Why is my if statement (bottom of code) causing an error in my #define string at the top?

This may be a question about the Arduino IDE interface, but anyway, I have the start of a new simple program that I'm trying to write myself rather than just chop up snippets of existing code. For that reason I want a better understanding of how/why this works so this is primarily an academic question.

Anyway, I've used the #define in the same way previously without trouble. (#define -some text string- then a pin) Now, as a result of a new if statement at the bottom of my program the IDE highlights the define (at the top of the code) as if that's the problem.

"too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'" is my error.

Can someone help clarify? I want to get this straight in my head before proceeding. Code below:

#define RingMotor (2)
#define RingSensor 3
#define TriggerMotor 4
#define TriggerSensor 5
// the setup function runs once when you press reset or power the board
void setup() {
  pinMode(RingMotor, OUTPUT);
  pinMode(RingSensor, INPUT); //RingMotor Sensor
  pinMode(TriggerMotor,OUTPUT); //TriggerMotor Pin
  pinMode(TriggerSensor,INPUT); //TriggerMotor Sensor
// the loop function runs over and over again forever
void loop() {
  digitalWrite(RingMotor, HIGH);
  digitalWrite(TriggerMotor, LOW);
  if (TriggerSensor>=HIGH) (digitalWrite RingMotor LOW)

(edit J-M-L: added code tags)

The easier you make it to read and copy the code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

digitalWrite RingMotor LOW

Did you forget the comma between the parameters and the brackets round them ?

if (TriggerSensor>=HIGH) (digitalWrite RingMotor LOW)

Missing ,

I don't know specifically why the error shows up where it does but you will come to realise that a lot of the time the actual error and the problem the compiler sees are not in the same place. Consider, for example, a function with lots of pairs of {} but with one missing } near the start. The compiler will work through it and find pairs, they won't be the right pairs but the compiler won't notice that. Only when it gets to the next function does it notice a new function defined before the final } in the function with the error. The compiler will report that you can't define a function inside another function because that's what it sees. You have to realise what the problem really is.

if (digitalRead(TriggerSensor) == HIGH)
    digitalWrite( RingMotor,LOW);

You missed the digitalRead()…
There are several ways to approach what you’re doing, but this is a straight fix.

Also check the pinMode() of the inputs…do you have pull-ups / downs ?

Hey thanks, Perry & everybody else! Sorry for the late reply I guess I wasn't getting notified. Anyway, I got this mostly working and really its just me getting used to the interface. Thanks for explaining!

well RingMotor does have parenthesis, but digitalWrite requires 2 arguements

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.