Message Boards Message Boards

Building reactive, multiuser countdown clocks in WL

Posted 9 years ago
POSTED BY: Andrew Burnett
2 Replies
Posted 9 years ago

Hi Marco,

Thanks for taking the time to work this out. That seems like a very neat solution. I will have to give it a try on the iWatch.

Cheers Andy

POSTED BY: Andrew Burnett

Hi,

this is far from ideal, but it does something in the lines of what you want.

First you create a Databin and make that publicly available:

binstarttime = CreateDatabin[];
SetOptions[binstarttime, "Permissions" -> "Public"];

The data bin will have a short ID something like 4LilXAIZ; you obviously need to change that to your Databin's ID. This following command sets the count-down to 5 minutes:

DatabinAdd[Databin["4LilXAIZ"], {Now, Quantity[5, "Minutes"]}]; 

On each of the clients you run:

RunScheduledTask[dummy = Databin["4LilXAIZ"]["Latest"]["Data"];, 1];
Dynamic[Refresh[
  If[dummy === {0, 0}, "Stop", 
   If[QuantityMagnitude[
      UnitConvert[dummy[[2]], "Seconds"] - 
       UnitConvert[Now - dummy[[1]], "Seconds"]] < 0, "Time's up!", 
    UnitConvert[dummy[[2]], "Seconds"] - 
     UnitConvert[Now - dummy[[1]], "Seconds"]]], 
  UpdateInterval -> 0.01]]

That should initiate the countdown. If you or anyone wants to stop the countdown this works:

Quiet[DatabinAdd[Databin["4LilXAIZ"], {0, 0}];]

When you are done you should also remove the Scheduled task:

RemoveScheduledTask[ScheduledTasks[]]

This is, of course, not really optimal. The RunScheduledTask slows the display of the count-down down. (That sounds funny!). Anyway, I cannot improve it any further right now as I am invigilating an exam and we are nearly doneĀ…

Cheers,

Marco

PS: If you can live with "distributing" a potential "Stop" with up to five seconds delay, this would work instead of the RunScheduledTask above:

RunScheduledTask[dummy = Databin["4LilXAIZ"]["Latest"]["Data"];, 5]

Then, the clock is much smoother and only stalls a bit every 5 seconds.

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract