shifting values in array
to update graph, need shift values in whole array 1 position left before adding new value end of array. following code me:
for(int i=1; i<width; i++) {
xvals[i-1] = xvals;
}
but array quite long, seems quite inefficient way of doing this, since requires lot of clock cycles complete. there way shift values in array more efficiently?
for(int i=1; i<width; i++) {
xvals[i-1] = xvals;
}
but array quite long, seems quite inefficient way of doing this, since requires lot of clock cycles complete. there way shift values in array more efficiently?
try:
the memcpy() function implement best possible under limitations of platform, it's doing same thing.
on fancier microprocessors, there special memory moving instructions , dedicated buses take care of these things @ speed of memory hardware. not microcontrollers.
note if you're "scrolling" array right, need count-down loop instead of count-up loop. otherwise, each copy overwriting next copy done. the memcpy() routine should internally check 1 necessary.
code: [select]
void memcpy(void* target, const void* source, size_t length);
// ...
memcpy(&xvals[0], &xvals[1], (width-1)*sizeof(*xvals));the memcpy() function implement best possible under limitations of platform, it's doing same thing.
on fancier microprocessors, there special memory moving instructions , dedicated buses take care of these things @ speed of memory hardware. not microcontrollers.
note if you're "scrolling" array right, need count-down loop instead of count-up loop. otherwise, each copy overwriting next copy done. the memcpy() routine should internally check 1 necessary.
code: [select]
memcpy(&xvals[1], &xvals[0], (width-1)*sizeof(*xvals));
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > shifting values in array
arduino
Comments
Post a Comment