I'm trying to write Arduino code for receiver that receives hexadecimal values from another Arduino (Transmitter), then I want to check this values and store them in new array which I don't know its size, while transmitter sends values receiver will store them.
Values reaches successfully to receiver but I don't know how to store them in new array.
My receiver code is like this:
for (i = 0; i < len; i++)
{
if (receivedValue[i]==0x60)
{
//digitalWrite(LED1,LOW);
// store receivedValue[i] in the new array
}
else
{
if(receivedValue[i]==0x61)
{
//digitalWrite(LED3,LOW);
// store receivedValue[i] in the new array
}
if (receivedValue[i]==0x62)
{
//digitalWrite(LED4,LOW);
// store receivedValue[i] in the new array
}
// any other receivedValue[i] dont do anything
}
}
LEDs works successfully as I want but how to store them in array?
Two approaches suggested:
Array pre-defined with fixed size
#define MAX_ITENS 50 // The size of buffer uint8_t buffer[MAX_ITENS]; // The Buffer uint8_t posBuffer = 0; // Pointer to actual position loop() { .... // Add data to buffer posBuffer++; if (posBuffer == MAX_ITENS) { // Buffer overflow - You can set position to 0 // or give some error } else { buffer[posBuffer] = data; // Save the data } }
Use a dynamic array library I like this one .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.