program help
rr
Posts: 63
Hello
·
I am working on a program for an art installation and I need some help with the code.
I am using the OSD video mod to display words on a tv. ·When a viewer activates a button, I want to display a random sequence of words. And when the viewer deactivates the button I want the program to start over.
·
I want to be able to flash random words on the screen. The problem is that I would like the word list to contain at least a hundred words. Is there a better way to do this other than the way done in the attached file? I am also aware that the way I am doing it wont allow a big word set because of program space.
·
Please help…
·
Thanks for your time…
rr
·
I am working on a program for an art installation and I need some help with the code.
I am using the OSD video mod to display words on a tv. ·When a viewer activates a button, I want to display a random sequence of words. And when the viewer deactivates the button I want the program to start over.
·
I want to be able to flash random words on the screen. The problem is that I would like the word list to contain at least a hundred words. Is there a better way to do this other than the way done in the attached file? I am also aware that the way I am doing it wont allow a big word set because of program space.
·
Please help…
·
Thanks for your time…
rr
Comments
A couple things cone to mind when looking at your program.
One is that you don't have to make a seperate routine for each different word. You can store all the words in EEPROM and access them as needed. If you need more memory space, you can add a serial EEPROM for that.
Another thing you will need to do, it to control the size of your random number. The random number you generate will have to match the number of words you have in memory.
One thing you didn't mention is whether you wanted the program to display any random word from the list or if you wanted to make sure each activation should pick a unique word from the list with no repeats.
When you look through a program and see a few lines of code that are repeated almost identically more than a couple times, that's usually a sign that there is an easier and more efficient way to do it. I know my carpel tunnel alarm goes off whenever I see that
Lee
·· Adding to what Lee said, you don't want to have a subroutine for each word since that will cause the program code to grow·fast due to all the branch testing you use.· Even if you use ON...GOTO your list would be extremely long and may not fir on one line.
·· Now, if you store the words in DATA statements, you can use the RANDOM value you're choosing to indicate the offset address to get the word from.· As for a hundred different words fitting into the EEPROM with your code, you'd need to know how many total characters were in all 100 words, adding one character each for the 0 termination.· That would give you a better idea.
·· If you don't have the room on a BS2 you have two choices.· One is to hang an external EEPROM onto the BS2 and store your words there.· Your second choice is to get a BS2pe or similar which can store more DATA in additional slots.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
·· Here is an example of printing random words from a list where all the words are the same length.· I did some funny stuff to help with the RANDOM command, but in your situation the value would seem more RANDOM since you're having a user push a button.· This will change the values you see each time.· Anyway, it's just an example of one way of doing this.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
why is this only good for the same size word, and is there a way to do this with different size words.
also would this work for more than 16 words
i am really new to programing so if you could put a couple comment lines in the program to tell me what the code is doing that would help a lot...
thank you for your time.
·· The program I posted could work with as many words as I could fit into the BS2 memory without really changing much of the program at all (mainly just adjusting variable sizes).· The reason for the constant word length is to calculate their position in the memory map.· For words of different lengths you would need a 0 termination between each word, and you would need to find the word in the list each pass since you wouldn't know it's address.·
·· Now, if you had the external EEPROM, you could build an address map in the BS2 EEPROM and then you could easily lookup the words again based on that information.· Or, if you had a BS2e or higher something similar could be done using slot1 to store the names, and slot0 would have an address map for them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I'm trying to figure out how to get SEROUT to access the EEPROM data. Would this work?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
·· Several changes would need to be made to do what you want to do.· For starters you could just LOOKUP the word like that because it's not at a fixed offset address.· For that many words you would literally need to search for the start of the word by finding the previous 0.· As for your output you've never loaded the variable array wordstart with any data to use that function.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
That doesn't quite parse. Did you mean couldn't? Either way, I'm not sure I follow. LOOKUP is using the index variable to look for the starting address of the word. The starting addresses of the words are defined by the labels in front of the DATA statements.
The wordStart variable is being loaded by the LOOKUP command.
I know the general logic of the program works. I've attached the running code. My real question is whether or not the syntax of my SEROUT command would work. (I'm not currently set up to test serial communications.)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
SEROUT·pinOut,·baud,·[noparse][[/noparse]STR·wordStart]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
PBASIC has no native ability to SEROUT strings. You would have to build a routine to SEROUT each character individually, looking for the null terminator. Is this the question you were asking?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Post Edited (Tom Walker) : 4/7/2006 12:54:04 PM GMT
So, if you have an array of bytes, and the location following the last string byte is a zero byte, then yes,
SEROUT SerPin, SerBaud, [noparse][[/noparse]STR wordstart, 13] should output the string. Note that '13' there is kind of important, that tells any recieving program that the string is complete.
Would you believe that I've been "looping through" strings since I started with the Stamp years ago? D'oh!!! Sometimes you get so complacent while jumping from project to project (hardware to hardware, language to language, system to system) that you turn off the "research bit"...thanks for the enlightenment...time for more research.
SSteve,
I withdraw my previous statement, and apologize for any confusion.
...wanders off, mumbling to himself...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Post Edited (Tom Walker) : 4/7/2006 3:26:26 PM GMT
·· Even so, you are still correct in that since the DATA is coming from DATA statements, it would still have to be read one character at a time, and sent out one character at a time.· The only way to use the STR function would be to preload the array, but that would still have to be done one character at a time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thanks for saving some of my dignity...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
·· No problem...The bottom line is that the information will have to be read from the DATA statements one character at a time, regardless of how it's handled elsewhere in the program.
Steve,
·· While I am not ever inclined to do anyone's work for them (you don't learn that way), I am willing to come up with something you can customize.· But you will need to enter all the DATA stements into the code and post it.· I will write a core routine that picks random words from that list and sends them out serially.
·· Please be specific on the way the program is supposed to work, including if the button the user presses is active high or active low.· How many words get sent, etc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thanks for the offer, but you don't need to write a program for me. I agree that doing is a better way to learn. I'm trying to clarify the SEROUT syntax. So if the variable "theAddress" contained the address of a zero-terminated string in a DATA statement, would this be the correct way to use SEROUT? (I tested this code and I see the words in the DEBUG terminal, but I don't currently have a way to test SEROUT.)
Thanks for your patience.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
·· At a glance that looks correct.· That is assuming you've already identified the beginning (start address) of the word you want to send, which will be different than you originally thought considering words of different lengths, zero-terminated.· Good luck.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
In other words, randomizing the selection of words will be a bear - correct assumption? If so, I would propose using fixed length words (padding all words with spaces to the length of longest word). Random selection could then be driven by a straightforward randomly generated index into the "word stack" - no parser (don't have to keep track of 0's or commas...) for example.
Make sense?
Paul
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Here's a program that will print a random word out of a list of 100 variable length, zero-terminated words stored in the stamp's EEPROM. I can't test the SEROUT statement, but the correct output shows up in the debug window.
-Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
·· That is a similar approach to what I was thinking, except that to save code-space I was going to have a DATA lookup table.· But hey, it works, right.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
·· Very good, you saved 2% of the EEPROM space and learn/shared a valuable lesson with your peers.· Congratulations!·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
P.S. am I a geek for writing a C program to generate repetitive code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
i came up with a program using Chris's sample program.
it works well for my needs but i am sure it could be more efficiant.
·· Functionality first, efficiency later.· Of course, to some degree you want to work on both while writing, but if you worry too much about one then you may have trouble with the other until you're more experienced.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
You can change the list of IF/THEN statements to "ON address // 7 GOTO pick8, pick7, pick6, pick5, pick4, pick3, pick2"
Any time you see code repeated as in your various "pick" routines, that's a good sign that you should make a subroutine. You could change your "pick" routines to something like this:
This routine displays the words:
Here are the variable definitions:
I haven't tested the code, but it should give you an idea of where to go.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows