Shop OBEX P1 Docs P2 Docs Learn Events
Writing variables? — Parallax Forums

Writing variables?

pcfreak22pcfreak22 Posts: 1
edited 2012-02-22 13:35 in Robotics
Hello,

I am in the process of building a maze solving BOE-bot and I want my robot to remember the maze layout after the first trial so it can simply go through the maze quickly for the next trials. I therefore need a way to store variables after the robot makes it out of the maze during the first trial so it can remember the layout for subsequent trials. Any suggestions on how to do this? Can I use the READ/WRITE commands in my code to automatically write variables to EEPROM after it makes it out of the maze?

Comments

  • ercoerco Posts: 20,255
    edited 2012-02-22 11:18
    Yes, write the variables and read them back. Stays in EEPROM until you write over them.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-02-22 11:23
    Yes you can do this, but keep these two caveats in mind.

    First, if you write to an eeprom to frequently you can wear it out. So keeping volatile state in RAM and then writing to the eeprom after it is more stable is the way to go.

    Second, you should reserve space in the eeprom for the amount of data you intend to write using Pbasic data statements. If you don't the risk of overwriting your program with your data.
  • ercoerco Posts: 20,255
    edited 2012-02-22 13:04
    Martin_H wrote: »
    First, if you write to an eeprom to frequently you can wear it out. So keeping volatile state in RAM and then writing to the eeprom after it is more stable is the way to go.

    True that, but we're talking about millions of write cycles before any damage is done. Very unlikely to get into trouble unless you have buggy code that mistakenly writes & rewrites in an endless loop.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-02-22 13:29
    erco wrote: »
    True that, but we're talking about millions of write cycles before any damage is done. Very unlikely to get into trouble unless you have buggy code that mistakenly writes & rewrites in an endless loop.

    True, but I just wanted to alert him to the issue.
  • photomankcphotomankc Posts: 943
    edited 2012-02-22 13:35
    erco wrote: »
    True that, but we're talking about millions of write cycles before any damage is done. Very unlikely to get into trouble unless you have buggy code that mistakenly writes & rewrites in an endless loop.

    That's surprisingly easy to run into. Had a bug in my thermostat code once that lead to me adding many many thousands of write cycles when it ran off the end of a variable and began running the updateLog routine every cycle instead of once every 1hr.

    That's my special talent.... doing things others find improbable and breaking something in ways nobody ever saw coming ;)
Sign In or Register to comment.