potar
var led1 = document.getElementById("led1"); var device = null; spark.on('login', function(){ //list devices spark.listDevices(function(err, devices) { device = devices[3]; console.log('Device name: ' + device.name); console.log('- connected?: ' + device.connected); console.log('- variables: ' + device.variables); console.log('- functions: ' + device.functions); console.log('- version: ' + device.version); console.log('- requires upgrade?: ' + device.requiresUpgrade); }); led1.onmouseenter = function(){ if(device !== null ){ led1.style.background = "#00F"; device.callFunction('led', 'on', function(err, data) { if (err) { console.log('An error occurred:', err); } else { console.log('Function called succesfully:', data); } } ); } }; led1.onmouseleave = function(){ if(device !== null ){ led1.style.background = "#000"; device.callFunction('led', 'off', function(err, data) { if (err) { console.log('An error occurred:', err); } else { console.log('Function called succesfully:', data); } }); } }; }); spark.login({accessToken: ''}); var potar = document.getElementById("potar"); var t=0; ( function getPotar(){ requestAnimationFrame(getPotar); t++; if(t%20 === 0){ if(device !== null){ device.getVariable('potarValue', function(err, data) { if (err) { // console.log('An error occurred while getting attrs:', err); } else { // console.log('Device attr retrieved successfully:', data); potar.style.borderLeft = "solid #000 " + Math.floor(data.result/10) +"px"; } }); } } } )();