https://thunderblog.org/2019/02/obniz-rc.html これすぐれものサイト
https://docs.obniz.com/ja/
https://docs.obniz.com/ja/sdk/parts/DCMotor/README.md
:: ⚠obnizBoard/obnizBoard1YにDCMotorをつなぐときは、obnizBoard/obnizBoard1Y電源供給はPCなどには繋がないでください。ノイズ等によりPCが破損する恐れがあります。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
https://blog.obniz.com/make/kids-project-simple-rc-car : : スマホオンリー
<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>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB"
crossorigin="anonymous"
/>
<script
src="https://unpkg.com/obniz@3.x/obniz.js"
crossorigin="anonymous"
></script>
</head>
<body>
<br />
<button
id="lf"
class="btn btn-warning"
style="width:45%;height:100px;font-size:50px;"
>
↑
</button>
<button
id="rf"
class="btn btn-warning"
style="width:45%;height:100px;font-size:50px;"
>
↑
</button>
<br />
<br />
<button
id="lb"
class="btn btn-primary"
style="width:45%;height:100px;font-size:50px;"
>
↓
</button>
<button
id="rb"
class="btn btn-primary"
style="width:45%;height:100px;font-size:50px;"
>
↓
</button>
<script>
let obniz = new Obniz("4998-4317");
obniz.onconnect = async () => {
let motorA = obniz.wired("DCMotor", { forward: 3, back: 2 });
motorA.power(40); // pwm? maybe....
let motorB = obniz.wired("DCMotor", { forward: 0, back: 1 });
motorB.power(40);
$("#lf").on("touchstart mousedown", () => {
motorA.move(true);
}); // during event , front on
$("#lf").on("touchend mouseup", () => {
motorA.stop();
});
$("#lb").on("touchstart mousedown", () => {
motorA.move(false);
}); // during event , back on
$("#lb").on("touchend mouseup", () => {
motorA.stop();
});
$("#rf").on("touchstart mousedown", () => {
motorB.move(true);
});
$("#rf").on("touchend mouseup", () => {
motorB.stop();
});
$("#rb").on("touchstart mousedown", () => {
motorB.move(false);
});
$("#rb").on("touchend mouseup", () => {
motorB.stop();
});
};
</script>
</body>
</html>
-------------------------------------------------------------------GUIをhtml/css/jsに変換したもの
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
/>
</head>
<body>
<h3 id="bploading" style="text-align:center;">LOADING...</h3>
<div id="OBNIZ_OUTPUT"></div>
<br />
<script
src="https://unpkg.com/obniz@latest/obniz.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/iothome/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/airobot/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ui/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/howler2.1.2/howler.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/opencv3.4/opencv.js"
crossorigin="anonymous"
></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.19.0"> </script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@2.1.1"> </script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8.5/dist/teachablemachine-image.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet@2.2.2"></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/clmtrackr/clmtrackr.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/clmtrackr/emotion_classifier.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/clmtrackr/emotionmodel.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/clmtrackr/model_pca_20_svm.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/ai/index.js"
crossorigin="anonymous"
></script>
<script
src="https://unpkg.com/obniz-parts-kits@0.18.0/storage/index.js"
crossorigin="anonymous"
></script>
<script>
$("#bploading").text("RUNNING...");
(async function(){ メイン関数
var obniz, servomotor, servometor2, button, button2;
obniz = new Obniz('4998-4317');
await obniz.connectWait(); コネクト定義とモータ定義とボタン定義
servomotor = obniz.wired("ServoMotor",{"signal":0, "vcc":1, "gnd":2});
servometor2 = obniz.wired("ServoMotor",{"signal":3, "vcc":4, "gnd":5});
button = new ObnizUI.Button('forward');
button2 = new ObnizUI.Button('backward');
while (true) {
await ObnizUI.Util.wait(0);
if (button.isClicked()) {
servomotor.angle(180);
servometor2.angle(0);
await obniz.wait(300);
servomotor.angle(91);
servometor2.angle(91);
await obniz.wait(100);
} else if (button2.isClicked()) {
servomotor.angle(0);
servometor2.angle(180);
await obniz.wait(300);
servomotor.angle(91);
servometor2.angle(91);
await obniz.wait(100);
}
}
})();
var obniz, servomotor, servometor2, button, button2;
obniz = new Obniz('4998-4317');
await obniz.connectWait(); コネクト定義とモータ定義とボタン定義
servomotor = obniz.wired("ServoMotor",{"signal":0, "vcc":1, "gnd":2});
servometor2 = obniz.wired("ServoMotor",{"signal":3, "vcc":4, "gnd":5});
button = new ObnizUI.Button('forward');
button2 = new ObnizUI.Button('backward');
while (true) {
await ObnizUI.Util.wait(0);
if (button.isClicked()) {
servomotor.angle(180);
servometor2.angle(0);
await obniz.wait(300);
servomotor.angle(91);
servometor2.angle(91);
await obniz.wait(100);
} else if (button2.isClicked()) {
servomotor.angle(0);
servometor2.angle(180);
await obniz.wait(300);
servomotor.angle(91);
servometor2.angle(91);
await obniz.wait(100);
}
}
})();
</script>
</body>
</html>
</html>
0 件のコメント:
コメントを投稿