Page 1 of 1
Storing Variables
Posted: Tue Oct 06, 2015 10:45 pm
by spryderweb
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
Re: Storing Variables
Posted: Tue Oct 06, 2015 11:04 pm
by kersing
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.
Re: Storing Variables
Posted: Wed Oct 07, 2015 12:00 am
by spryderweb
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
Posted: Wed Oct 07, 2015 9:47 am
by Seif
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..