Shop OBEX P1 Docs P2 Docs Learn Events
Problem with my repeat array — Parallax Forums

Problem with my repeat array

grasshoppergrasshopper Posts: 438
edited 2008-03-10 21:17 in Propeller 1
I am trying to display the correct data using this array

{{ Demo LCD
  Uses LCDDEMO Version 1.2

}}

con
  esc = $1B       'Escape code
  cr = $0D        'Carriage Return code                 
  lf = $0A        'Line Feed code
  eos = $FF       'End of string code
  eog = $FF       'End of graphics code
  space = $20     'Space character code
  
obj
  LCD : "LCDDEMO"
  
pub main | x, Y[noparse][[/noparse] 10 ], index      'Memory

                                '$ = hex 30to39 = 0to9
                                
  Y := $30                      'Y is = to 0 for starting point
  index := $0                   'Index array starting at 0
  
  LCD.init                      'Initialize Display
  LCD.CLS                       ' Clear Display
  
  repeat x from $30 to $39      'Repeat from 0 to 9                       
    LCD.writeout(Y[noparse][[/noparse] index ])      'Write to display 
    index := index + $31        'increment one
    waitcnt(1_000_000 + cnt)    'Pause     




I am getting incorrect characters on the display. I think that the data is lost some how.

Basically i wanted to show the numbers 0 - 9 in decimal or hex.

