Created
August 19, 2016 08:21
-
-
Save bathtimefish/274e4103f28bd813aa921c19c0d44f70 to your computer and use it in GitHub Desktop.
CHIRIMENで人感センサー検知LEDなサンプル
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1"> | |
<title>Motion Sensor</title> | |
<!-- https://github.com/club-wot/WebGPIO --> | |
<script src="./bower_components/webgpio/dist/webgpio.js"></script> | |
<!-- https://github.com/mozilla/task.js/blob/master/lib/task.js --> | |
<script src="./js/task.js"></script> | |
<script type="application/javascript;version=1.8" src="./js/main.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or 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
document.addEventListener("DOMContentLoaded", function() { | |
let { spawn, sleep } = task; | |
spawn(function() { | |
const gpio = yield navigator.requestGPIOAccess(); | |
const sensor = gpio.ports.get(196); // Motion Sensor Data Pin: CN1 7 | |
const led = gpio.ports.get(198); // LED Anode Pin: CN1 9 | |
yield sensor.export("in"); | |
yield led.export("out"); | |
while(true) { | |
sensor.onchange = v => { | |
console.info(v); | |
led.write(v); | |
}; | |
yield sleep(1000); | |
} | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment