View Full Version : How to set defaults and keep them

08-20-2005, 11:50 AM

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,


kelvin james
08-20-2005, 01:00 PM
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.


08-20-2005, 09:59 PM
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,


08-21-2005, 03:10 AM
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


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 Savage
08-21-2005, 07:31 AM

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 (mailto:csavage@parallax.com)

08-21-2005, 10:20 PM
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 Williams
08-21-2005, 11:54 PM
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

08-23-2005, 07:28 AM
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.

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

08-23-2005, 07:45 AM
Short version:

~ = invert bits, check the help file in the Stamp editor.

kelvin james
08-24-2005, 12:12 AM
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.


x VAR Byte
DATA @0,5
READ 0,x
PAUSE 2000
PAUSE 2000