Skip to content

Instantly share code, notes, and snippets.

@bathtimefish
Created August 19, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bathtimefish/274e4103f28bd813aa921c19c0d44f70 to your computer and use it in GitHub Desktop.
Save bathtimefish/274e4103f28bd813aa921c19c0d44f70 to your computer and use it in GitHub Desktop.
CHIRIMENで人感センサー検知LEDなサンプル
<!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>
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