Problems with arrays :-?

I have been using the RF (Radio frequency) modules in some of my project in combination with the Arduino. I have managed to send singular messages between each module, However i have been trying to find a way to be able to change the message without having to re-upload the code each time and be able to send multiple messages

Project context:
I want the transmitter to be able to send either “yes” or “no” depending on the High input of ptm buttons to the Arduino. And for the Receiving module to maybe light up a LED depending on the “yes” or “no” input.

Thanks in advance

Notes:
i have been using the radiohead library: RadioHead: RadioHead Packet Radio library for embedded microprocessors

code is attached

Error:
conflicting declaration ‘char Blank [1]’

#include <RH_ASK.h>//radiohead libary for the use of the RF transmitter
#include <SPI.h> // Not actually used but needed to compile
int YesPin = 7;//when high, the Serial should send the message “YES”
int NoPin = 6;//when high, the Serial should send the message “NO”
char Blank[3];// Array “blank” to be changed depending on the state of NoPin or YesPin
RH_ASK driver(2000, 9, 2, 10); // ESP8266 or ESP32: do not use pin 11

void setup()
{

Serial.begin(9600);
pinMode(YesPin, INPUT);
pinMode(NoPin, INPUT);
if (!driver.init())
Serial.println(“init failed”);
}

void loop()
{
if (digitalRead (YesPin)== HIGH);//If the Pin is high then it should change the array to “YES”
{
char Blank[0]= “Y”;
char Blank[1]= “E”;
char Blank[2]= “S”;
char Blank[3]=0;
}
if (digitalRead (NoPin)== HIGH);//If the Pin is high then it should change the array to “NO”
{
char Blank[0]= “N”;
char Blank[1]= “O”;
char Blank[0]=0;
}
if (digitalRead (YesPin) == LOW and digitalRead (NoPin) == LOW);//when no buttons are pressed( both of them are low) then the message will be changed to “…” to show that it is not yes or no
{
char Blank[0]= “.”;//This would be in the array when both YesPin and NoPin is low
char Blank[1]= “.”;//This is needed as i want some sort of filler message instead of it just spamming the previous state of the pin E.g. “…” “…” “YES” “…” “No” “…” instead of “YES” “YES” “NO” “NO” “NO” “YES”
char Blank[2]= “.”;
char Blank[3]= 0;
}
const char *msg = Blank;// this is what is needed to be changed to send different messages E.g. const char *msg = “message”; And this would send “message” to the receiving module connected to the arduino

Serial.println(Blank);// so i can see what it is sending to the arduino

driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(1000);// Sends every second
}

ask_transmitter03.ino (2.07 KB)

transmitter 03.txt (2.11 KB)

    {
      char Blank[0]=0;//clears the string, by being null terminator?
      char Blank[0]= "Y";
      char Blank[1]= "E";
      char Blank[2]= "S";
    }

Here, you are trying to create 4 arrays of the same name, with different sizes. This is NOT how you populate an array.

I am sorry, i am new to the arrays. How would you do so

You need to dimension an array with the maximum number of characters it will use. So:-

char Blank[2];// Array "blank" to be changed depending on the state of NoPin or YesPin

Needs to be 4 not 2 bytes long. 3 for the longest message “YES” plus one for the terminating character “0”

Now

   char Blank[0]=0;//clears the string, by being null terminator?
      char Blank[0]= "Y";
      char Blank[1]= "E";
      char Blank[2]= "S";

Is rubbish. Putting 0 in the first byte of an array does indeed make it a null array. BUT you then put “E” into the first character thus over writing your “end of character string” marker. You should be using this:-

      char Blank[0]= "Y";
      char Blank[1]= "E";
      char Blank[2]= "S";
      char Blank[3]=  0;// marks the end of the character array

Threr are better ways of doing this but this will work for a start.

thank you grumpy mike

i am also getting error message saying

conflicting declaration 'char Blank [1]'

would you be kind a tell me what might be wrong?

You should be using this:-

Sorry, Mike. Not even close.

     Blank[0]= "Y";
      Blank[1]= "E";
      Blank[2]= "S";
      Blank[3]=  0;// marks the end of the character array
      char Blank[0]= "Y";
      char Blank[1]= "E";
      char Blank[2]= "S";
      char Blank[0]=  0;// marks the end of the character array

