Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If you've ever wanted to see how fast a remote controlled car can actually go (or you are bored and want to see how fast you can spin your mouse wheel) this script is for you.

This script measures how fast the mouse wheel is spinning and translates that into miles per hour (when I'm bored I write stuff in perl).

Note: The script is calibrated for a Microsoft Wireless IntelliMouse Explorer 2.0

use warnings; use strict; use Tk ':variables'; use Time::HiRes; my $clicksPerRevolution = 17; #how many numbers are sampled in one com +plete revolution of the mouse wheel my $wheelArea = 4.75; #how many inches are in one complete revolution +of the mouse wheel my $clicksPerMile = (63360/$wheelArea)*$clicksPerRevolution; #63360 in +ches in a mile my $mouseWheel = 0; my ($previousClickTime, $currentClickTime); my $maxSpeed = 0; my $mw = MainWindow->new(); my $lbl1 = $mw->Label(-text => 'Max MPH'); my $lbl2 = $mw->Label(-textvariable => \$maxSpeed); my $lbl3 = $mw->Label(-text => 'Current MPH'); my $lbl4 = $mw->Label(-textvariable => \$mouseWheel); $lbl1->grid(-row => '0', -column => '0'); $lbl2->grid(-row => '0', -column => '1'); $lbl3->grid(-row => '1', -column => '0'); $lbl4->grid(-row => '1', -column => '1'); $mw->bind('<MouseWheel>' => \&mph ); $mw->bind('<4>' => \&mph ); #zentara $mw->bind('<5>' => \&mph ); #zentara $mw->MainLoop(); sub mph{ $previousClickTime = $currentClickTime; $mouseWheel = $Tk::event->XEvent; $incr++; ($seconds, $microseconds) = Time::HiRes::gettimeofday(); $currentClickTime = $microseconds; if ($incr > $clicksPerRevolution){ $incr = 1; } $microSecondsBetweenClicks = $currentClickTime-$previousClickTime; if (eval{ $mouseWheel = sprintf '%.2f', (1/$clicksPerMile)/($micro +SecondsBetweenClicks/3600000000); }){} if ($mouseWheel > $maxSpeed && $mouseWheel < 600){ $maxSpeed = $mouseWheel; } } sub arrPush{ my $value = shift; push (@avgArray, $value); }

In reply to Use your mouse wheel as a dynamometer by coderama

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (7)
    As of 2018-05-27 13:52 GMT
    Find Nodes?
      Voting Booth?