Keyboard Demo
Newzed
Posts: 2,503
In Keyboard Demo, I changed:
'echo keystrokes in hex
· repeat
··· term.hex(kb.getkey,3)
··· term.out(" ")
to read
'echo keystrokes in ASCII
· repeat
··· term.out(kb.getkey)
Now the TV displays:
"Come visit Port Richey"
Also, in TV Terminal, under DATA/colors, I changed:
long··· $BC_6C_05_02
to
long··· $BC_6C_05_0A
Now the TV background is blue instead of black.
Sid
'echo keystrokes in hex
· repeat
··· term.hex(kb.getkey,3)
··· term.out(" ")
to read
'echo keystrokes in ASCII
· repeat
··· term.out(kb.getkey)
Now the TV displays:
"Come visit Port Richey"
Also, in TV Terminal, under DATA/colors, I changed:
long··· $BC_6C_05_02
to
long··· $BC_6C_05_0A
Now the TV background is blue instead of black.
Sid
Comments
I would like to enter four numbers - for example, 5500 - and have the four numbers become an entity equal to 5500.· Then I want to equate this four-digit value to a variable called "cycle".· I think I can handle the equate part, but how do I enter the four numbers and how do I tell the program I have finished entering digits for this particular entity?· What if I wanted to enter just 550?
Is this even close:
term.getstr(string(ser\5\"*")
I don't think there is a "term.getstr" routine in keyboard.spin
Questions, questions, questions
Sid.
My situation is a little more complicated in that there is a pre-existing 32 bit hexidecimal value that is displayed on the screen (there are 4 such numbers displayed) and keyboard entries are taken and processed accordingly, 0-9, a-f, A-F, the arrows, Tab, Shift-Tab, Enter and Esc must all be handled.
Taking 4 numbers straight up should be a bit easier, just use a case statement to catch the numbers (which would be case "$30..$39:", have a working variable and a place variable, start the place variable at 1000 and the working variable at 0, multiple the place variable by the number entered and add it to the working variable, if the place variable is 1 leave the loop otherwise divide it by 10 and loop. Have Enter be another entry in the case statement where the working variable is divided by 10 times the place variable to achieve the properly shifted final value and leave the loop.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Life is one giant teacup ride.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
That's almost what I have.
I'm working on including functionality to print each digit as it goes and support for the backspace / delete keys.
I'm currently at work otherwise I'd post the code I completed...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
before until theKey == 13
Echoing each digit would add a fair amount of complexity. I'd probably make a separate method for displaying keys and add a call to that method right after theKey := kb.getkey to avoid cluttering up the code that's putting together the value. I can't work on it right now, but I'll be interested to see what you have come up with.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
As soon as I can, I'll post it...
The laptop's batteries are currently dead, and as well as at home and have some time.
Prolly the latter part of the weekend...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
I have attached two files, Frequency Counter Internal and Frequency Counter Internal A, hereafter referred to as Internal and Internal A.
Internal A is your program with some changes in the variable names.
Internal is a program that outputs·a frequency dependent on the "cycle' time.· As you can see near the end of the program, cycle value is entered in the program and then run.
Both programs work perfectly when run independently.
What I would like to do is to merge the two programs so that the cycle value can be entered from the keyboard.· Internal has no keyboard object and I tried several approaches but nothing would work.· I do not understand the PUB configuration very well - that is where my problem is.· I tried copying Internal into Internal A but that didn't work either.
If you have time to help I would appreciate it.
Sid
I merged them into a program that does the following:
1) Accept a "cycle" value from the keyboard
2) Display the entered cycle
3) Start another cog to measure frequency
4) Toggle a pin, wait the given number of cycles, repeat
While the pin is being toggled, the other cog measures and displays the frequency on the input pin. (Of course you'll need to connect the output pin to the input pin.)
Note the simplified toggle routine:
The "!" operator toggles the value to its right.
I didn't add anything to allow entering a different cycle value once the program starts. That's what Reset buttons are for.
I hope this is instructive. Please feel free to ask about anything that's not clear.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
Also, your explanation of the "· !· " operator helped me solve a problem with another program.
One question -· how come you could do it with one cog when the original program had two cogs?
You wrote:· PRI MeasureFrequency | Frequency
I noticed frequency was not defined in VAR.· Does your PRI statement declare frequency as a local variable?··If I wrote:
PRI MeasureFrequency
and defined "frequency" in VAR, would it still work?
Does the "· |· " operator declare one or more variables?· Could I write
PRI MeasureFrequency |frequency, period
and then write:· Period == 1/frequency*1_000_000 to express the period in us?
Thanks again.
Sid
·
dan
I believe that once those two cogs are launched, the cog running Start shuts down. In my code, there are still two cogs running. One is executing these lines at the end of the Start method:
and one is executing MeasureFrequency. The original example could have done the same thing like this:
The only difference being that instead of launching a new cog to run MeasureFrequency it would run it in the cog running Start. (I hope that makes sense. I'm pressed for time so I have to be short.) Exactly. Yes. The difference would be that frequency in that case would be global to every method in the object. A change to frequency in any method would be seen by all, as happens with cycle. If you define a variable as a local variable, only that method would see it and if you launched multiple copies of the method in different cogs, each would have its own instance of the variable. So there's no right or wrong, it's a matter of what you need in your application. There are some situations (like this one) where either works. Yes. Except you'd use ":=", not "==". ":=" is the assignment operator and "==" is the comparison operator.
I have to run. Let me know if I've raised more questions than I answered.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
repeat
···· WaitCNT( clkfreq + CNT )
··· until kb.getkey···········
··· start
If load the program· I get a good answer for Hz.· I press any key, the screen clears, then display the starting menu.· If I enter another number, the screen turns black for a moment then back to a blank blue screen, which is the color of the screen when I press Game on the remote.
What am I overlooking?··I know I could use Reset but I would like to do the same thing from the keyboard.
Thanks
Sid
PUB Start
·repeat············ 'inserted this command
· 'start the tv terminal
· term.start(12)
· term.out(3)
and then wrote:
cognew(MeasureFrequency, @stack1)
· cycle := 500
· DirA[noparse][[/noparse]OutPin] := Out
· Repeat travel
·· repeat 102
··· !OutA[noparse][[/noparse]OutPin]·········· 'Toggles at cycle rate
··· WaitCNT(cycle + CNT)
· waitcnt(clkfreq*10 + cnt)······ 'inserted this command
Now the scrren displays for 10 seconds, clears the screen, then displays the starting menu.· Everything works fine - I would still like to accomplish the same thing by entering any key from the keyboard, but I can live with this.· Now the only problem is getting a precise number of pulses generated on Pin 6.
Sid
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just tossing my two bits worth into the bit bucket
KK
·
But now looking at OP's other thread (Pulsing a Pin) I'm not sure if we wants constant frequency or just a specific number of pulses.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
PUB start
· repeat
and then after I found the right place to put it I wrote:
··· if kb.getkey
····· waitcnt(clkfreq/100 + cnt)
Now the display remains on the screen until I press any key, then it clears the screen and displays the starting menu.· Nice and clean and it works perfectly.
Sid
there are two big ifs - if i can ever get the program written and, if the Propellor can do it as well as the BS2E.· The BS2E uses five banks, so I may have to use·5 cogs - I just don't know yet.
I have modified my pulsout.spin to pulsout_B.spin.· The modifications let me select the axis X or Y.· If I select X it lets me set the direction L(eft) or R(ight).· If I select Y it lets me select I(n) or O(ut).
Then I enter the travel.· For each mil of travel on the X axis I need to generate 51.56 pulses.· For each mil of travel on the Y axis I need to generate 20.3 pulses.
I have attached a copy of pulsout_B and· of the objects it uses so you will have them handy.···If your Propellor has a keyboard and a TV connected, I would appreciate anyone running the program and giving me their comments.
I still have to write a sequence to select and control the Z axis, which I think I can do.· I think memory might be a problem.· The BS2E probably uses about 8500 of the 10,000 bytes available in the 5 banks.· If I understand correctly, a long on the Propellor is 4 bytes, but I'm not sure how much memory each cog has.· As you can see, my little old Propellor will be spinning its heart out.· Wish me luck and give me lots of H-E-L-P.
Sid
·· Perhaps I missed something...This thread is a little hard to follow.· I thought he just wanted to count to a certain point while waiting for a keypress...IN any event it seems you have more of a handle on what he's doing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com