Open narita2 opened 6 years ago
<script src="https://mz4u.net/libs/gc2/polyfill.js"></script>
<script src="https://mz4u.net/libs/gc2/i2c-ADT7410.js"></script>
<div id="detection"></div>
#detection{
width:60px;
height:60px;
border-radius:30px;
background-color:black;
}
(async ()=>{
var detection = document.getElementById('detection');
navigator.requestGPIOAccess().then( (gpioAccess)=>{
var port = gpioAccess.ports.get(18);
await.port.export("out").then( ()=>{
setInterval(function(){
var ^= 1;
port.write(v);
detection.style.backgroundColor = (v)? "red" : "black";
}, 2000);
});
});
})();
(()=>{
var detection = document.getElementById('detection');
navigator.requestGPIOAccess().then( (gpioAccess)=>{
var port = gpioAccess.ports.get(18);
port.export("out").then( ()=>{
setInterval( function(){
var ^= 1;
port.write(v);
detection.style.backgroundColor = (v)? "red" : "black";
}, 2000);
});
};
})();
(async()=>{
navigator.requestGPIOAccess().then( gpioAccess=>{
var ledport = gpioAccess.ports.get(26);
var dport = gpioAccess.ports.get(18);
var v = 0;
return dport.export("out").then( ()=>{
setInterval( function(){
v ^= 1;
ledport.write(v);
}, 2000);
});
});
})();
(()=>{
navigator.requestGPIOAccess().then((gpioAccess)=>{
var ledport = gpioAccess.ports.get(26);
var dport = gpioAccess.ports.get(18);
return dport.export("out").then(()=>{
setInterval(function()=>{
v ^= 1;
ledport.write(v);
},2000);
});
});
})();
緑色のピンを、Webアプリから利用可能なGPIOとして設定している GPIOとは_Qiita
(async()=>{
var sleep = (ms)=>{
return new Promise((resolve)=>setTimeout(resolve,ms));
}
navigator.requestGPIOAccess().then((gpioAccess)=>{
var ledport = gpioAccess.ports.get(26);
var dport = gpioAccess.ports.get(5);
var v = 0;
await dport.export("in").then(()=>{
ledport.write(v) = (v == 1) ? 1 : 0;
});
});
})();
GPIOポート番号 26を指定してportオブジェクトを取得
GPIOポート番号 5を指定してportオブジェクトを取得
SB412A
<div id="viewMessage"></div>
<script src="https://mz4u.net/libs/gc2/polyfill.js"></script>
#viewMessage{
width:60px;
height:60px;
border-radius:30px;
background-color:black;
}
(async ()=>{
var viewMessage = document.getElementById("viewMessage");
var gpioAccess = await navigator.requestGPIOAccess();
var port = gpioAccess.ports.get(5); //人感センサのポート
function detection(v){
if(v === 0){
port.write(0);
viewMessage.style.backgroundColor = "black";
}else{
port.write(1);
viewMessage.style.backgroundColor = "blue";
}
}
})();
(async()=>{
var sleep = (ms)=>{
return new Promise((resolve)=>setTimeout(resolve,ms));
}
var viewMessage = document.getElementById("viewMessage");
var gpioAccess = await navigator.requestGPIOAccess();
var port = gpioAccess.ports.get(5); //人感センサのポート
function detection(v){
if(v === 0){
port.write(0);
viewMessage.style.backgroundColor = "black";
}else{
port.write(1);
viewMessage.style.backgroundColor = "red";
}
}
while(1){
var val = await port.read();
val ^= 1;
function(val);
await sleep(100);
}
})();
(async ()=>{
var slepp = (ms)=>{
return new Promise((resolve)=>setTimeout(resolve,ms));
};
var viewMessage = document.getElementById("viewMessage");
var gpioAccess = await navigator.requestGPIOAccess();
var port = gpioAccess.ports.get(12); //人感センサのポート
function detection(v){
if(v === 0){
port.write(0);
viewMessage.style.backgroundColor = "black";
}else{
port.write(1);
viewMessage.style.backgroundColor = "red";
}
})();
}
})();
(async()=>{
var slepp = (ms)=>{
return new Promise((resolve)=>setTimeout(resolve,ms));
};
var viewMessage = document.getElementById("viewMessage");
var gpioAccess = await navigator.requestGPIOAccess();
var port = gpioAccess.ports.get(12); //人感センサのポート
function detection(v){
if(v === 0){
port.write(0);
viewMessage.style.backgroundColor = "black";
}else{
port.write(1);
viewMessage.style.backgroundColor = "red";
}
})();
<div id="viewMessage"></div>
<script src="https://mz4u.net/libs/gc2/polyfill.js"></script>
#viewMessage{
width:60px;
height:60px;
border-radius:30px;
background-color:black;
}
<!DOCTYPE html>
<!--
Created using JS Bin
http://jsbin.com
Copyright (c) 2018 by anonymous (http://jsbin.com/qayerabapa/1/edit)
Released under the MIT license: http://jsbin.mit-license.org
-->
<meta name="robots" content="noindex">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
#viewMessage{
width:60px;
height:60px;
border-radius:30px;
background-color:black;
}
</style>
</head>
<body>
<div id="viewMessage"></div>
<script src="https://mz4u.net/libs/gc2/polyfill.js"></script>
<script id="jsbin-javascript">
(async ()=>{
var slepp = (ms)=>{
return new Promise((resolve)=>setTimeout(resolve,ms));
};
var viewMessage = document.getElementById("viewMessage");
var gpioAccess = await navigator.requestGPIOAccess();
var port = gpioAccess.ports.get(12); //人感センサのポート
function detection(v){
if(v === 0){
port.write(0);
viewMessage.style.backgroundColor = "black";
}else{
port.write(1);
viewMessage.style.backgroundColor = "red";
}
}
port.onchange
})();
</script>
</body>
</html>
参考にしたページ1
参考にしたページ2
参考にしたページ3
参考にしたページ4
参考に?ページ