Shop OBEX P1 Docs P2 Docs Learn Events
How to set defaults and keep them — Parallax Forums

How to set defaults and keep them

TorquewrenchTorquewrench Posts: 28
edited 2005-08-23 17:12 in BASIC Stamp
Hi,

I am working on a project for automating the firing of a paintball gun. I've made huge progress in developing the code. I have a firing sequence, firing modes, and LCD menu control (thanks big time to Nuts & Volts, Jon Williams, you rock!).

My question concerns how to incorporate presets to variables that can then be changed and kept.

To clarify, here are my variables
Shot counter 'short term shots, easily reset
Odometer 'lifetime shots, difficult to reset
firing rate limit
burst count
solenoid dwell
drop time between shots
low battery voltage

So I would like to load up defaults when I first load the program on the stamp, but afterwards I have built menus to be able to adjust these values, and when the stamp is turned off I would like these user configured settings to remain.

I have attached the menu portion of my code if it helps, but I think this is a more general question.

Thank you,

Phil

Comments

  • kelvin jameskelvin james Posts: 531
    edited 2005-08-20 06:00
    Not a problem, just use the write command to store the variables to different addresses as they are set from the menu, and then read the variable data at the start up. Have a look at the help section, pretty easy to do. Just check the eeprom map to make sure you are not overwriting anything in those locations.

    kelvin
  • TorquewrenchTorquewrench Posts: 28
    edited 2005-08-20 14:59
    I'm not sure if I'm quite there yet. I want to write values to these variables at the time the stamp is programmed, then have the variables be user modifiable so that out in the field the user-set values will remain intact even when the stamp is turned on and off.

    What I'm thinking is I need an EEPROM location for the default values, and somehow copy these to the variables and the user set EEPROM locations only at programming time. Once programming is complete the user can modify the user set EEPROM locations only.

    If this is what you described, could you maybe give me a sample of code on how this is done?

    Thank you,

    Phil
  • OrionOrion Posts: 236
    edited 2005-08-20 20:10
    What about using the DATA command to load the stamp eeprom with the defaults @ program, then READ them in @ runtime.

    DATA 0, 60 'firing rate limit
    DATA 1, 31 'low battery voltage *10

    firerate var byte
    lowbat var byte

    Main:

    READ 0, firerate
    READ 1, lowbat

    Then to change them through the menu, then WRITE and they will be stored.

    WRITE 0, firerate
    WRITE 1, lowbat

    Check the help in the editor for more info on these commands, but it should do want you want.

    Post Edited (Orion) : 8/21/2005 3:19:48 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-21 00:31
    Orion,

    ·· I don't know if you realize with your code where the data is going.· With your current code the EEPROM will contain 0, 60, 1 and 31.· So when the code is run the 0 and 60 will be read in for the firing rate and lowbat.· The 1 and 31 will never be accessed.

    ·· Also, this program writes to EEPROM what it read.· You should change the values first to see the effect.· But other than that it will store the values written at run-time in place of those DATA values (The first 2).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • OrionOrion Posts: 236
    edited 2005-08-21 15:20
    My bad I did not test it, and should have. It still shows how it "could" be done

    DATA 60,31

    instead of

    data 0,60
    data 1,31

    Post Edited (Orion) : 8/21/2005 3:20:27 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-08-21 16:54
    If you want to target a location in EEPROM to place data, you can:

    DATA @0, 60
    DATA @1, 31

    In this case, however, it just creates more typing than required.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • metron9metron9 Posts: 1,100
    edited 2005-08-23 00:28
    New at all of this but could you tell me how the key input routine works? and what is the "~" used for? or link to where I can read about it thanks.

    GetKey:
    key = %11000000 ' assume all pressed
    FOR loop = 1 TO 5 ' test five times
    key = key & ~tempB ' test against new input
    PAUSE 5 ' wait 5 ms between tests
    NEXT
    RETURN
  • OrionOrion Posts: 236
    edited 2005-08-23 00:45
    Short version:

    ~ = invert bits, check the help file in the Stamp editor.
  • kelvin jameskelvin james Posts: 531
    edited 2005-08-23 17:12
    After a look at your program, man that is a lot of code to run an lcd. You should really consider going serial to simplify things. Anyway, for anyone that is interested to see this work, here is a simple program. When the stamp is programmed, the first debug shows the 5, and the second debug a 2. When the stamp is reset, or turned off/ on, the first debug will show 2. Obviously, if x is not changed, the 5 would hold. A subroutine could be made to reset defaults, as to re-write all the default values to the eeprom locations.

    kelvin

    x VAR Byte
    DATA @0,5
    READ 0,x
    DEBUG DEC x,CR
    PAUSE 2000
    x=2
    WRITE 0,x
    DEBUG DEC x,CR
    PAUSE 2000
Sign In or Register to comment.