On Github mimming / synchronizing-state
Created by Jenny Tong / mimming.com / @MimmingCodes
A tiny app company that specalizes in solving important problems across many platforms.
var five = require("johnny-five");
var Firebase = require("firebase");
var board = new five.Board();
// Connect to Firebase
var myFirebaseRef =
    new Firebase("https://fruit.firebaseio-demo.com/");
board.on("ready", function() {
  // Set up the Adruino
  var fruit = new five.Sensor({
    pin: "A2",
    freq: 250
  });
  board.repl.inject({ sensor: fruit });
  ...
    // When the voltage changes, do math
  fruit.scale([0, 1024]).on("data", function() {
    var voltage = this.raw / 1024 * 5;
    var fruitType = "unknown";
    if(this.raw < 20) {
      fruitType = "none";
    } else if(this.raw >= 20 && this.raw < 92) {
      fruitType = "orange";
    } else if(this.raw >= 92 ) {
      fruitType = "apple";
    }
    // Save to to Firebase and alert all listeners
    myFirebaseRef.set({"type":fruitType, "voltage":voltage});
  });
});
    // Connect to Firebase
var fruitRef =
    new Firebase("https://fruit.firebaseio-demo.com/");
// Listen for fruit changes
fruitRef.on("value", function(snapshot) {
  var fruitType = snapshot.val();
  $("#fruit-type").html(fruitType.type);
});
    let ref = Firebase(url:"https://fruit.firebaseio-demo.com/")
ref.observeEventType(.Value, withBlock: {
  snapshot in
  let fruit = "\(snapshot.value)"
  self.textView.text = fruit
  if(fruit == "apple") {
    self.imageView.image = UIImage(named: "apple");
  } else if(fruit == "orange") {
    self.imageView.image = UIImage(named: "orange");
  }
})
    protected void onResume() {
  Firebase ref = new Firebase("https://fruit.firebaseio-demo.com/");
  // Find the ImageView
  final ImageView fruitImageView =
          (ImageView)findViewById(R.id.fruit_image);
  // Listen for changes
  ref.child("type").addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
      String fruitType = snapshot.getValue(String.class);
      if(fruitType.equals("orange")) {
        fruitImageView.setImageResource(R.drawable.orange);
      } else ...
    }
  });
}
    mimming.com/presos/synchronizing-state
github.com/mimming/synchronizing-state
github.com/mimming/firebase-fruit-detector
Created by Jenny Tong / mimming.com / @MimmingCodes