@zacklabel wrote:
Hello, I have the Pan Tilt Hat web server example loaded but I am unable to keep the unit moving while holding down an arrow key. It moves briefly then stops. I looked into the code and could not figure out what the problem is since the keydown should be looping until keyup. How can I edit this base code to loop the KeyDown?
$(function(){ $(window).on('keydown',function(e){ clearInterval(interval); switch(e.keyCode){ case 38: // Arrow Up current_direction = 'tilt'; current_angle = 1; interval = setInterval(pantilt,pantilt_speed); break; case 40: // Arrow Down current_direction = 'tilt'; current_angle = -1; interval = setInterval(pantilt,pantilt_speed); break; case 37: // Arrow Left current_direction = 'pan'; current_angle = 1; interval = setInterval(pantilt,pantilt_speed); break; case 39: // Arrow Right current_direction = 'pan'; current_angle = -1; interval = setInterval(pantilt,pantilt_speed); break; } }); $(window).on('keyup',function(e){clearInterval(interval)});
Posts: 2
Participants: 2