Quantcast
Channel: Support - Pimoroni Buccaneers
Viewing all articles
Browse latest Browse all 6857

Pan Tilt Hat Web Interface KeyDown Loop

$
0
0

@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

Read full topic


Viewing all articles
Browse latest Browse all 6857

Trending Articles