Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FirebaseでLチカしてみた

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 FirebaseでLチカしてみた

Avatar for Tomohiko Himura

Tomohiko Himura

September 15, 2016
Tweet

More Decks by Tomohiko Himura

Other Decks in Programming

Transcript

  1. ブラウザ側 var keypath = "switch" // DBʹswitchͱ͍͏໊લͰอଘ var switchRef =

    firebase.database().ref(keypath); var buttonState = null; var button = document.getElementById("button"); button.addEventListener('click', function(){ switchRef.set(!buttonState); // ΫϦοΫ͞ΕͨΒOn/Offτάϧ }); switchRef.on('value', function(sw) { buttonState = sw.val(); // ஋ͷมߋΛड͚औͬͨΒऔಘͯ͠දࣔ੾Γସ͑ if (buttonState) { button.innerHTML = '఺౮த'; button.style.background = "rgb(3,155,229)"; } else { button.innerHTML = 'ফ౮த'; button.style.background = "rgb(155,155,155)"; } });
  2. Arduino側 var board = new five.Board(); board.on("ready", function() { var

    led = new five.Led(13); led.off(); firebase.database().ref("switch").on('value', function(sw) { buttonState = sw.val(); //஋͕ߋ৽͞ΕͨΒ൓ө if (buttonState) { led.on(); } else { led.off(); } }); });