Hello! Im currently trying to program a homemade RC car with a brushless motor and a servo. This is the code causing the error of
Transmitter_Base_Code:61:3: error: 'radio' does not name a type
radio.write(&data, sizeof(Data_Package));
^~~~~
Multiple libraries were found for "nRF24L01.h"
\Documents\Arduino\libraries\RF24
Not used: \Documents\Arduino\libraries\RF24-master
exit status 1
'radio' does not name a type
And here is the full code
#include <SPI.h>
#include <RF24.h>
RF24 radio(9, 10); // nRF24L01 (CE, CSN)
const byte address[6] = "00001"; // Address
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
byte j1PotX;
byte j1PotY;
byte j2PotX;
byte j2PotY;
};
Data_Package data; //Create a variable with the above structure
void setup() {
Serial.begin(9600);
pinMode(27,OUTPUT);
// Define the radio communication
radio.begin();
radio.openWritingPipe(address);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
// Set initial default values
data.j1PotX = 127; // Values from 0 to 255. When Joystick is in resting position, the value is in the middle, or 127. We actually map the pot value from 0 to 1023 to 0 to 255 because that's one BYTE value
data.j1PotY = 127;
data.j2PotX = 127;
data.j2PotY = 127;
}
void loop() {
// Read all analog inputs and map them to one Byte value
data.j1PotX = map(analogRead(A1), 0, 1023, 0, 255); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255
data.j1PotY = map(analogRead(A0), 0, 1023, 0, 255);
data.j2PotX = map(analogRead(A2), 0, 1023, 0, 255);
data.j2PotY = map(analogRead(A3), 0, 1023, 0, 255);
}
// Send the whole data from the structure to the receiver
radio.write(&data, sizeof(Data_Package));
}
This isn't all my code and I'm no Arduino code master, i barely know python, so some help would be appreciated. Thanks!