Problems with primary-expression (argument/equation)

Hi Guys - In Advance - thanks for the many good topics in this forum - this is my first Q posted here in the forum.

I receive below error code in connection with below code.

I should mention that is is part of a bigger code, but isolated in this form I still get the error! I have tried to add parenthesis different places in my equation, but cannot make it work :frowning:

Error code

sketch_jun10a:35:86: error: expected primary-expression before '||' token

   if (G_SW_current == LOW  && G_SW_preveous == HIGH && millis() - G_time > debounce) || G_CMD == HIGH {

                                                                                      ^

exit status 1
expected primary-expression before '||' token

Arduino code

// Definition of PIN names and numbers
  const int G_SW2_Door = 8;           // G SW Door for outdoor Light
  const int G_TSW_Port = 9;           // G TSW Port - currently not used
  const int G_TSW_Door = 13;          // G TSW Door for Light in Garage
  const int G_Light3 = 29;            // G lys bagerst, IO kort 2
  const int G_Light4 = 31;            // G lys front_bag_midt, IO kort 2
  const int G_Light2 = 35;            // G lys midt, IO kort 2
  const int G_Light1 = 37;            // G lys front, IO kort 2 top
 
// Variables used for light in garage (toggelswitch)
  int G_State = HIGH;                   // Used for toggle light in Garage
  int G_SW_current = LOW;                     // Used for toggle light in Garage
  int G_SW_preveous = LOW;              // Used for toggle light in Garage
  long G_time = 0;                      // Used for toggle light in Garage
  int G_CMD = LOW;                      //Used for external commands for the light in Garage
  long debounce = 300;                  // Used for avoiding flicker på PIR
  unsigned long currentMillis = 0;      // Will be equal to millis() every time loop() is starting

void setup() {
// Definition af inputs:
  pinMode(G_TSW_Door, INPUT_PULLUP);

// Definition af outputs:
  pinMode(G_Light1, OUTPUT);
  pinMode(G_Light2, OUTPUT);
  pinMode(G_Light3, OUTPUT);
  pinMode(G_Light4, OUTPUT);
}

void loop() {
  currentMillis = millis();  //Timer should be used to control when to go into which subprocess

// Lightcontrol in garage
  G_SW_current = digitalRead(G_TSW_Door);                     // read the switch at the door
  if (G_SW_current == LOW  && G_SW_preveous == HIGH && millis() - G_time > debounce) || G_CMD == HIGH {
    if (G_State == HIGH) {
      G_State = LOW;                                          // Used for swithing light on
    }
    G_State = HIGH;                                           // Used for swithing light off
    G_time = millis();                                        // When the switch was last time checked
  }
  digitalWrite(G_Light1, G_State);                            // Switch the light on/off
  digitalWrite(G_Light2, G_State);                            // Switch the light on/off
  digitalWrite(G_Light3, G_State);                            // Switch the light on/off
  digitalWrite(G_Light4, G_State);                            // Switch the light on/off
  G_SW_preveous = G_SW_current;                               // Used for controlling the toggle function
  
}
G_CMD == HIGH {

Here, I’ve got a spare - you have it. )

Dont get your point! However - just realized what the problem is. The entire expression must be encapsulateed in parenthesis :slight_smile:

Kaniwd:
Dont get your point! However - just realized what the problem is. The entire expression must be encapsulateed in parenthesis :slight_smile:

That's why I gave you a spare one.

AWOL:
That's why I gave you a spare one.

But, you need to use them in pairs. Make a copy of the spare, and turn the copy over. Or not. You don't really need more parentheses. You just need them in the right places.

More parentheses, to make your meaning clear, would not be amiss.