Shop OBEX P1 Docs P2 Docs Learn Events
Sending numbers — Parallax Forums

Sending numbers

charleyshfcharleyshf Posts: 165
edited 2011-10-27 09:52 in Propeller 1
Hello,,

The code I am working on is the following:
PUB testing
    a := 0         '0-9                                                     
    b := 60       '0-255
    c := 255     '0-255
    d := 255     '0-255'
    e := 120     '0-255
    f := 120      '0-255
    g := 255     '0-255
    
    outdata[0] := a 
    outdata[1] := b 
    outdata[2] := c 
    outdata[3] := d 
    outdata[4] := e 
    outdata[5] := f 
    outdata[6] := g 
    
     repeat i from 0 to 7(outdata)
        PST.Dec(outdata[i])

This 'kind of ' works, however I was expecting the result of 060255255120120255 and instead I get an extra 0 at the end "0602552551201202550" . I could send each value one at a time with PST.Dec , but I would think there is a better way to do this, I am also using the PST object to display my results. Any ideas what I am doing wrong?

Comments

  • RavenkallenRavenkallen Posts: 1,057
    edited 2011-10-26 06:51
    You are sending a extra character it seems like. Try cutting the repeat line a little...

    Repeat i from 0 to 6(Outdata)

    See if that helps:)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-26 07:23
    Ravenkallen is correct.

    You're sending an extra value to the PST. Your data is from 0 to 6 but your sending 0 to 7. I assume outdata[7] is either zero or undefined.

    I don't understand "repeat i from 0 to 7(outdata)".

    Are you missing a comment before "(outdata)"?

    Duane
  • charleyshfcharleyshf Posts: 165
    edited 2011-10-26 10:54
    Sorry, the line that reads repeat i from 0 to 7(outdata) should read repeat i from 0 to 7. Changing the 7 to 6 did the trick, can't believe I missed that one, Thank You!
  • charleyshfcharleyshf Posts: 165
    edited 2011-10-26 12:48
    I ran into another problem, with the correction from above I get the proper responce, however I need the format of "0000000000000000000" , in other words if I want to send 90 in part of that, I need to actually send 090, it seems simple enough, but I am having a hard time trying to understand this, maybe I have to convert the responce to a string?

    Thanks again
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-10-26 12:59
    I couldn't find a simple example of zero padding so I wrote the code below.

    I think this should work (I haven't tested it).
    PUB Main |  localIndex 
    
      repeat localIndex from 0 to 999
        if localIndex < 100
          pst.dec(0) ' was ("0")
        if localIndex < 10
          pst.dec(0) ' was ("0")
        pst.dec(localIndex)
    
    

    This should output a thee digit number with leading zeros when needed.

    Duane

    Edit: charleyshf's post made me realize I was using the dec method incorrectly. I fixed (I think) the code above.
  • charleyshfcharleyshf Posts: 165
    edited 2011-10-27 09:52
    Thanks again,

    Your example made me think about what I wanted the prop to do and this is working for me:
    repeat y from 1 to 6
       If outdata[y] < 100
       SERIAL.Dec(0)
       If outdata[y] < 10
      SERIAL.Dec(0)
      SERIAL.Dec(outdata[y])
    
Sign In or Register to comment.