-1

The code i make is this */

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Servo.h>
#define CE_PIN   9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;
int servoy;
int servox;
Servo Yservo; 
Servo Xservo; 

RF24 radio(CE_PIN, CSN_PIN);

int joystick[2];

void setup()RF24
{
  Serial.begin(9600);
  delay(1000);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  Xservo.attach(3);
  Yservo.attach(5);
}

void loop()
{
  if ( radio.available() )
  {
    bool done = false;
    while (!done)
    {
done = radio.read( joystick, sizeof(joystick) );
servox= joystick[0]/5.683; 
servoy= joystick[1]/5.683;    
      Serial.println(servoy);
      Yservo.write(servoy);
      Serial.println(servox);
      Xservo.write(servox);
    }
  }
  else
  {    
      Serial.println("NO RADIO CONECTION");
  }

}

and i don't know what happen it's said that

 sketch_aug20b_rc_rc_rc_22:33:13: error: expected initializer before 'RF24'

 void setup()RF24

             ^

C:\Users\ASUS\Documents\Arduino\sketch_aug20b_rc_rc_rc_22\sketch_aug20b_rc_rc_rc_22.ino: In function 'void loop()':

sketch_aug20b_rc_rc_rc_22:51:6: error: void value not ignored as it ought to be

 done = radio.read( joystick, sizeof(joystick) );

      ^

exit status 1
expected initializer before 'RF24'
1
  • It's basically saying "Why have you got a random "RF24" in the middle of your code like that?" - and I'm asking the same thing...
    – Majenko
    Commented Aug 20, 2019 at 14:58

1 Answer 1

1

You have two problems:

sketch_aug20b_rc_rc_rc_22:33:13: error: expected initializer before 'RF24'

void setup()RF24

         ^

It's basically saying "I don't understand what you mean by RF24 here". That RF24 in that line should not exist. I assume you made some kind of typo or copy-pasta error.

Second:

C:\Users\ASUS\Documents\Arduino\sketch_aug20b_rc_rc_rc_22\sketch_aug20b_rc_rc_rc_22.ino: In function 'void loop()':

sketch_aug20b_rc_rc_rc_22:51:6: error: void value not ignored as it ought to be

 done = radio.read( joystick, sizeof(joystick) );

That is saying that radio.read doesn't return a value - yet you are trying to assign that value that doesn't exist to something.

According to the documentation for RF24::read():

Read the available payload

The size of data read is the fixed payload size, see getPayloadSize()

Note

I specifically chose 'void*' as a data type to make it easier for beginners to use. No casting needed.

No longer boolean. Use available to determine if packets are available. Interrupt flags are now cleared during reads instead of when calling available().

Parameters

  • buf Pointer to a buffer where the data should be written
  • len Maximum number of bytes to read into the buffer

    if(radio.available()){ radio.read(&data,sizeof(data)); }

Returns

No return value. Use available().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.