Is very wrong

  blank[0] = 'Y';
  blank[1] = 'e';
  blank[2] = 's';
  blank[3] = 0;

Works

PaulS:
Sorry, Mike. Not even close.

     Blank[0]= "Y";

Blank[1]= "E";
     Blank[2]= "S";
     Blank[3]=  0;// marks the end of the character array

I am uncertain how to manipulate arrays, sorry i am new.
I was using this website, however i don't know if it the correct way
https://startingelectronics.org/software/arduino/learn-to-program-course/18-strings/

I was using this website, however i don't know if it the correct way

It is A correct way. There are other correct ways that are easier, depending on what you are trying to do with the array after you get data into it.

It is possible that you don't need an array at all. It is possible that, if you do need an array, that you don't need a global array.

What ARE you trying to do?

It sounds like you're just using the contents of the array basically as a boolean, so why not just do that? Have the sender transmit just a 1 or 0, then you can use that to toggle your LED on or off accordingly. Any reason why you're going the character route?

silly_cone:
It sounds like you're just using the contents of the array basically as a boolean, so why not just do that? Have the sender transmit just a 1 or 0, then you can use that to toggle your LED on or off accordingly. Any reason why you're going the character route?

I want to be able to eventually be able to put it on a lcd display or perhaps be able to send more than two messages aswell

PaulS:
It is A correct way. There are other correct ways that are easier, depending on what you are trying to do with the array after you get data into it.

It is possible that you don't need an array at all. It is possible that, if you do need an array, that you don't need a global array.

What ARE you trying to do?

I am sorry for my ignorance, i am trying to learn and i have little exprience

I want to be able to send multiple messages with my RF module and arduino, to do this i have to have some sort of variable or string that can change depending on the state of YesPin or NoPin.

to do this i am currently trying to use a array

please tell me how i can to this in a better way

Spades101:
I want to be able to eventually be able to put it on a lcd display or perhaps be able to send more than two messages aswell

I want to be able to send multiple messages with my RF module and arduino, to do this i have to have some sort of variable or string that can change depending on the state of YesPin or NoPin.

to do this i am currently trying to use a array

please tell me how i can to this in a better way

No need to send an arrary for this. I’d send a byte or an int. Then code the value with the message you want to send. Perhaps:

0 = No
1 = Yes
2 = Some other message
3 = Yet another message
.
.
etc.

Then at the receiving end you read that value and take the appropriate action. Hint: Think about the if / else and switch / case structures.

gfvalvo:
No need to send an arrary for this. I’d send a byte or an int. Then code the value with the message you want to send. Perhaps:

0 = No
1 = Yes
2 = Some other message
3 = Yet another message
.
.
etc.

Then at the receiving end you read that value and take the appropriate action. Hint: Think about the if / else and switch / case structures.

Thank You so much for the Idea : )

ditto what gfvalvo said. you can save the number to a variable, then use that variable in a switchcase statement to execute the action.

Switchcase

One thing you need to take away from this (that is not perhaps clear) is that char array[n] is a declaration of an array of length n, where array[n] = "x" is an assignment of x to array index n. The use of the statement char array[n] = "x" declares an array of length n and then an initialization equal to x. In the case where there is only one value of x, it is the same as

char array[n];
array[0] = 'x';

If, for example, you

char array[6] = '1'; // note the different use of double/single quotes

and then print the array, you'll get

49
0
0
0
0
0

Another takeaway is that if you declare an array globally it is automatically set to all zeros/NULLs. When declared locally however, the array must be initialized. If you simply make the local declaration as

char array[n] = {};

it will be initialized, in this case with a char array, to all NULLs.

char array[21]; // for up to 20 characters plus 1 null terminator


// to put "YES" in the array
array[0] = 'Y';  // Notice I am using single quotes.
array[1] = 'E';  // Individual elements of a character array get single quotes.
array[2] = 'S';
array[3] = 0;    // The null terminator belongs right after the final character.


// to put "NO" in the array
array[0] = 'N';  // remember single quotes
array[1] = 'O';
array[2] = 0;    // null terminator


// If you don't want to do so much typing, do this instead:
strcpy(array, "YES"); // double quotes this time
// or
strcpy(array, "NO");  // again, double quotes
// or
strcpy(array, "MAYBE");
// or whatever you want to put into your character array

// Remember:
// Your array needs to be big enough to hold the entire string,
// including the null terminator!
// If your array is too small, Bad Things Happen!