2023年7月21日金曜日

Obniz::ardu-cam streaming radicon-car

cf https://iot-gym.com/arducammini-obniz/

https://qiita.com/y-hira/items/0a1f4a69f1b1e858a916

下記コードはarducam-mini-plusのvccを外部からとっているので、そこのところ注意!

<html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script> <script src="https://unpkg.com/obniz@latest/obniz.js"></script> </head> <body> <h2 class="text-center" style="margin:40px">motor contol</h2> <div id="onoff-buttons" class="text-center"> <button id="front" type="button" class="btn btn-primary">front</button> <button id="back" type="button" class="btn btn-secondary">back</button ><br /> <button id="right" type="button" class="btn btn-primary">right</button> <button id="left" type="button" class="btn btn-secondary">left</button ><br /> <div id="obniz-debug"></div> <img id="image"> <script> var obniz = new Obniz("4998-4317"); //obnizIDを入力する obniz.onconnect = async function () { var motor = obniz.wired("DCMotor",{forward:10,back:11}); var motor2 = obniz.wired("DCMotor",{forward:8,back:9}); $('#front').click(function () { motor.forward(); motor2.forward(); setTimeout(function(){ motor.stop();motor2.stop(); }, 1000); }); $('#back').click(function () { motor.reverse(); motor2.reverse(); setTimeout(function(){ motor.stop();motor2.stop(); }, 1000); });  $('#right').click(function () { motor.forward(); motor2.reverse(); setTimeout(function(){ motor.stop();motor2.stop(); }, 1000); }); $('#left').click(function () { motor.reverse(); motor2.forward() setTimeout(function(){ motor.stop();motor2.stop(); }, 1000); }); var cam = obniz.wired("ArduCAMMini", { cs:0, mosi:1, miso:2, sclk:3, gnd:4,sda:6, scl:7 }); await cam.startupWait(); while (true) { //これでストリームとなる const data = await cam.takeWait('160x120');

//'160x120'or'176x144'or'320x240'or'352x288'or'640x480'or'800x600'or'1024x768'or'1280x960'or'1600x1200'を指定する data.unshift(255); // for mini-plus (mini need no this code) console.log("image size = " + data.length + " bytes"); const base64 = cam.arrayToBase64(data); document.getElementById("image").src = "data:image/jpeg;base64, " + base64; } // end of while } </script></body></html>

-------------------arducam only----------------------------------------------------------

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/obniz@latest/obniz.js"></script>
</head>
<body>

<div id="obniz-debug"></div>
<img id="image">

<script>
var obniz = new Obniz("4998-4317"); //obnizIDを入力する
obniz.onconnect = async function () {
var cam = obniz.wired("ArduCAMMini", { cs:0, mosi:1, miso:2, sclk:3, gnd:4, sda:6, scl:7 });
await cam.startupWait();
const data = await cam.takeWait('320x240'); // これでも写真がでるのが結構遅い
 //'160x120'or'176x144'or'320x240'or'352x288'or'640x480'or'800x600'or'1024x768'or'1280x960'or'1600x1200'を指定する
data.unshift(255); // ここが重要!
console.log("image size = " + data.length + " bytes");
const base64 = cam.arrayToBase64(data);
document.getElementById("image").src = "data:image/jpeg;base64, " + base64;
}
</script>
</body>
</html>

0 件のコメント:

コメントを投稿