Pasted in code from Arduino forum

Code made to calculate free memory. Code imported from Arduino Forum.