Please Help: Compilation error: expression cannot be used as a function

I was making a drone's transmitter
Arduino Ide is showing "Compilation error: expression cannot be used as a function"
Can anyone fix this?
Here is the code


```cpp
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
#include <SPI.h>
RF24 radio(7, 8);
const byte(address) = "node1";

void setup() {
  // put your setup code here, to run once:
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
}

struct datapack {
  bool toggleSwitch1 = 0;
  bool toggleSwitch2 = 0;
  int joystickLeft_x;
  int joystickLeft_y;
  int joystickRight_x;
  int joystickRight_y;
};

datapack data;

void loop() {
  // put your main code here, to run repeatedly:
data.toggleSwitch1(digitalRead(4));
data.toggleSwitch2(digitalRead(5));

data.joystickLeft_x = map(analogRead(A0), 0, 1023, 0, 255);
data.joystickLeft_y = map(analogRead(A1), 0, 1023, 0, 255);
data.joystickRight_x = map(analogRead(A2), 0, 1023, 0, 255);
data.joystickRight_y = map(analogRead(A3)), 0 , 1023 , 0 , 255);

radio.write(&data, sizeof(data));
}

By Advay Shrivastava
India

Please edit your post, then select all and only the code and press the "<CODE/>" button to let it be shown in a better and more usable form.
Thanks.

1 Like
  1. use code tags
  2. capture complete error message using handy little button in IDE
  3. post it in code tags as well, so we can help you.
1 Like
1 Like

This is wrong:

What do you want it to do? Do you want something as in

This thing does not help. It is saying it's error in void loop first two lines and in data.joystickRight_y = map(analogRead(A3)), 0 , 1023 , 0 , 255)

For success on this forum, you'll have to learn to work with those who want to help. Please, edit your message to use code tags, and provide the complete error capture. Last request.
By the way, this line is incorrect, near as I can tell.
data.joystickRight_y = map(analogRead(A3)), 0 , 1023 , 0 , 255)
count the brackets opening and closing. Oh, and it's missing the semicolon at the end.

2 Likes

You need to match every ( with ).

Look close.

a7

1 Like

Thank you but still it is confusing

Helping is sometimes easy, sometimes seems a waste. 'See you later, alligator'.

2 Likes

The comment above gives only the information that something related to my post is confusing. Your post has no detail what is confusing.

You are able to ask questions about what you do not understand.

If you expect that somebody can read your mind. This is not the case.

If you continue posting without providing detailed information more and more users will go away like user camsysca already did.

This detailed information is at least asking what do you mean with
"quoting the words that you do not understand"

2 Likes

I add he must edit his first post to comply with the forum rules about "CODE" tags.

Unless it'll be done, I (and I think many of us) will cease to reply or try to help.

4 Likes

I second that.

3 Likes

Thank you, I will try it


```cpp
#include <RF24.h>
#include <RF24_config.h>
#include <nRF24L01.h>
#include <printf.h>
#include <SPI.h>
RF24 radio(7, 8);
const byte(address) = "node1";

void setup() {
  // put your setup code here, to run once:
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
}

struct datapack {
  bool toggleSwitch1 = 0;
  bool toggleSwitch2 = 0;
  int joystickLeft_x;
  int joystickLeft_y;
  int joystickRight_x;
  int joystickRight_y;
};

datapack data;

void loop() {
  // put your main code here, to run repeatedly:
data.toggleSwitch1(digitalRead(4));
data.toggleSwitch2(digitalRead(5));

data.joystickLeft_x = map(analogRead(A0), 0, 1023, 0, 255);
data.joystickLeft_y = map(analogRead(A1), 0, 1023, 0, 255);
data.joystickRight_x = map(analogRead(A2), 0, 1023, 0, 255);
data.joystickRight_y = map(analogRead(A3)), 0 , 1023 , 0 , 255);

radio.write(&data, sizeof(data));
}

So this is code formatted as a code-section.
Even better is if you delete this last posting and

re-edit your first posting So the code in your first posting is shown in a code-section.
using the pencil-icon below your posting

See I have recently come to Arduino Forum please cooperate and Please can you send the revised code by fixing all the errors. I can't understand how to basically revice the code

Thanks I will Try

This means "call a function named digitalRead passing 4 as parameter", which will return some value. Take this value and then pass it as parameter to another function named "toggleSwitch1"

Is this what you want to do?

1 Like

This is a user-forum. A user-forum is really different from WhatsApp, Telegram, etc.
Posting something short like

Does not even say what you will try

If you like to snapp-chatter. Use snap-chat

If you want really help then

I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.
This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

best regards Stefan