Shop OBEX P1 Docs P2 Docs Learn Events
I want to use a set of variable arrays to store direction and distance to trave — Parallax Forums

I want to use a set of variable arrays to store direction and distance to trave

tedbeautedbeau Posts: 48
edited 2008-04-03 13:44 in BASIC Stamp

I have a simple question (yeah right, they’re all simple if you know the answer).

I want to use a set of variable arrays to store direction and distance to travel. The user would input the direction and distance into the array using debug.

Here is the question, when the stamp is started or reset, are variable arrays and variables reset or cleared?

If so what are is the default value. In other words after I have the numbers in the array, when the program finishes, can I press reset, and run it again without entering, and also, if I want to change the array, do I need to clear out old values first, in case I use less numbers. I don’t want to program to use the old data if it’s still in the array after reset.

Thanks



[noparse][[/noparse]Moderator Added Subject]

Post Edited By Moderator (Chris Savage (Parallax)) : 4/1/2008 4:25:09 PM GMT

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-04-01 18:43
    Hi, each time the Stamp is reset the variable stored in each element of the array will initially be at 0.

    When you enter the data through debugin you will increment the index of the array by one each time , by keeping track of the index you will know exactly how many elements of the array·you are using·and you will ignore any elements of the array·beyond the stored index value.

    Jeff T.
  • ercoerco Posts: 20,260
    edited 2008-04-01 20:58
    Make your program WRITE the values at the top of EEPROM as you enter them, they'll stay there forever (through reset, power off, etc) for you to READ them until you WRITE over them again. Remember, these values are stored from the top down in EEPROM. Your program is stored starting at the bottom of the EEPROM and fills up. Don't let them meet in the middle, or the earth as we know it will cease to exist.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-01 21:36
    Okay, but your program is stored in location 0x2FF and DOWN. And your "DATA" statements are stored from address 0x0000 and UP.

    Terms like "top" and "bottom" can be misunderstood. In your code you're going to be using the address values. The above should keep you safe.
  • tedbeautedbeau Posts: 48
    edited 2008-04-02 13:10
    Thanks for the information. I knew I could write the data to the unused EEPROM space but I was kind of wanting to avoid that, not knowing how much space I would have. I am just learning to program the stamp and don't have a feel yet for how much space the robot run program will use up, or how many waypoints/changes in direction I might want to enter.

    So from the replies it appears that the array elements are reset to 0 every start or reset. That would negate my plan of having a zero value serve as an end of usable data marker in the array. I guess I could use a different character. I think its possible to write a NULL into an array, isnt it? Or I could use unsounds suggestion and just track how many elements were filled using the index. Thats probably the "Correct" way to do it.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-04-02 16:37
    Hi, one thing about arrays is that you are limited to how many elements you can have due to available variable space. If you use the EEPROM to store values then you could store a lot more distance and travel data but probably would not use an array, in the case of the EEPROM data you might use a variable as an index to point to an EEPROM address containing distance and direction data.

    Whichever way you choose keeping track of the index is keeping track of your position, you can count from 0 to the upper limit of your index to travel one direction and the upper limit of the index to 0 to travel back or use an index value to perform a certain action at a certain position.

    Jeff T.
  • tedbeautedbeau Posts: 48
    edited 2008-04-03 13:44
    Thanks for the help. I have it working OK now with a little adjusting yet to do. I did run into a ram limitation when I created the variable arrays. I wasn't paying attention to where I was headed with the variables and created a array of word size, for direction even though I only need 9 options for actions or directions. This of course makes a VERY large array. I was quite pleased that the data input routine that I wrote using debugin worked the first time. This was my first time writing input code using debug and PBasic so I think I actually just got lucky, but hey, better lucky than good, anyday!

    Ted
Sign In or Register to comment.