Shop OBEX P1 Docs P2 Docs Learn Events
Reading a Number from an SD card. — Parallax Forums

Reading a Number from an SD card.

mosquito56mosquito56 Posts: 387
edited 2008-02-21 21:22 in Propeller 1
I have been working on reading a setting from the sdcard. I am assuming that the extended full duplex sends info from lsb to msb. The sd card reads info from msb to lsb or left to right. When using the extended full duplex all the numbers were comming reversed so I wrote a subroutinue to read a value from a file on an SD card. Here it is.
· I only used a file with 12345, on it.
Some variables are from the old extended full duplex and aren't used here. Just to lazy to remove them.

I plan to have a large list of setting the user can set and save on the SD card. This is step 1 of 100



pri getinfo |x,y,r ,sta,bytes ,chrbyte ,bytecnt,chrcnt ,place,value,revalue,curx
· out(0)
· color:=3
· 'printstr(string("Mounting.", 13))·······
· sdfat.mount(0)
· r := sdfat.popen(string("infotoread.txt"), "r") 'opens file to read
· bytecnt:=chrbyte:=0
·· repeat
····· r := sdfat.pgetc··········· 'read bytes and transfer to "byte chr[noparse][[/noparse]30]
····· if r<>"," 'r<>$0D and r<>$0A 'uses "," delimited· OD and OA are linefeed and chariage return
······· chr[noparse][[/noparse]chrbyte]:=r
········ chrbyte++
····· else
·······
······· printstr(@chr) 'print what was read
······· y:=1
······· revalue:=0
········ repeat x from 0 to chrbyte-2 'multiply by number of digits 'gets msb: If number is 897 will store 100
·········· y:=y*10
······
······· repeat x from 0 to chrbyte
········· curx:=x···
········· if (chr[noparse][[/noparse]curx] => ("0")) and (chr[noparse][[/noparse]curx] =< ("9"))
············ 'row++
············ 'dec(chr[noparse][[/noparse]curx])
············ revalue:= revalue + ((chr[noparse][[/noparse]curx]-48)*y)
············ y:=y/10
·······
······· 'whatever:=revalue
······· hobbscheck:=1
·······
····· if r < 0
······· sdfat.pclose
······· quit

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·······

······· "What do you mean, it doesn't have any tubes?"
······· "No such thing as a dumb question" unless it's on the internet
········
Sign In or Register to comment.