Subject:
|
Re: Does any RCX firmware allow a variable to survice shutdown?
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Wed, 29 Jun 2005 15:26:48 GMT
|
Viewed:
|
1116 times
|
| |
| |
In lugnet.robotics, Justin Fisher wrote:
> I'd like my robot to be able to store a variable, such that when I turn the RCX
> off, then back on again, with the start/stop button, the value of the variable
> is retained, not wiped.
Global variables in the standard LEGO firmware(s) are persistent (i.e., their
values are not lost when you turn off the RCX). You describe turning the RCX
off and on using the "start/stop" button. I am guessing that you mean the red
button labeled On-Off. Do you actually mean the green button labeled Run?
There isn't a start/stop button so I am a bit unsure if I have understood you
correctly.
In an NQC program you defined a global variable outside any function or task.
int a;
task main()
{
a = 4;
int x = 3;
int y = 3;
OnFwd(OUT_A);
OnFwd(OUT_B);
Wait(400);
OnRev(OUT_A+OUT_B);
Wait(400);
Off(OUT_A+OUT_B);
}
If you look at the generated code (via F12 in BricxCC) you will see at the top a
section like this:
*** Var 0 = a
*** Var 47 = x
*** Var 46 = y
The value of "a" will be 4 after you run this program and it will have that
value after you turn off the RCX and turn it back on again. Of course the next
time you run a program that writes to global variable zero (the global variable
that "a" happens to be assigned to here) then that value will be changed.
Variables 0-31 are global variables and, as mentioned above, they are
persistent. The only time the values will be lost is if the firmware is lost
due to taking the batteries out long enough for the capacitors to drain or by
downloading the firmware again.
John Hansen
|
|
Message is in Reply To:
6 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|