3
$\begingroup$

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]
$\endgroup$
  • $\begingroup$ Could someone with at least 300 points of reputation please add some more tags? $\endgroup$ – zab Apr 28 '14 at 12:57
  • 1
    $\begingroup$ Dynamic[Clock[] > .5] $\endgroup$ – Vitaliy Kaurov Apr 28 '14 at 13:10
8
$\begingroup$

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}]
| improve this answer | |
$\endgroup$
2
$\begingroup$

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]}]]

trigger

| improve this answer | |
$\endgroup$
  • $\begingroup$ @ m_goldberg, nope, Trigger doesn't work on the Linux version :-( $\endgroup$ – zab May 2 '14 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.