Problem with my repeat array
grasshopper
Posts: 438
I am trying to display the correct data using this array
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.
{{ 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
You have to correct the comment!
Nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Never use force, just go for a bigger hammer!
The DIY Digital-Readout for mills, lathes etc.:
YADRO
-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.
Now my new code is as it was as before only fixed using your advice. Behold; I still get errors on the LCD
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
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.
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?
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.
Edited or this
Why 48 ?? this is 2F hex right ?
Post Edited (grasshopper) : 3/10/2008 6:15:51 PM GMT
- 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 )
I figured it out - Beats head on desk!!!
Still i need help on strings any ideas ?
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 !!!
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
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
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).