Created
December 7, 2018 14:26
-
-
Save yasugahira0810/2c4156e731a1501358d44250157efcdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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