i did some test regarding the available memory. here's my code below
#include <math.h>
void setup()
{
Serial.begin(9600); // set up Serial library at 9600 bps
int b;
b=availableMemory();
Serial.println(b,DEC);
}
void loop()
{
}
// this function will return the number of bytes currently free in RAM
int availableMemory()
{
int size = 1024;
byte *buf;
while ((buf = (byte *) malloc(--size)) == NULL)
;
free(buf);
return size;
}
output is 828
i was wondering what was used to wipe off so many bytes since there is no floating point calculation?
i have another question:let say i have a function (say it takes up 200bytes)with full of floating point calculations in it.And i need to call it quite frequently to update some other functions.will the function use up the 1k sram eventually as it was being called ?
1)is it the right way to clear the 2 bytes by calling Serial.read() for 2 times?please refers to my code PosSend() function.
No. You call Serial.read() occurs well before the motor has had a chance to response to the call to SendOperCommand. Why do you need to clear this buffer anyway? You don't appear to using RX serial anywhere.
2)why i couldn't see the rx led blings or it's too fast for a naked eye?
115 thousand times per second = way too fast!
3)how to optimize my code as the dynamic ram only left 50bytes?
You actually have 818 bytes free. The problem is that you are assigning the int return from availablememory() into a char variable.