Shop OBEX P1 Docs P2 Docs Learn Events
Combining variables into a string? — Parallax Forums

Combining variables into a string?

pcrobotpcrobot Posts: 103
edited 2006-05-17 04:15 in BASIC Stamp
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

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-06 21:58
    If you wrote a string to the EEPROM it would consist of the individual bytes as well.· Are you perhaps referring to converting a numeric value to an ASCII string?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-05-08 12:05
    Instead of writing 4 variables individually, I'd like to combine them together.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-08 12:58
    pcrobot -

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-05-08 14:37
    Okay, one of us isn't understanding the other, so I will put it to you this way...If your strings are numeric you can comine numbers into a single byte/location but you would be limited to a number no higher than 255.· The same can be said with 2 bytes (one word) which you would be limited to 65535 as the highest value.· I hope this more adequately explains the limitations of "combining" the variables.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • pcrobotpcrobot Posts: 103
    edited 2006-05-09 23:12
    I have four separate, 2 digit variables that I need to store at one time. But, as these variables change, I'd like to save them again, but I only write over them. So, I'd like to combine them... or how do I save the above mentioned variables multiple times?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-10 00:59
    pcrobot -

    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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-10 02:23
    Just a note on the formatters:

    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
  • Robert KubichekRobert Kubichek Posts: 343
    edited 2006-05-10 05:04
    Bruce Bates said...
    pcrobot -



    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 smile.gif



    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.




    Gee, I thought it was your pinkies that are used for counting ... smilewinkgrin.gif

    Bob scool.gif
  • pcrobotpcrobot Posts: 103
    edited 2006-05-10 15:56
    OK, thanks Bruce..

    Here is my code:
    IF IN3 = 0 THEN
            WRITE eepromAddress, month
            WRITE eepromAddress + 1, day
            WRITE eepromAddress + 2, hour
            WRITE eepromAddress + 3, minute
    


    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.
  • SSteveSSteve Posts: 808
    edited 2006-05-10 16:10
    pcrobot said...
    when I want to record all the varibles again, it just writes over the previous variables. How do I save them again?
    I'm not sure what you mean by "How do I save them again?". Are you saying you don't want to write over the previous variables so that you can have access to multiple versions of past data? If so, you need to increment the write address each time you write the variables. Something like this:
    IF IN3 = 0 THEN
            WRITE eepromAddress + addrOffset, month
            WRITE eepromAddress + addrOffset + 1, day
            WRITE eepromAddress + addrOffset + 2, hour
            WRITE eepromAddress + addrOffset + 3, minute
            addrOffset = addrOffset + 4
    


    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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-05-10 16:29
    If you're using PBASIC 2.5 syntax you can do this:

    · 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
  • pcrobotpcrobot Posts: 103
    edited 2006-05-17 02:36
    Jon Williams (Parallax) said...
    READ eeAddr + eeOffset, month, day, hour, minute
    eeOffset = eeOffset + 4
    Now, how would I debug that? confused.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Robotics
    ro-bot-ics (noun)
    the science or technology of robots, their design, manufacture, application, use, etc.
  • SSteveSSteve Posts: 808
    edited 2006-05-17 04:15
    The results are exactly the same as the code I posted, so you'd debug it in exactly the same way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows
Sign In or Register to comment.