Combining variables into a string?
pcrobot
Posts: 103
Hey,
Is there a way to combine multiple variables (4, in my case) into a string? I want to write the string to the EEPROM, instead of multiple variables.
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.
Post Edited (pcrobot) : 5/6/2006 11:26:34 AM GMT
Is there a way to combine multiple variables (4, in my case) into a string? I want to write the string to the EEPROM, instead of multiple variables.
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.
Post Edited (pcrobot) : 5/6/2006 11:26:34 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.
The following question presumes that the four variables of which you speak are all the same size. If they are not, then please just skip this message.
In what way would you be combining them, such that they would end up being anything but 4 contiguous (byte size) locations or 8 contiguous (word size) locations in EEPROM? In other words, what do you hope to gain by this proposed "combining"?
By their very nature, most EEPROMs are byte oriented devices. Additionally, PBASIC has no specific commands for string manipulation, although much can be done with math routines, depending on the contents of the data fields.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.
FLASH, FLASH, I think the lights just went on (here) as to what you're trying to do, and·I think I can show you why it·really isn't necessary. I suspect there may be a misunderstanding going on here in terminology. See if this short "lesson" doesn't straighten it out. If not, I'm game to keep on going :-)
Let's get back to basics for a moment:
Definitions (mostly mine) -
digit -
a : any of the Arabic numerals 1 to 9 and usually the symbol 0, which are part of the decimal (base 10) number system.
b : one of the elements that combine to form numbers in a system other than the decimal system. Eg. A-F in the hexadecimal (base 16) number system.
c: one significant element (of a possibly larger group) intended to be unique and identifiable, which may or may not be positionally weighted by value.
number -
a: a symbol or digit which represents a quantitative value in a particular set of mathematical elements upon which arithmetic operations can be applied.
b: one or more symbols or digits as noted above.
byte -
a : The smallest unit of computer memory which can be uniquely addressed.
b : An 8-bit field, used in computers, which can attain or be assigned any·value from 0-255 (decimal), ·0-FF (hexadecimal) or 0-7F (octal). Thus, one byte can contain up to 3 digits, but can never be assigned a numeric value greater than 255 (decimal).
bit -
a : The smallest unit of computer memory which can be manipulated, but which can not be individually addressed.
b : one of the eight digits, having a value of·0 or 1,·which comprise a BYTE.
(Note: I have no intention of "defending" these definitions, as they are specific·purpose oriented)
- - - - -
Although asynchronous serial data transmission is BYTE oriented, it is NOT DIGIT oriented. Since it·_is_ BYTE oriented, it is also value-limited by definition (see BYTE definition above). Thus, any given BYTE within that data stream, may have a one, two or three digit number (value) within that ONE BYTE (0-255). Since this is so, and since SERIN (PBASIC command to read or access asynchronous serial data) needs to be "smart" about what it's reading, formatters are available to further define the data input in terms of DIGITS.
Here are some of those formatters:
DEC1 or just DEC ==> Selects ONLY one digit from the serial data stream.
DEC2 ==> Selects two digits from the incoming serial data stream.
DEC3 ==> Selects·three digits from the incoming serial data stream.
etc.
For additional information, and other formatters, please see the PBASIC Manual, or the PBASIC Help File under SERIN or SEROUT and look near the end of those sections where·formatters are discussed.
I hope the thought of "combining" becomes unnecessary at this point. Data compression (as opposed to "combining") is an entirely different subject which will not be covered here.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Post Edited (Bruce Bates) : 5/10/2006 5:30:03 AM GMT
DEC will print as many characters as required by the value -- output is unsigned (use SDEC for signed output)
DEC1, DEC2, DEC3, DEC4, and DEC5 (no space between "DEC" and digit) will print a specific number of characters, zero-padding if necessary, or truncating higher digits.
For example:
· value = 123
· DEBUG DEC value
Output is: 123
· value = 12
· DEBUG DEC4 value
Output is: 0012.
· value = 1234
· DEBUG DEC2 value
Output is: 34
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Gee, I thought it was your pinkies that are used for counting ...
Bob
Here is my code:
Now, what I can't figure out is... when I want to record all the varibles again, it just writes over the previous variables. How do I save them again? (This was the problem I was trying to avoid by combing the variables...)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.
If you do it this way, you'll need to be careful that addrOffset doesn't become large enough to write into the area where your program is stored. For example, if you need access to just the last 10 sets of data, the last line could be changed to "addrOffset = addrOffset + 4 // 40"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
· WRITE eeAddr + eeOffset, month, day, hour, minute
· eeOffset = eeOffset + 4
It doesn't really save on compiled code, but it does shorten your source and prevent possible errors.· Of course, you can read back the same way:
· READ eeAddr + eeOffset, month, day, hour, minute
· eeOffset = eeOffset + 4
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Robotics
ro-bot-ics (noun)
the science or technology of robots, their design, manufacture, application, use, etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows