You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: simulator/programming/index.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,12 +96,20 @@ The LEDs are attached to digital pins 3-4:
96
96
97
97
Using the `digital_write` method, you can set these to True (On) or False (Off).
98
98
99
-
###Time
99
+
##Simulated Time
100
100
101
101
In the simulated environment, time advances only at the pace that the simulator
102
102
is run. As a result, using `time.time` to know how long your robot has been
103
103
running for or `time.sleep` to wait for some duration will be unreliable.
104
104
105
105
As a result the API present in the simulator supports a slightly different
106
-
approach to handling time. See the documentation about [simulated time](./time)
107
-
for more details.
106
+
approach to handling time.
107
+
The methods `R.time` and `R.sleep` are provided as a direct replacement of `time.time` and `time.sleep` respectively and can be used anywhere the previous methods were used.
108
+
109
+
<divclass="warning">
110
+
Since the simulator does not simulate the time taken to execute your code, any loop or decision which needs an event to occur must be accompanied by a <code>R.sleep</code> even if with a small value.
111
+
112
+
<b>If in doubt add an <code>R.sleep</code></b>.
113
+
114
+
If you find that the simulator freezes then this indicates that your code is reaching a loop which does not contain any <code>R.sleep</code> and is expecting time to advance.
0 commit comments