View Full Version : Writing Decimal Values to SD
11-03-2011, 04:20 PM
Is is possible to write a decimal value directly to an SD card using Kwabena W. Agyeman SD card driver? I have tried sdfat.writebyte(count), where count has bee assigned a value. A character instead of the number is been stored.
11-03-2011, 04:31 PM
My first guess is that instead of writing the actual number, it is dumping it as an ASCII code, thus displaying the character instead of the number. Have you tried:
11-03-2011, 04:33 PM
.writebyte is doing exactly what it's supposed to do. Some of the other SD card objects have a routine (.dec) that takes a value and converts it to an ASCII decimal string, then outputs it to the SD card a character at a time. Here's one such routine that you can use:
pub writeDec(value) | i ' Output a decimal value
if value < 0
i := 1_000_000_000
if value => i
sdfat.writebyte(value / i + "0")
value //= i
elseif result or i == 1
i /= 10
The example code comes with a rountine that writes decimal and hexadecimal values also.
11-04-2011, 09:54 AM
Thank you for sample code works brilliant.
Is it possible to check if a file exists before opening??
No need. Please read up on the documentation here: http://www.parallaxsemiconductor.com/an006
You can just open the file. Catch the error string and check the error code. If the error code is that the file does not exist then you know it does not exist.