This seems like a very simple question, however I am having some trouble with it.
I wish to write a 2 byte value (unsigned short) to an SD card, and then read that same 2 byte value later on.
Saving and reading to the SD card all works fine, however I can only find how to read and write 1 byte at a time, using the basic functions such as file.read(), file.write().
Sorry I should have been more specific, I do understand how to read 2 bytes and join them together, however I can only seem to write into the file as ascii.
For example, if I wanted to write in the file the number 425, file.print() writes it in as the seperate digits '4', '2', and '5'.
Is there any way to write into the file as a complete number? Or prehaps combine the seperate digits '4', '2' and '5' into a complete number again?
You could either store the value as ASCII on the SD card and convert it back using atoi(), or you can use the .write() function to write individual bytes.
You can separate bytes out, and recombine them, by using simple boolean algebra - AND (&), OR (|), left shift (<<) and right shift (>>).
For example, to turn a 16-bit integer into two 8-bit bytes:
int in = 3769;
byte b1,b2;
b1 = in >> 8;
b2 = in & 8;