Problems with my javascript program on the RPi -
i new javascript , made little program control rpi robot on wlan... got problem. every time when hold w, or d longer time, robot goes crazy , doesn't want stop , drives in 1 direction, until press 1 of other 2 keys. can control robot on webinterface. here code:
<html> <head> <script language="javascript"> window.addeventlistener("keydown", onkeydown, false); window.addeventlistener("keyup", onkeyup, false); function set0() { document.location="cgi-bin/set0.cgi"; } function set1() { document.location="cgi-bin/set1.cgi"; } function set01() { document.location="cgi-bin/set01.cgi"; } function clear01(event) { document.location="cgi-bin/clear01.cgi"; } function onkeydown(event){ var keycode = event.keycode; switch(keycode){ case 87: //w set01(); break; case 68: //d set1(); break; case 65: //a set0(); break; } } function onkeyup(event){ var keycode = event.keycode; switch(keycode){ case 87: //w clear01(event); break; case 68: //d clear01(event); break; case 65: //a clear01(event); break; } } </script> </head> <body> <div style="text-align:center"> <h1>the pirover</h1> <img src="/forward.jpg" id="f" onmousedown="set01()" onmouseup="clear01(event)"> <br> <img src="/left.jpg" id="l" onmousedown="set0()" onmouseup="clear01(event)"> <img src="/right.jpg" id="r" onmousedown="set1()" onmouseup="clear01(event)"> <br> <img src="/stop.jpg" id="s" onmousedown="clear01(event)" onmouseup="clear01(event)"> </div> </body> </html>
Comments
Post a Comment