I understand I need to create new array but how do I know what size it will be ?
(because I don't know how many changes I need to do )
I did the same thing in C# - so maybe this can help (I used "List" so it much more easy ....)
this is the C# code that is working
List<string> msg= new List<string>();
*
* // insert data into msg list - so it's not empty.
*
List<string> changeOne = new List<string>();
for (int i = 0; i < msg.Count; i++)
{
if (msg[i]=="A") //this is a new message
{
changeOne.AddRange(new[] { "5C", "70", "5C" ,"70", "5C", "70", "5C","73", "20" });
}
else
{
if (msg[i] == "0")
{
//changeOne.Add("1A");//start of new msg
}
else
{
changeOne.Add(msg[i]);
}
}
}
can you say what is the max size I can save? - I don't think it will be more then 150 hex values
also how can I know how much am I using when the code is running?
You can use a loop. BUT, it's wasteful... The Arduino isn't a Intel i9 with 64GB of RAM and fancy memory management. Why not:
a) Put the values in one array to start with?
b) Just loop over both sequentially if you need it.
But really, this is the THIRD very related question about arrays. Which all would be clear if you did some research / leaned a bit more about actually using micro controllers...
On a micro controller you*
a) don't dynamically size an array
b) don't concatenate arrays
c) don't do fancy dances like reverse if you don't really need to. For example, sort it.
Of course there are always exceptions but he. "Exceptions prove the rule" as we say.
a) I can't do that because I get data from all kind of devices and then need to send it as 1 array to another device.
b) can you show me an example of how to do it?
because let say I define a array of size 150 (which is the maximum byte I can think of I will need)
how do I loop the next one
what will be the first place to put the data for the next array ?
array1 [] {0x01 ,0x02}
array2 [] {0xA1 , 0xA2}
array3 [] {0xC1 , 0XC2}
arrayFinal [6] = {0};
for (int i = 0 ; i<sizeof(arrayFinal); i++)
{
arrayFinal[i] =array1 [i];
}
for (int i ="What do I need to write here? ; i<sizeof(arrayFinal); i++)
I will explain :
my project is to read from 1 RS485 device , and send to another RS485 device the data with some changes.
I'm using Mega
to be able to read from device and save the data as HEX - is working.
to send data to other device (is working with sample\demo message )
so I know how to read and how to write .
now my problem is adding some chars in the original message
this is why I want\need to do this
do you need more explain or something to understand what I need to get ?
this project is working for me on on C# on x86 , so it's doable -
my problem is to make it work on Arduino ...