Shop OBEX P1 Docs P2 Docs Learn Events
Really dumb question involving character arrays — Parallax Forums

Really dumb question involving character arrays

firestorm.v1firestorm.v1 Posts: 94
edited 2006-03-31 21:43 in BASIC Stamp
I'm really embarassed to be asking, but I haven't been able to find a solution on this. I'm working with an array as shown trying to extract the characters and convert them into numbers. The array is not populated like this in the program but is read from SERIN to the inputArray array. I can read, and DEBUG the results, but DEBUG DEC inputArray(4) shows the ASCII code for the character "2" not the value 2.

inputArray(3)="1"
inputArray(4)="2"
inputArray(5)="0"
inputArray(6)="3"

How do I convert "1" into the digit 1 so I can do some variable testing with it? Right now if I try to show it, it returns the ASCII code for it. I am needing to do this for several elements on this array but if I can get this one down, the others will fall into place.

Thank you for your help, a schematic and code will be posted once the display is complete. [noparse]:)[/noparse]

Matt

P.S. I managed to figure out how to use the serial port You can use pin 16 for the DEBUG port for serial communications. My application uses SEROUT 16,16468,[noparse][[/noparse]"X1"] in order to send "X1" out the serial port on the BS2 homework board at 9600,n,8,1

Comments

  • JonathanJonathan Posts: 1,023
    edited 2006-03-30 15:56
    Matt,

    Remove the quotes, like this:


    inputArray(4) = 2

    The quotes tell the editor to view whatever is inside as ASCII.

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2006-03-30 16:08
    Another way to do it (with numerals) is to subract 48 (the ascii value of "0")

    DEBUG DEC InputArray(4)-48

    Another way is to use SERIN to do the conversion

    SERIN ,,,[noparse][[/noparse]DEC1 inputArray(0),DEC1 inputArray(1),...]
    but that would work only at slower baud rates.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2006-03-30 16:30
    Thank you both. The array isn't being defined like the example I provided but is being automatically populated by SERIN. I forgot about subtracting 48 from the ASCII value stored in the array, That helps immensely. I hope I can get this done now.

    Refresh my memory, but you can store a single character in a Byte, correct?
  • Tom WalkerTom Walker Posts: 509
    edited 2006-03-30 16:31
    In addition to Tracy's way, you can subtract the CHARACTER "0"

    intValue = InputArray(4) - "0"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-30 16:49
    Note also, when you say "DEBUG DEC inputArray(4)", the DEC modifier says to take the value in inputArray(4) and output a string version of it, AS a Decimal number.

    So MyVal = "2" puts the ascii value of "2" (42?) in MyVal

    DEBUG DEC MyVal takes that 42, and outputs it as "42".

    DEBUG MyVal would output "2".
  • firestorm.v1firestorm.v1 Posts: 94
    edited 2006-03-31 21:43
    I got it working! My project is now on the projects page: http://forums.parallax.com/forums/default.aspx?f=21&m=118073

    Thanks for all your help, I couldn't have done it without it.
Sign In or Register to comment.