I don't really know what I've did wrong. Kindly please say what I need to do now
Transmitter-Code.ino (1.99 KB)
I don't really know what I've did wrong. Kindly please say what I need to do now
Transmitter-Code.ino (1.99 KB)
Please do this:
If the text exceeds the forum's 9000 character limit, save it to a .txt file and podst it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.
Whenever possible, you should post your code directly to the forum, using code tags. Many forum users won't or can't download attachments, so you make it much less likely that you will get help when you post code that way. When the code exceeds the forum's 9000 character limit, it's OK to post it as an attachment, but your code is nowhere near that limit
Here's the code, now with [code][/code]
tags:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
// Define the digital inputs
#define jB1 1 // Joystick button 1
#define jB2 0 // Joystick button 2
RF24 radio(5, 6); // 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 j1Button;
byte j2PotX;
byte j2PotY;
byte j2Button;
byte j3PotX;
byte j3PotY;
byte j3Button;
byte j4PotX;
byte j4PotY;
byte j4Button;
};
Data_Package data; //Create a variable with the above structure
void setup() {
Serial.begin(9600);
// Define the radio communication
radio.begin();
radio.openWritingPipe(address);
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_LOW);
// Activate the Arduino internal pull-up resistors
pinMode(jB1, INPUT_PULLUP);
pinMode(jB2, INPUT_PULLUP);
// 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;
data.j1Button = 1;
data.j2Button = 1;
}
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);
// Read all digital inputs
data.j1Button = digitalRead(jB1);
data.j2Button = digitalRead(jB2);
// Send the whole data from the structure to the receiver
radio.write(&data, sizeof(Data_Package));
}
void loop(void){
msg[0] = map (analogRead(0), 0, 1023, 0, 179);
radio.write(msg, 1);
}
The error message always gives a bit more information than just the error (scroll up the black window to find out more).
I get different errors from the one you quoted:
Arduino: 1.8.9 (Mac OS X), Board: "Arduino/Genuino Uno"
Build options changed, rebuilding all
/Users/julianchurch/Downloads/Transmitter-Code/Transmitter-Code.ino: In function 'void loop()':
Transmitter-Code:67:6: error: redefinition of 'void loop()'
void loop(void) {
^
/Users/julianchurch/Downloads/Transmitter-Code/Transmitter-Code.ino:53:6: note: 'void loop()' previously defined here
void loop() {
^
Transmitter-Code:68:3: error: 'msg' was not declared in this scope
msg[0] = map (analogRead(0), 0, 1023, 0, 179);
^
exit status 1
redefinition of 'void loop()'