Last active
August 29, 2015 14:08
-
-
Save adoyle/d31a7f600d81757cfcc1 to your computer and use it in GitHub Desktop.
Snippet to send motor controller requests via jQuery get()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lock keeps requests from piling on top of each other. | |
// without this, you can get requests totally out of order | |
var lock = 0; | |
function mouseMove(event) { | |
var speed = event.pageY / 4; // Just a hack to make the control box bigger | |
if ( lock === 0 ) { | |
lock = 1; | |
$.get('/motors?m1s=' + speed + '&m2s=' + speed +'&m3s=' + speed, | |
function(data) { | |
$('#control').html(data); | |
lock = 0; | |
} | |
); | |
} | |
} | |
$(document).ready(function() { | |
$('#control').mousemove(mouseMove); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment