PDA

View Full Version : Storing and recalling the value of a variable



TonyA
01-08-2006, 03:01 AM
Hi,

I am using a pot (with RCTIME) to change the value of a variable. Is there a way I can store the current value of that variable with a switch and then "recall" that variable with another switch?

If anyone can point me in the right direction it would be greatly appreciated. Thanks again (and Happy new year).

Tony

Jon Williams
01-08-2006, 03:02 AM
Are you wanting to store the value so that you can recall it after a restart? If yes, you can use WRITE with the Word modifier. To retrieve the value you would use READ, also with the Word modifier.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

TonyA
01-08-2006, 03:18 AM
Hi Jon,

Yes, I would like to be able to record the value of the variable at any given time with the push of a button and then to retrieve it at any given time with another button.

This is for my midi appilcations. I want to be able to preset sound bank changes. Like if using the sound patch "water bells", I can press a button and store it's value (127) and return to "water bells" at any given time by pressing a button rather than scrolling with my pot.

Thanks again,
Tony

Jon Williams
01-08-2006, 03:35 AM
It's actually quite simple; you just need to be able to scan buttons in your main loop:

· IF (StorePatch = Pressed) THEN
··· WRITE PatchAddr, patchVal
· ENDIF

· IF (RecallPatch = Pressed) THEN
··· READ PatchAddr, patchVal
····' do something with patchVal
· ENDIF

StorePatch and RecallPatch are button inputs, Pressed is a constant (0 or 1)·that defines the state of the input when a button is pressed, PatchAddr is the location in EEPROM you want to use to store the value, and patchVal is , of course, the sound patch (0 - 127).· By using WRITE for storage you can reset/restart the program and still have the stored value available for recall.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

TonyA
01-08-2006, 04:10 AM
Hi Jon,

I see, yeah. That's all I need. Thanks again for your help, I really appreciate it.

Tony

Post Edited (TonyA) : 1/7/2006 8:21:04 PM GMT