Skip to content

Instantly share code, notes, and snippets.

@adoyle
Last active August 29, 2015 14:08
Show Gist options
  • Save adoyle/d31a7f600d81757cfcc1 to your computer and use it in GitHub Desktop.
Save adoyle/d31a7f600d81757cfcc1 to your computer and use it in GitHub Desktop.
Snippet to send motor controller requests via jQuery get()
// 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