I'm trying to make a binary switch that switches after a fixed given interval. Why doesn't the following work:
step = .1;
t = Dynamic[Clock[{0, 5, step}, 5, 1] ];
Dynamic[t >= 2]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI'm trying to make a binary switch that switches after a fixed given interval. Why doesn't the following work:
step = .1;
t = Dynamic[Clock[{0, 5, step}, 5, 1] ];
Dynamic[t >= 2]
Note that you've defined t
as a Dynamic
expression. A relational operator like GreaterEqual
(>=
) works with numeric expressions like the result of Clock
. You could try something like this to get a displayed output that eventually switches from False
to True
:
step = .1;
Dynamic[{t, t = Clock[{0., 5., step}, 5., 1]; t >= 2}]
I couldn't help thinking about this question even after I voted for billsphere's perfectly satisfactory answer. Finally, I concluded that Trigger
would be a better way to implement the requested functionality. It is just as easy to use as Clock
and throws in a nice little control panel as a bonus.
With[{dt = 1, tmax = 10, threshold = 4},
Column[{
Dynamic @ Row[{t, " > ", threshold, " is ", t > threshold}],
Trigger[Dynamic @ t, {0, tmax, dt}, dt]}]]
Dynamic[Clock[] > .5]
$\endgroup$