Please help me understand variables
Oldbitcollector (Jeff)
Posts: 8,091
Ok, I'm made some headway in spin in the last couple days working with various objects.
Could someone explain how one can grab keyboard data from 'comboKeyboard' or 'FullDuplexSerial' or even 'fsrw' and
drop it into memory for usage in other places. I just can't seem to get my brain around this concept! Perhaps
because my experience in programming has been various BASICs and Perl. (Two places that have variables)
and spin doesn't support this. (Perhaps a good object for something like this could be created, *or I really don't get it)
in 'comboKeyboard' using 'key.key' I can wait for a keystroke and that keystoke is assigned to a variable? am I wrong?
PRI terminal | local,name
repeat
local := key.key
if local <> 0
name := name + local ' <-- Why can't I simply add them into local to save a line of text?
text.out(local)
I can write the keystroke back to the screen, remote, SD. What would I do to fill 'local' with all the keystrokes
and display them later as 'text.out(local)?
If someone who understands either of the languages I mentioned could explain a solution in comparison, I'd really
be grateful. I'd really like to get my mind around this concept.
Thanks!
Oldbit
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.
— Calvin, of 'Calvin and Hobbes.
Post Edited (Oldbitcollector) : 9/18/2007 4:08:44 AM GMT
Could someone explain how one can grab keyboard data from 'comboKeyboard' or 'FullDuplexSerial' or even 'fsrw' and
drop it into memory for usage in other places. I just can't seem to get my brain around this concept! Perhaps
because my experience in programming has been various BASICs and Perl. (Two places that have variables)
and spin doesn't support this. (Perhaps a good object for something like this could be created, *or I really don't get it)
in 'comboKeyboard' using 'key.key' I can wait for a keystroke and that keystoke is assigned to a variable? am I wrong?
PRI terminal | local,name
repeat
local := key.key
if local <> 0
name := name + local ' <-- Why can't I simply add them into local to save a line of text?
text.out(local)
I can write the keystroke back to the screen, remote, SD. What would I do to fill 'local' with all the keystrokes
and display them later as 'text.out(local)?
If someone who understands either of the languages I mentioned could explain a solution in comparison, I'd really
be grateful. I'd really like to get my mind around this concept.
Thanks!
Oldbit
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.
— Calvin, of 'Calvin and Hobbes.
Post Edited (Oldbitcollector) : 9/18/2007 4:08:44 AM GMT
Comments
I don't know if I understand good your question... but...did you see the "Keyboard Buffer Demo.spin" ??
It saves the keystrokes into a buffer....you can do it as long as you want...or simply pass the data to another buffer, for save all keystrokes on it ...
Why not that ??
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
Oldbitcollector
Is my confusion on this because I am working with numbers in actuality?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.
— Calvin, of 'Calvin and Hobbes.
I can't remember the thread where I downloaded it ...but seems to be a demo from Parallax.
I've attached the files here..
I'm working with "numbers" too, in this momment...and I used and modified this code.
Good Luck !!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Regards.
Alberto.
Glancing at that Buffer demo it looks like I'm heading in the right direction.
I think I'm starting to get it. Now if I can figure out why this works. [noparse]:)[/noparse]
Oldbitcollector
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.
— Calvin, of 'Calvin and Hobbes.
if local <> 0
name := name + local ' <-- Why can't I simply add them into local to save a line of text?
text.out(local)
Local gets an·ascii character value. Then you begin a sum of these characters. Name isn't a string, it is a sum. To get a string you need to build an array of saved character values.
Post Edited (Fred Hawkins) : 9/18/2007 10:06:46 AM GMT
I'm working on some spin code to create a type of BASIC 'INPUT' command.
I've got a funky problem with removing the last character from the @data block.
I take it that "byte[noparse][[/noparse]data--] := 0" is not ideal? It seems to work only part of the time
when used in my backspace routine.
Oldbitcollector
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.
— Calvin, of 'Calvin and Hobbes.
tline is the input buffer and linelen is the number of bytes in the buffer. tp is a pointer to the start of the input text. The rest should be pretty obvious.
Here's where I'm at so far.. The routine is reasonable, but not quite perfect. [noparse]:)[/noparse]
I'm using 'key.key' so I can implement FullDuplex later.
Do you see any obvious mistakes?
Oldbitcollector
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Buttons . . . check. Dials . . . check. Switches . . . check. Little colored lights . . . check.
— Calvin, of 'Calvin and Hobbes.
(a) You can use "ELSE" (or "ELSEIF") or even a CASE-construction so you can avoid the clumsy "keystroke :=0"
(b) Usinga "repellent" loop is not always the best construction, SPIN has a "break" and a "continue" for reasons only known to it's inventors called QUIT and NEXT. This can sometimes improve readability:
Post Edited (deSilva) : 9/18/2007 6:24:02 AM GMT