About variables definition

Sorry I have a silly question, looking for a kind of no classification variable that can receive any data from a RC or Bluetooth and print that out?
Is there a variable like this exist?

No. Every variable must have a type. You could have multiple functions with the same name that accept different data types or combinations of data types. This is known as function overloading and is how Serial.print() works, for instance

What exactly are you trying to do ?

1 Like

what exactly I'm trying to do is let a variable can just copy whatever the RC receiver got from it's Transmitter.

It seems that you want to connect an RC receiver to the Arduino and have the Arduino interpret the data received from the RC transmitter. Is that correct ?

If so, what information do you want to extract from the received data ?

1 Like

the data sent is also simple, mixed numbers and string.

Are the numbers in the form of raw data (I doubt it) or more likely are they sent as ASCII characters representing the numbers ?

What you describe does not sound like any RC system that I have ever come across. What make/model of RC system are you using and can you post an example of a typical message sent by the transmitter ?

1 Like

it is a RC 433MHz unit as picture, the joystick send X/Y axis number data, and the button send character like 'A' 'B'.

FROM: https://www.instructables.com/Arduino-RC-Gamepad/

And a sample of the message for a number ?
Does the message contain the data for all of the inputs every time or only the data for whichever input is used ? How are the X and Y numbers differentiated in the message ?

1 Like

this code used number for button, but I used 'A'/'B'/'C' for the button.

#include <VirtualWire.h>

//gamepad setup
int up_button = 2;
int down_button = 4;
int left_button = 5;
int right_button = 3;
int start_button = 6;
int select_button = 7;
int joystick_button = 8;
int joystick_axis_x = A0;
int joystick_axis_y = A1;
int buttons[] = {up_button, down_button, left_button, right_button, start_button, select_button, joystick_button};

void setup()
  //gamepad setup
  for (int i; i < 7; i++)
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH);

  Serial.begin( 9600 );
  //transmitter setup
  vw_set_tx_pin(12);          // Sets pin D12 as the TX pin
  vw_set_ptt_inverted(true);  // Required for DR3100
  vw_setup(2000);             // Bits per sec

int counter = 0;

int Xint;
int Yint;

char Xstr[60];
char Ystr[60];

void loop()
  // Read and store Sensor  data
  Xint = analogRead(joystick_axis_x);
  Yint = analogRead(joystick_axis_y);
  // Convert integer data to Char array directly 

  int XstrLength = String(Xstr).length();
  if(Xstr[XstrLength-1] != '|'){
    Xstr[XstrLength] = '|';
    Xstr[XstrLength+1] = '\0';
  char combinedArray[String(Xstr).length() + String(Ystr).length() + 1];
  sprintf(combinedArray, "%s%s", Xstr, Ystr);

  vw_send((uint8_t *)combinedArray, strlen(combinedArray));
  vw_wait_tx(); // Wait until the whole message is gone 



  sprintf(combinedArray, "%s%s", Xstr, Ystr);

So, the X and Y values are being sent as a string after much manipulation including conversion to a String

In view of that what you need is a function to receive a string (not a String) and to parse it and convert it to variables that you can use

Take a look at Serial input basics - updated for some ideas

1 Like

Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.