Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!-- HTML Example -->
<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@latest/obniz.js"></script>
</head>
<body>
<div id="obniz-debug"></div>
<h1>ルームライトスイッチ</h1>
<button id="on" class="btn btn-warning" style="width:45%;height:90px;font-size:50px;">点灯</button>
<br>
<br>
<button id="off" class="btn btn-warning" style="width:45%;height:90px;font-size:50px;">消灯</button>
<script>
var obniz = new Obniz("OBNIZ_ID");
obniz.onconnect = async function () {
var servo = obniz.wired("ServoMotor", {signal:0,vcc:3, gnd:2});
$("#on").on("click",async function(){
servo.angle(100.0);
await obniz.wait(1000);
servo.angle(80.0);
});
$("#off").on("click",async function(){
servo.angle(63.0);
await obniz.wait(1000);
servo.angle(80.0);
});
};
obniz.onclose = async function(){
$("#on").off("click");
$("#off").off("click");
};
</script>​
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.