Skip to content

Instantly share code, notes, and snippets.

@colegleason
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save colegleason/9768806 to your computer and use it in GitHub Desktop.
Save colegleason/9768806 to your computer and use it in GitHub Desktop.
[wearscript] Magnet
<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>
function isActive(sensor, threshold) {
for (var i =0; i < sensor.values.length; i++) {
if (Math.abs(sensor.values[i]) > threshold)
return true;
}
return false
}
function server() {
WS.log('Welcome to WearScript');
WS.say('Magnetometer');
WS.sound('SUCCESS')
WS.sensorOn('magneticField', .15, function(magnet) {
if (isActive(magnet, 90)) {
WS.say("magnet");
}
WS.publish('magnet', magnet)
});
WS.dataLog(false, true, .15);
}
function main() {
if (WS.scriptVersion(1)) return;
WS.serverConnect('{{WSUrl}}', server);
}
window.onload = main;
</script>
</body>
</html>
{
"name":"Magnet",
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment