Expression cannot be used as function

Hello, im making a really simple traffic light project an i'm getting "expression cannot be used as function" error idk what's wrong. I'm also using the ezButton library. Thanks in Advance! :slight_smile:

#include <ezButton.h>

const int BUTTON_PIN = 2; 
const int LED_PIN0    = 3;
const int LED_PIN1    = 4; 
const int LED_PIN2    = 5; 
const int LED_PIN3    = 6; 
const int LED_PIN4    = 7; 

int TrafficCycle = 0;     
int lastButtonState;   
int currentButtonState; 
ezButton button(BUTTON_PIN);

void setup() {
  Serial.begin(9600);                
  pinMode(BUTTON_PIN, INPUT_PULLUP); 
  pinMode(LED_PIN0, OUTPUT);
  pinMode(LED_PIN1, OUTPUT);   
  pinMode(LED_PIN2, OUTPUT);   
  pinMode(LED_PIN3, OUTPUT); 
  pinMode(LED_PIN4, OUTPUT);               
  button.setDebounceTime(50);
}

void loop() {
  button.loop(); // MUST call the loop() function first

  if(button.isPressed()) {
    TrafficCycle = 1;
  } else {
    digitalWrite(LED_PIN0, HIGH);
     delay(50);
    digitalWrite(LED_PIN1, HIGH);
     delay(50);
    digitalWrite(LED_PIN0, LOW);
    digitalWrite(LED_PIN1, LOW);
    digitalWrite(LED_PIN3, HIGH);
     delay(1000);
    digitalWrite(LED_PIN3, LOW);
    digitalWrite(LED_PIN2, HIGH);
     delay(50);
    digitalWrite(LED_PIN2, LOW);
    digitalWrite(LED_PIN1, HIGH);
   }
   if(TrafficCycle = 0() {
    digitalWrite(LED_PIN3, HIGH);
    }
  if(TrafficCycle = 1() {
     delay(100);
    digitalWrite(LED_PIN4, HIGH);
     delay(1000);
    TrafficCycle = 0
  }
}

That one?
0(). Looks a lot like a function call, doesn't it?

(If you'd posted the actual error message I wouldn't have had to ask. This is no kind of introductory tutorial)

And don't forget, after fixing the non-functioning expressions, that a "=" and a "==" are not the same things.

Well im still learning and i havo 0 idea what is the diffrence between "=" and "==" + its still giving me this error

There is the error message i copied:
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Vývojová deska: "Arduino Uno"

C:\Users\Daniel\Documents\Arduino\sketch_apr30a\sketch_apr30a.ino: In function 'void loop()':

sketch_apr30a:46:24: error: expression cannot be used as a function

if(TrafficCycle = 0() {

                    ^

sketch_apr30a:46:26: error: expected ')' before '{' token

if(TrafficCycle = 0() {

                      ^

sketch_apr30a:55:1: error: expected primary-expression before '}' token

}

^

exit status 1

expression cannot be used as a function

This is how you call a function:

someFunction ();

Can you see that that looks a lot like

0 ()

?

In C++ to compare things, we use "==", so how about

if(TrafficCycle == 0) {

?

Needs a semicolon

Hello iwanttolearnarduino
Take a view here to gain the knowledge.
=
==
Have a nice day and enjoy coding in C++.
Дайте миру шанс!

Thx 4 help works now!

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