Do we have counter service here?
March 21, 2024 4:55 AM   Subscribe

For a workshop I need to make three digital counters that can sit in the corner of my (Windows 11 Pro) desktop, each of which will increment by a fixed, non-variable amount every second - how do I do this?

One counter needs to increment @ 29.8 units per second, one @ 280 units per second and one @ 361.1 units per second over an extended period of time (3 hours or so).

I don't code (yet) but I am reasonably tech savvy, and could install a coding environment and probably run some code if that's the best way to do this, but would have no idea how to write the code, and probably not enough time to figure this out myself?

Also happy to use a free or minimal cost off-the-peg solution if one exists, but I ended up with mostly useless results when I tried to Google for this.

Bonus points for figuring out what the values are that I want to display - they should be pretty obvious to anyone with an astrophysics background (and if you do recognise them, and my values are wrong, please tell me!)

Thanks in advance, I figured that if anyone would know how to do this, they'd be here on the Green!
posted by Chairboy to Computers & Internet (5 answers total)
 
Best answer: I peeked around but didn't immediately see anything canned.

I did find a JavaScript stopwatch, and tweaked the 'updateStopwatch' function to increment by one of your values.

Do note that JavaScript due to the way that floating point numbers work, you will start to get funny rounding decimals. I'll leave it as an exercise to the reader to add the rounding function!
posted by gregr at 6:35 AM on March 21 [1 favorite]


Best answer: My usual for programming little widgets with a relative minimum of extra work is either AutoHotKey or Python's Tkinter. Both should be capable of doing what you want.
posted by BungaDunga at 7:51 AM on March 21


Best answer: The approach in gregr's comment will basically work, but it's not super accurate because there's no guarantee that the setInterval callback will be called exactly once per second, and any errors will be cumulative.

A more reliable approach is to have the callback that updates the counters run at whatever frequency you like, but recalculate the counters on every update, based on the elapsed system time since the timer started. That way, even if the updates are occasionally delayed because the browser is busy doing something else, the counter values will be as accurate as your system clock (which can be kept in sync using NTP or whatever, if you really want to be as accurate as possible).

Like this: https://jsfiddle.net/b7sh5emp/

If you want to run that code locally, paste the HTML into a .html file, and put the JavaScript code at the end inside of a <script>...</script> tag.

(I'm guessing the first value, 29.8, is the Earth's orbital speed in km/sec, but I'm not sure about the other two.)
posted by teraflop at 2:04 PM on March 21 [2 favorites]


Best answer: teraflop's solution seems to work really well. I'll just mention that if you want the display to visually update every second instead of "continuously" you can just change this line:

timer = setInterval(updateCounters, 50);

To this:

timer = setInterval(updateCounters, 1000);

Then hit "run" at the top left to re-start with the changed code. As teraflop mentioned, the 1-second timer in javascript is not going to be 100% accurate, because the browser can get busy doing this or that and javascript gets delayed. But as a rule it will be pretty good, and the inaccuracies in the update interval don't really matter because as teraflop pointed out it recalculates the values based on the actual elapsed time since the timer was started. So variations in the actual update interval won't make things go awry, except for perhaps looking a little jerky or inconsistent in the update interval once in a while.
posted by flug at 8:52 PM on March 21 [1 favorite]


Response by poster: Thanks all - this is super helpful!

Thats's spot on re Earth's orbital velocity, and the other two values were what I found respectively for the Sun's rotation rate around the galactic core, and for the Milky Way's velocity in relation to the local cluster, although there seems to be great deal of variance in relation to the values given for both of them.
posted by Chairboy at 7:52 AM on March 25


« Older Good examples of employee profit sharing for small...   |   When will the love come? Newer »

You are not logged in, either login or create an account to post comments