Help with strings
joeld
Posts: 49
I've been reading the Prop manual and am kind of stumped on the correct way to implement a string function in Spin. I'm new at Spin and haven't programmed much recently so as simple as this may sound I still need some help.
I am taking a floating point value (temp from sensirion), using the FloatToFormat command out of the Float object to convert the number into a string of fixed length.·My goal is to write a method that will take the string length and variable as inputs and output characters one at a time to a uOLED display. I was thinking a conditional loop that would run the number of iteration as characters in the screen. I'm not finding much info on working with strings in the prop manual. I see how to get the starting address. Can I somehow reference the following addresses somewhat like an array?
Any help getting pointed in the right direction would be appreciated.
I am taking a floating point value (temp from sensirion), using the FloatToFormat command out of the Float object to convert the number into a string of fixed length.·My goal is to write a method that will take the string length and variable as inputs and output characters one at a time to a uOLED display. I was thinking a conditional loop that would run the number of iteration as characters in the screen. I'm not finding much info on working with strings in the prop manual. I see how to get the starting address. Can I somehow reference the following addresses somewhat like an array?
Any help getting pointed in the right direction would be appreciated.
Comments
PUB displayString(row, col, length, s) : Index
repeat Index from 0 to length -1
oled.putChar(byte[noparse][[/noparse]@s][noparse][[/noparse]Index++],col,row,1, 255,255,255)
col++
This method is passed the starting row, col, string length and string (s). Right now it's just writing jibberish to the screen. I'm assuming now I will have to find a way to convert that byte to the ascii number for the char I want displayed. I'll have to spend some thought on that. Am I off base or at least starting down the right path?
However "s" IS THE ADDRESS of the string, so adding @ before it in this routine is "doppelt gemoppelt" as we say in German
As you are using a "for"-loop INDEX is incremented automatically, so incrementing it between the brackets is again "doppelt gemoppelt"
You can also avoid a further "doppel moppel" by callint StrSize, that will determine the length of the string , so you need not pass it as a parameter.
Last... well, it is possible to use the return value as variable (especially when you want to use the fact that it is zero preset), but it is cleaner to declare a local variable after the | symbol...
Post Edited (deSilva) : 2/19/2008 11:24:01 PM GMT
The loop issue explains why I was only getting half the number of characters. I'm still getting jibberish on the screen. I think it's probably the way I'm assigning the value to the varaible before I pass it to the method. Time to study some more then maybe I can ask a more intelligent question. I think I'm getting close. I don't have any other display to hook up for debugging where I'm at, so I'm not totaly sure the SHT1x is putting out good info either. I thought I might just work with a constant till I get the display method working.
Note that I do not consider it helpful to talk of "arrays" or "strings" when using SPIN. SPIN does not know of such "data structures". You are always on your own with the most basic referencing and dereferencing techniquies as in machine code.
PUB displayString(row, col, s) | Index
··· repeat Index from 0 to strSize(s) - 1
····· oled.putChar(byte[noparse][[/noparse]s][noparse][[/noparse]Index],col,row,1, 0,0,255)
····· col++
I finally got the correct statements up in the main method to send the addresses of the formated data. At first I wasn't getting good info out of the sensirion module but I lowered the clock from 16x to 8x and it sprung to life as well. I've tried to attach a picture.
Joel