I am using Flowcode 5. I have a program that auto adjusts a variable called SPEED. Its a pretty simple routine. Here is the problem. When I run the program the auto adjust works fine. Say I initialize it at 50 and after the auto adjust routine it ends up at 55. Perfect. But if the program is stopped and restarted it resets SPEED to 50. I need it to hold the value of 55 upon power up. I'm guessing I am not storing it properly. I have only used Flowcode to write my code and do not know how to write c. Any help would be great.
Thanks
Storing Variables
-
- Posts: 14
- Joined: Tue Jul 22, 2008 6:25 am
- Has thanked: 4 times
- Been thanked: 2 times
- Contact:
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
- Contact:
Re: Storing Variables
Variables are stored in RAM, the contents of RAM will be lost on power cycle. Also, if you initialize the value at the start of the program like you should (otherwise it would be a random value) you are resetting it to the default value of 50.
If you want to store a value between runs, look into using the EEPROM component if the controller you are using has EEPROM. Read the value at the start of your program, if the value is valid (between certain limits) use it, otherwise use the default. After adjusting the value write it to eeprom so it can be reused for the next program run. Keep in mind eeprom has a limit on the number of times data can be written, it might be a good idea to check if the currently stored value and the new value differ before writing to avoid wearing the cells.
If you want to store a value between runs, look into using the EEPROM component if the controller you are using has EEPROM. Read the value at the start of your program, if the value is valid (between certain limits) use it, otherwise use the default. After adjusting the value write it to eeprom so it can be reused for the next program run. Keep in mind eeprom has a limit on the number of times data can be written, it might be a good idea to check if the currently stored value and the new value differ before writing to avoid wearing the cells.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 14
- Joined: Tue Jul 22, 2008 6:25 am
- Has thanked: 4 times
- Been thanked: 2 times
- Contact:
Re: Storing Variables
Great, thanks. Do you have any samples showing reading and writing to EEPROM? I don't know how to write C so Flowcode is the best I can do. I've been messing with it a bit here.
Re: Storing Variables
Hi spryderweb,
this is a short video describing how to store and read from an EEPROM, in order to save your variable content even after restart..
this is a short video describing how to store and read from an EEPROM, in order to save your variable content even after restart..
- Attachments
-
- Untitled.zip
- EEPROM handling tutorial
- (1.54 MiB) Downloaded 294 times