Can someone help me explain how to easily access bytes in a byte array?
void IncomingByte (const byte c)
{
if (tailindex <= 256)
{
ringbuffer[tailindex++] = c;
Serial.println (ringbuffer[tailindex]); //this doesn't work for accessing bytes
}
else
{
tailindex = 0;
}
if (tailindex == 8)
{
for (int x = 0; x < 8; x++)
{
Serial.println (ringbuffer[x]); //this works fine for accessing bytes
}
}
}
Nothing wrong with that assuming that the author meant to write it that way. It sets the value of the current entry in the array then increments the index to the array.
Can someone help me explain how to easily access bytes in a byte array?
byte anArray[] = {12, 23, 45};
void setup()
{
Serial.begin(115200);
for (int x = 0; x < sizeof(anArray); x++)
{
Serial.println(anArray[x]);
}
}
void loop()
{
}
ringbuffer[tailindex++] = c;
Serial.println (ringbuffer[tailindex]); //this doesn't work for accessing the byte just saved because tailindex has been incremented since then
tailindex = 0;
ringbuffer[tailindex++] = c; //now ringbuffer[0] has the byte read from c byte "201"
Serial.println (ringbuffer[tailindex]); //this just prints a 0
Serial.println (ringbuffer[0]); //this prints the correct byte "201"
ringbuffer[tailindex++] = c; //now ringbuffer[0] has the byte read from c byte "201"
Serial.println (ringbuffer[tailindex - 1]); //maybe this can work?
Thanks for your help, I will try it out when I get my hands back on my hardware.
ringbuffer[tailindex++] = c; //now ringbuffer[0] has the byte read from c byte "201"
Serial.println (ringbuffer[tailindex - 1]); //maybe this can work?
ringbuffer[tailindex] = c; //now ringbuffer[0] has the byte read from c byte "201"
Serial.println (ringbuffer[tailindex]); //Trying this too,
tailindex++; //Trying this too, your awesome me not so much
ring buffers of size 256 are particularly easy to fill/empty IFF the index is uint8_t.
if index is NOT uint8_t , or the buffer is NOT size 256, you have do more work; it might be a LOT more, percentagewise, but it's still 'not very much'.
I'm curious why you are passing something that is not a string to a function that expects a string, but still expecting the function to operate properly.
How can you expect to make ringbuffer into a string?
Why the hell aren't you using camelCase for your names?
and what happens when tailindex = the last element of the array? I don't understand "trying" some code. When you put code in a sketch, you put it there because you know what t is going to do.