Shop OBEX P1 Docs P2 Docs Learn Events
Store Variable Basic Stamp 2 — Parallax Forums

Store Variable Basic Stamp 2

Luis_PLuis_P Posts: 246
edited 2009-01-21 16:33 in BASIC Stamp
Hello, Please help! help! help!

I'm getting crazy trying to store a variable on the stamp 2, After program runs completely I need to keep a number on a variable, how do I do that?
In Visual Basic we use global or public variable but on PBasic I have not idea, please dump some code so I can understand. I'm new on this.

Gracias!!!!tongue.gif


' {$STAMP BS2}
' {$PBASIC 2.5}

·

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-01-20 06:53
    Hi Luis, where you would declare a variable in Visual Basic perhaps Public x As Byte in PBasic you would declare x VAR Byte.

    The Pbasic help files and manual have plenty of examples and if you are already familiar with aspects of Basic programming you should be up and running very quickly, when you run into difficulty or aspects of the manual you don't understand then this forum is a great resource to turn to for further advice.

    Jeff T.

    ·
  • Luis_PLuis_P Posts: 246
    edited 2009-01-20 19:40
    Hi Jeff:

    · I tried x VAR Byte. but when the pogram finish next time I run that variable when back to Zero.

    I need to store an acummulative value example:

    Run the program first time:

    x = 0

    Run the program second time:

    x = 1

    So I think I need something like x = x + 1 every time I run the program the variable x = 0 it should be read only at the first time so I can use a code like this:

    If x = 1 then goto firts_Subrutine·

    x = 0

    'code here for x = 0

    end

    First_Subrutine:

    'seconde code here if x equal to 1



    Luis
  • sylvie369sylvie369 Posts: 1,622
    edited 2009-01-20 19:44
    You need to write your variables to the BS2's EEPROM using the WRITE command, and then read it back the next time using the READ command. That's how to make variables that persist during power off periods.

    Read the Basic Stamp manual's entries on those two commands carefully. It's pretty clear how to use them, but you'll want to be familiar with what's happening.
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-01-21 02:20
    Oh, and do be careful. You can only WRITE to a particular location a million times. While that sounds like a lot, during testing if you write to the same location every millisecond, you can wear it out in a few days.

    Oh, and you should know that the PBasic program is stored in the eeprom from high addresses down, while your "DATA" and "READ/WRITE" locations start at zero up.

    In other words, you can WRITE to location zero or one or two safely.
  • Luis_PLuis_P Posts: 246
    edited 2009-01-21 06:01
    Oh that's bad, but thanks for the advice.
    · So I have to write a code that before reaches the million times to use another location, mmmm sounds dificult, any ideas?

    Luis
  • TWRackersTWRackers Posts: 33
    edited 2009-01-21 16:33
    If your application explicitly terminates (as opposed to stopping only when you power it down), write the value(s) you want to save to EEPROM at that time, but use variable space (or SPRAM if your chip has any) while your code is looping.· You probably won't run your application a million times.
Sign In or Register to comment.