Skip to content

Instantly share code, notes, and snippets.

@scottgwald
Last active November 14, 2015 04:33
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 scottgwald/106c61c90479cbeab418 to your computer and use it in GitHub Desktop.
Save scottgwald/106c61c90479cbeab418 to your computer and use it in GitHub Desktop.
[wearscript] Light Sensor
<html style="width:100%; height:100%; overflow:hidden">
<head>
<!-- You can include external scripts here like so... -->
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>-->
</head>
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<canvas id="canvas" width="640" height="360" style="display:block"></canvas>
<script>
var isLightSensorOn = false;
function myLightSensorOn() {
isLightSensorOn = true;
WS.say("light sensor on");
WS.sensorOn('light', 0.5);
WS.dataLog(false, true, 0.5);
}
function myLightSensorOff() {
isLightSensorOn = false;
WS.say("light sensor off");
WS.sensorOff( 5 );
WS.dataLog(false, false, 0.5);
}
WS.gestureCallback('onGestureTAP', function() {
isLightSensorOn ? myLightSensorOff() : myLightSensorOn();
});
function server() {
console.log("Server connected");
myLightSensorOn();
}
function main() {
if (WS.scriptVersion(1)) return;
ctx = document.getElementById('canvas').getContext("2d");
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script>
</body>
</html>
{ "name" : "Light Sensor" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment