このプロジェクトでは、LAN 経由でおもちゃの車を制御します。
私のHTMLページには、上、下、左、右、停止の5つの「ボタン」があります。私のコードは次のように機能します: ユーザーが「up」をクリックすると、処理のために値が php ページに送信され、処理された文字列が別の php ページに出力され、arduino が読み取ることができるとします。
車が止まるには、ユーザーは停止をクリックする必要があります。
<html>
<head>
</head>
<form name="motorform" action="motorboardprocess.php" method="post">
<tr><p align='center'><font face="BN machine" size="6" color="royalblue">Motor Shield</font></tr>
<tr>
<input id="forward" type="image" src="up.png" name="forward">
</tr>
<tr>
<input id="left" type="image" src="left.png" name="left">
<input id="stop"type="image" src="stop.png" name="stop">
<input id="right" type="image" src="right.png" name="right">
</tr>
<tr>
<input id="backward" type="image" src="down.png" name="backward">
</tr>
</form>
</body>
</html>
そして、前述のphp ...
<?php
if (isset($_POST['forward_x'], $_POST['forward_y'])){
$myFile = "mtboardcom.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<?php\n";
fwrite($fh, $stringData);
$stringData = "echo ".'"<forward>"'."\n";
fwrite($fh, $stringData);
$stringData = "?>\n";
fwrite($fh, $stringData);
fclose($fh);
}
else if (isset($_POST['left_x'], $_POST['left_y'])){
$myFile = "mtboardcom.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<?php\n";
fwrite($fh, $stringData);
$stringData = "echo ".'"<left>"'."\n";
fwrite($fh, $stringData);
$stringData = "?>\n";
fwrite($fh, $stringData);
fclose($fh);
}
//and so on.....
arduinoは次のように読みます:
<?php
echo "<forward>"
?>
mousedown
問題は、jquery のイベントとイベントをどのように利用しmouseup
て停止「ボタン」を削除するかです。
または別のシナリオ: ユーザーがボタンを押したままにして車を動かし、ボタンを放して車を止める。
mousedown
では、文字列がarduino'forward'
によって読み取られます。
mouseup
同じボタンで、文字列'stop'
が arduino によって読み取られます。