PKpwJ7s< index.html I2Cテスト (温度計:ADT7410) - js do it
Connect
SBBLE / FirmaSBBLE / konashi
Connecting...
00 . 0
Temperature
PKpwJ #+ + index.js// forked from micutil's "FirmaSBBLE (浜サブレー) I2Cテスト (温度計:ADT7410) " http://jsdo.it/micutil/5aN2 // forked from kogyu's "forked: Samples.ReadSignalStrength+LEDBlink" http://jsdo.it/kogyu/A60R // forked from reo.matsumura's "Samples.ReadSignalStrength+LEDBlink" http://jsdo.it/reo.matsumura/bC4N // forked from reo.matsumura's "Samples.ReadSignalStrength" http://jsdo.it/reo.matsumura/dPQE ///////////////////////////////////// // view functions ///////////////////////////////////// $(function(){ $("#button").tap(function(){ k.find(); }); }); function showFirst(){ $("#content").animate( {left: "0%"}, {duration: 500, easing: "ease-in-out"} ); } function showConnecting(){ $("#content").animate( {left: "-100%"}, {duration: 500, easing: "ease-in-out"} ); } function showMeter(){ $("#content").animate( {left: "-200%"}, {duration: 500, easing: "ease-in-out"} ); } function changeMeter(value){ $("#meter").animate( {height: value + "%"}, {duration: 500, easing: "ease-in-out"} ); //$("#num").html(value); } ///////////////////////////////////// // konashi functions ///////////////////////////////////// var intervalId; var tempcr=0; var tempar=0; var tempbr=0; var ADDR=0x48; k.ready(function(){ showMeter(); //I2Cを有効にする k.i2cMode(k.KONASHI_I2C_ENABLE_400K); k.i2cStartCondition(); k.i2cWrite(1, 0x00, ADDR); k.i2cStopCondition(); intervalId = window.setInterval(function(){ k.i2cStartCondition(); k.i2cWrite(1, 0x00, ADDR); k.i2cRestartCondition(); k.i2cReadRequest(2, ADDR); }, 1000); }); k.on(k.KONASHI_EVENT_CONNECTED, function(){ showConnecting(); }); k.completeReadI2c(function(){ k.i2cStopCondition(); k.i2cRead(2, function(value){ tempcr=(value[0]*256+value[1]); tempar=Math.floor( tempcr/128 ); tempbr=Math.floor( (10*(tempcr-tempar*128))/128 ); }); //tempar=Math.floor( tempcr/128 ); changeMeter(Math.floor( tempar*1.2 )); $("#num").html(tempar); $("#num2").html(tempbr); }); k.disconnected(function(data){ window.clearInterval(intervalId); showFirst(); });PKpwJ3( style.css@font-face { font-family: 'icomoon'; src:url('http://jsrun.it/assets/s/m/w/y/smwyM'); src:url('http://jsrun.it/assets/s/m/w/y/smwyM?#iefix') format('embedded-opentype'), url('http://jsrun.it/assets/k/y/D/Z/kyDZo') format('woff'), url('http://jsrun.it/assets/a/D/a/t/aDati') format('truetype'), url('http://jsrun.it/assets/x/Q/J/L/xQJL1#icomoon') format('svg'); font-weight: normal; font-style: normal; } /* Use the following CSS code if you want to use data attributes for inserting your icons */ [data-icon]:before { font-family: 'icomoon'; content: attr(data-icon); speak: none; font-weight: normal; font-variant: normal; text-transform: none; line-height: 1; -webkit-font-smoothing: antialiased; } * { -webkit-touch-callout: none; -webkit-user-select: none; margin: 0; padding: 0; border: 0; font-family: sans-serif; font-weight: bold; color: #FFF; } #content { position: fixed; width: 100%; height: 100%; left: 0%; top: 0px; } #first { position: absolute; width: 100%; height: 100%; left: 0px; top: 0px; background: #77AABB; } #konashijs_logo { position: absolute; width: 150px; height: 28px; left: 50%; top: 80px; margin-left: -75px; background: url(http://jsrun.it/assets/L/I/q/X/LIqXY.png); background-size: contain; background-repeat: no-repeat; } #robomic_logo { position: absolute; width: 185px; height: 40px; left: 50%; top: 120px; margin-left: -92px; background: url(http://micutil.com/logo/30_2.png); background-size: contain; background-repeat: no-repeat; } #button { position: absolute; top: 50%; left: 50%; width: 280px; height: 80px; margin-top: -40px; margin-left: -140px; background: #e74c3c; text-align: center; line-height: 40px; font-size: 16px; cursor: pointer; } #button_icon { font-family: "icomoon"; } #button_icon:before { content: "\e001"; } #connecting { position: absolute; width: 100%; height: 100%; left: 100%; top: 0px; background: #34495e; } #connecting_title { position: absolute; width: 200px; height: 100px; left: 50%; top: 50%; margin-left: -100px; margin-top: -50px; text-align: center; line-height: 100px; font-size: 30px; } #main { position: absolute; width: 100%; height: 100%; left: 200%; top: 0px; background: #34495e; } #meterbkg { position: absolute; width: 16px; top: 80px; bottom: 50px; left: 36px; background: #FFFFFF; } #meterbkgCircW { position: absolute; border-radius: 50%; height: 32px; width: 32px; bottom: 46px; left: 28px; background: #FFFFFF; } #meterbkgCircR { position: absolute; border-radius: 50%; height: 24px; width: 24px; bottom: 50px; left: 32px; background: #e74c3c; } #meter { position: absolute; width: 8px; height: 0%; bottom: 60px; left: 40px; background: #e74c3c; } #value { position: absolute; top: 50%; left: 50%; width: 300px; height: 300px; margin-top: -150px; margin-left: -150px; font-size: 50px; line-height: 300px; text-align: center; } #num { font-size: 70px; margin: 0px -15px; } #num2 { font-size: 30px; margin: 0px -15px; } #title { position: absolute; top: 40px; left: 20px; font-size: 25px; } #title_icon { font-family: "icomoon"; } #title_icon:before { content: "\e000"; } PKpwJ7s< index.htmlPKpwJ #+ + 7index.jsPKpwJ3( style.cssPKn