Moheeb ZaraChris Matthieu
Published © MIT

Lightblue Bean + Button + Octoblu

Attach a button to Octoblu!

Full instructions provided3,562
Lightblue Bean + Button + Octoblu

Things used in this project

Hardware components

Light Blue Bean
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wire (any small length of wire will do)
×1
4-pin push button that fits on the bean
×1
Soldering Kit
×1

Story

Read more

Code

file_9750.txt

C/C++
void setup() 
{
  Serial.begin(57600);
  pinMode(4,INPUT);
}
 
 
// the loop routine runs over and over again forever:
void loop() 
{
  uint8_t buffer[2];
  
  uint16_t d0 = digitalRead(4);
 
  
  buffer[0] = d0 & 0xFF;
  buffer[1] = d0 >> 8;
  
  Bean.setScratchData(1, buffer, 2);
  
  
  Bean.sleep(1000);
}  

file_9747.js

JavaScript
npm install johnny-fivenpm install bean-ionpm install meshblunode file_9747.js
var five = require("johnny-five");
var beanio = require("bean-io");
var meshblu = require('meshblu');

var conn = meshblu.createConnection({
  "uuid": "f0af1a01-fd5d-11e3-a290-ef9910e207d9",
  "token": "0wyjcbbffnely2e29zuz9ygnoaymygb9",
  "protocol": "websocket",
  "server": "meshblu.octoblu.com",
  "port": 80
});

conn.on('notReady', function(data){
  console.log('UUID FAILED AUTHENTICATION!');
  console.log(data);
});

conn.on('ready', function(data){
  console.log('UUID AUTHENTICATED!');
  console.log(data);

  var board = new five.Board({
    io: new beanio.Board()
  });

  board.on("ready", function() {
    console.log("Bean Ready...");

    var button = new five.Button(12);

    // "down" the button is pressed
    button.on("down", function() {
      console.log("down");
      conn.message({
        "devices": "*",
        "payload": {
          "button":"down"
        }
      });      
    });

    // "hold" the button is pressed for specified time.
    //        defaults to 500ms (1/2 second)
    //        set
    button.on("hold", function() {
      console.log("hold");
      conn.message({
        "devices": "*",
        "payload": {
          "button":"hold"
        }
      });      

    });

    // "up" the button is released
    button.on("up", function() {
      console.log("up");
      conn.message({
        "devices": "*",
        "payload": {
          "button":"up"
        }
      });      
    });

  });

});

Credits

Moheeb Zara

Moheeb Zara

39 projects • 136 followers
Developer Advocate at EMQ Technologies - . Co-founder - South West Maker Festival. Hardware hacker, artist, robots, HeatSync Labs
Chris Matthieu

Chris Matthieu

2 projects • 16 followers
Creator of SkyNet.im, Octoblu.io, Computes.com.Developer Evangelist for Intel RealSense Cameras.

Comments