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

Please do not say this!! I already told you I am recently came to forum. Instead of finding my mistakes can you please help. This is why I have created this thread. I got it that you want long answers. Look at the main page, I edited it and used code. You are making fun of me around the whole world. You wanted me to give explanation, in this message I gave.
Now if you want to make fun of me then you are left with 2 options Help or Go out of this thread because I am Done you making fun of me.
Do you even realize what are you doing?
You are making fun of another country's person.
I will give you one Quote "Think before you speak/write"
And "Judge yourself before judging others"
See, I have tried to be humble and polite but in spite of that you are making fun of me.
You too read the section "BE POLITE" in t&c's
I have created this thread for answers not humiliation
I have spent my 20 min in the documentation
You should also read because I think you have also forgot some t&c's
"This is a user-forum. A user-forum is "really different" from WhatsApp, Telegram, etc."
I do not use these sources to contact
I have never ever used Telegram
Even Short sentences also make sense and if it is not enough then message me from my email or message privately
See you are making me and you go off topic
So get on topic
Once again I Will not use any social media platform
I Read the t&c's
Now can you be useful and help?

Anyway I found out the mistake
OLD 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));
}

NEW CODE:

#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));
}

Thank you but this code didn't work. Look above... This is the right code.
Well thank you for your time!!!

Regards
Advay Shrivastava
India

Ignoring the help of others is also rude. This:

And this:

are now correct, the changes were pointed out to you and you did not acknowledge, but seem to be claiming the find for yourself. Bravo! Hence, you are promoted to 'ignore' from 'mute', as I doubt I will have any interest in helping you in future.
I bear you no ill will, I simply am here to help those who understand the helper-helpee relationship differently than you apparently do. I need no more frustration in my life.
Best wishes

I don't see how it's "right" or works or even compiles. This is nonsense:

Oh really, Check with your compiler
It works for me

I heard it. I am sorry.

For the moment, I will stick around. I created a simple example, for discussion:

const byte(address) = "something";
void setup() {
}

void loop() {
}

Amusingly, it does compile, but you seem to be confused. "It compiles" does not equate to "It works". @mancera1979 is totally correct, the line they objected to is not doing what you think it's doing. So, we must ask, at a detailed level, what is it you think that line does?
Here's what the compiler dislikes about it, if you change your preferences in the IDE to output more errors and warnings you can get the same feedback:
C:\Users\CAMSYSCA4\Documents\Arduino\sketch_apr12a\sketch_apr12a.ino:1:23: warning: invalid conversion from 'const char*' to 'byte {aka unsigned char}' [-fpermissive]
const byte(address) = "something";
^~~~~~~~~~~
What does that tell you?

1 Like

REALLY ....

So that's a compiler warning on when compiled for an AVR board. With different compiler options, it's an error if attempted for an ESP32:

sketch_apr12a:1:23: error: invalid conversion from 'const char*' to 'byte' {aka 'unsigned char'} [-fpermissive]
 const byte(address) = "something";
                       ^~~~~~~~~~~

But, @advay_and_akshat, I really don't care if you believe me (or anyone else here) .... especially with an attitude like that. You Know Best.

2 Likes

yeah, but are you sure the code you wrote does exactly what you made for? The code seems a bad "mix" of many things with code residues from various attempts and an unnecessary code like that "#include <printf.h>". On top of that, that "const byte" statement doesn't make any sense, and even if it compiles you can't "fit" a C string in a byte variable.
Using Wokwi I tried adding a printout to @camsysca example code:

const byte(address) = "something";
void setup() {
  Serial.begin(9600);
  Serial.println(address);
}

void loop() {

}

So the content of "address" variable is just the value "18" and the same happens if I remove the brackets:

const byte address = "something";

So the compiler just ignores the brackets but I can't understand what that value could come from. But surely it doesn't contain the expected string.

The radio function "openWritingPipe()" requires a pipe ID/address (a number, not a string anyway!), so you are here implicitly using the pipe 18 so I don't know what this could help you and, still, why on Earth you wrote "node1" string trying to store it over a byte variable...

2 Likes

It gives the same result if you use "node2", "something", or "infect my computer with a virus".

const byte(address) = "node2";
void setup() {
  Serial.begin(115200);
  Serial.print("0x");
  Serial.println(address,HEX);
}

void loop() {
}

It's casting a pointer to wherever the compiler decided to place the string into a byte. You'll get different answers in 'address' depending on any other strings, the compiler optimizations and placement in memory.

1 Like

I don't know weather you will be able to understand case it is in hindi

Google translate it...

Uh sorry I didn't mean to show attitude, I just wanted you to know
Once again I am sorry

It works for me...

I didn't Ignore,
Do you have to credit others for their support?
I am new to forum so that's why I didn't know

This topic has been solved

Only reply here if:

  • You have additional details
  • The solution doesn't work for you

If you have an unrelated issue, please start a new topic instead.

Yes, I have.
@advay_and_akshat - in #32 you provided a link to the video to prove that your code is correct. I don't know Hindi, but the code in the video doesn't need translation. You just didn't copy the code from the explanation correctly. Look at the highlighted line below

and then compare it with your code:

Instead of arguing, take the time to understand the difference between yours and video code and why yours is an error.

2 Likes

I think in hindsight my original decision was correct. Goodbye.

1 Like

Oh, I see.
Thank you...
I will try with const byte address[]= "node1"