Comments

  • Nick MuellerNick Mueller Posts: 815
    edited 2008-03-10 16:17
    > index := index + $31 'increment one

    You have to correct the comment! smile.gif

    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-10 16:26
    Some more tips:

    -When you mean "0" or "1" just write "0" or "1" and not such obfuscating things as $30 or $31. Who told you that?? It will make you very unhappy!

    - When you introduce a REPEAT variable as x here: USE IT. There are some languages and very few applications where it makes sense not to use it, but not with SPIN. It shows bad thinking when not using it.
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-10 16:50
    Ok first off, forgive me if I am insulting any of you. I am new YES this is obvious...

    Now my new code is as it was as before only fixed using your advice. Behold; I still get errors on the LCD

    
    PUB main | X, Y[noparse][[/noparse] 11 ], index     
                               
    Y := 0                        'Y is = to 0 for starting point
    index := 0                    'Index array starting at 0
    X := 0
      
    LCD.init                      'Initialize Display
    LCD.CLS                       'Clear Display
        
    repeat x from 0 to 9          'Repeat from 0 to 9                       
        LCD.writeout(Y[noparse][[/noparse] index ])      'Write to display 
        index := X
        waitcnt(1_000_000 + cnt)    'Pause     
    
    
    
    



    As you can see deSilva I have employed the X in my repeat as best as i can imagine
    I wrote it in hex in my first example; thinking that If it were in HEX to begin with then I could get HEX in the end. Not the case...

    Any advice would be absorbed and if permitted applauded feverously tongue.gif
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 16:59
    Where in your program do you put anything into the array Y? Why do you have "index := X" after the use of "index"?
    I still don't understand what you are trying to do. I think you need to address that before you try to write code that doesn't work ...
    In other words, clearly state the function of your program in sufficient detail so that someone else could write the program from
    just that description. Usually that clears up many misunderstandings and allows you to understand your own needs enough so that
    you can write the program successfully yourself.
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-10 17:05
    @Grasshopper: You have 82 postings; you already tried many programs: You shouldn't be a beginner any longer...

    Al right, lets start with your code....

    (A) It seems you want to output some elements of the vector Y.... But there is nothing in Y ! You defined it with a length of 11 elements, set the first to 0 and the rest is undefined!

    (B) When I said "0" I had "0" in mind, not 0. It must be obvious to you that $30 cannot be 0...

    (C) INDEX := X makes it more confusing.. Why do you use X and why do you use INDEX? or both? or none?
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-10 17:56
    Well let me back up some. My biggest problem to date is strings and data types. My main goal this week is to take a variable that changes depending on user input and display it on an LCD screen. For example:

    Any number from 0 – 1000 imputed, and then displayed it in base 10. This is difficult to me because the data so far has to, either be in a library that I must look up i.e. can not change (the variable), or the data has to be manipulated some how using a repeat statement, dividing or somme other fashion.

    So far no one has sparked an OH (expletive) moment for me. DeSilva you have help as well as Mike Green and my long over due book from parallax that will be here tomorrow. So please keep plugging the info at me.

    So in my original code I wanted to count from 0 – 9 and display it in base 10 on an 2x20 LCD. Better yet some one show me how to display a string like "329Abc" or "234" on the LCD screen. Using the LCDDEMO object.

    I am having no such luck because of my lack of knowledge on strings or data types.
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-10 18:10
    How does this code work? I writes 0 - 9 on the LCD but i am not sure why ?

    pub main | x , Z
    
                                    '$ = hex 30to39 = 0to9
      z := 1
    
      LCD.init                      'Initialize Display
      LCD.CLS                       ' Clear Display
      
      repeat x from 0 to 9          'Repeat from 0 to 9                       
        LCD.writeout((Z + 47) + X)          'Write to display
        'waitcnt(1_000_000 + cnt)    'Pause
    
    
    



    Edited or this

    pub main | x , Z
    
                                    '$ = hex 30to39 = 0to9
      z := 48
    
      LCD.init                      'Initialize Display
      LCD.CLS                       ' Clear Display
      
      repeat x from 0 to 9          'Repeat from 0 to 9                       
        LCD.writeout(Z + X)          'Write to display
        'waitcnt(1_000_000 + cnt)    'Pause
    
    



    Why 48 ?? this is 2F hex right ?

    Post Edited (grasshopper) : 3/10/2008 6:15:51 PM GMT
  • hippyhippy Posts: 1,981
    edited 2008-03-10 18:15
    - z := 1
    - repeat x from 0 to 9 'Repeat from 0 to 9
    --- LCD.writeout((Z + 47) + X)

    Bizarre.

    Z + 47 = 1 + 47 = 48 = $30 = "0"

    Ultimately you are therefore sending the ascii characters "0" to "9" but that must be the most convoluted way I've ever seen.

    - repeat x from 0 to 9
    --- LCD.writeout( x + "0" )

    or

    - repeat x from "0" to "9"
    --- LCD.writeout( x )
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-10 18:21
    Dam i am so stupid today!
    I figured it out - Beats head on desk!!!

    Still i need help on strings any ideas ?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 18:39
    I suggest you look at the FullDuplexSerial object that comes with the Propeller Tool. It includes some output formatting routines for decimal, hexadecimal, and binary outputs and for displaying a literal string or a zero-terminated string in a byte array. The only part of these routines that's dependent on the use of serial I/O is the call on a "output this character to the display and move to the next position" routine and it's easy to substitute any other similar routine, like for an LCD display.
  • grasshoppergrasshopper Posts: 438
    edited 2008-03-10 19:10
    *mike green this is exzactly what I am after but ill need more clarity.

    Do I need to redesign the LCDDEMO object with the particulars contained in the FullDuplexSerial object? [noparse][[/noparse]copy and paste; assign variables, etc]
    Or do I use the FullDuplexObject combined with the LCDDEMO object? "Have no idea how this would work..."



    PLEASE LET ME KNOW I THINK THIS IS THE OH (expletive) MOMENT !!!
  • hippyhippy Posts: 1,981
    edited 2008-03-10 19:30
    Strings are just sequences of bytes, and when of variable length terminated by a byte of value zero. An array is an obvious way to hold strings but they may also be held as bytes somewhere in RAM ( or ROM ) with a pointer to them. Such a pointer can also point to the start of an array.

    String manipulation is really just using and altering the data stored in those arrays or where the pointer points to in memory.

    Your needing "help on strings" is a bit too vague for me to answer usefully; it's a bit like asking "how do I use numbers" I'm afraid.

    Added : There is a section on the Propeller Wiki which might be of some help ...

    propeller.wikispaces.com/Strings

    Post Edited (hippy) : 3/10/2008 8:15:50 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-10 20:21
    Strings are - similar to what Hippy described - a "concept", a "logical datatype". They are very similar to "real numbers". The language SPIN has very limited insight in both, in fact a lot more in reals than in strings smile.gif

    The first thing to understand is that there is no string denotation in SPIN. "abc" can be anything BUT NOT A STRING. You can use it as a building block to generata a string in DAT or using the string(..) directive.

    The second thing you have to understand is that there are exactly two functions in SPIN than work on strings: STRSIZE and STRCOMP, nothing more.

    The rest must be done by yourself - everything. This is not strictly for the beginner!

    There are of course very well known BASIC OPERATIONS and this is something Hippy can easily code for you -)

    (a) Concatenating two strings
    (b) Removing characters from position n to m from a string
    (c) Determining the position in a string where a given substring starts
    (d) Making all characters upper case (or lower case)
    (e) Coverting a sequence of digits to its binary value
    (f) Inserting a string at position n into another string

    ---
    Edit: It might also help to look into Phil Pilgrims SPIN[noparse]:D[/noparse]EMO
    http://forums.parallax.com/showthread.php?p=587930

    Post Edited (deSilva) : 3/10/2008 9:51:57 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-10 21:17
    grasshopper,
    You use the routines in FullDuplexSerial as a model for your own. You can cut and paste them and modify them to suit your circumstances. The routines in FullDuplexSerial are written to send their output (characters) to a serial port and that can only be changed by modifying the routines.

    There is also an object in the Object Exchange called Extended_FullDuplexSerial which is a collection of input formatters that use the FullDuplexReceive routines to receive a string, then convert the sequence of characters into a number which they return. These are also useful models for other input devices (like keyboards).
Sign In or Register to comment.