Skip to content

Instantly share code, notes, and snippets.

@jhonata-menezes
Created June 27, 2017 17:57
Show Gist options
  • Save jhonata-menezes/1efd76409e9c91b9c188d0b351d8f9a0 to your computer and use it in GitHub Desktop.
Save jhonata-menezes/1efd76409e9c91b9c188d0b351d8f9a0 to your computer and use it in GitHub Desktop.
Utilizando a API de sensor de luz com chrome e android
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
Sensor de Luz
<br>
<div id="out"></div>
<script>
let sensor = new AmbientLightSensor();
let out = document.getElementById('out')
sensor.start();
sensor.onchange = function(event) {
out.innerHTML=sensor.illuminance;
};
sensor.onerror = function(event) {
alert(event.error.name + event.error.message);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment