Tweet with “#obniz”! Flag will shake!

The flag shake when someone tweets with hashtag “#obniz.”

Materials

  • obniz x1
  • power supply for obniz x1
  • Servo Motor x1
  • flag x1

Steps

Wire a Servo Motor and an obniz like the table and the image below.

obniz Servo Motor
0 signal
1 Vcc
2 GND

Then, attach a flag to the Servo Motor and connect a power to the obniz.

Finally, you execute the program, and tweets with hashtag “#obniz” will make the flag shaking.

Program

This program works with node.js, not a browser.

// Nodejs

var Obniz = require('obniz');
var Twitter = require('twitter');

var obniz = new Obniz("OBNIZ_ID_HERE");
 
obniz.onconnect = function(){
  var servo = obniz.wired("ServoMotor", {signal:0,vcc:1, gnd:2});
  servo.angle(10);
}
 
var client = new Twitter({
  consumer_key: '<ConsumerKey>',
  consumer_secret: '<Secret>',
  access_token_key: '<TokenKey>',
  access_token_secret: '<TokenSecret>'
});
 
var stream = client.stream('statuses/filter',
 {track: '#obniz'});
stream.on('data', function(event) {
  if (event) {
    var count = 0;
    var angles = [10,50,10,50,10,50,10]
    var timer = setInterval(function(){
      count++;
      servo.angle(angles[count]);
      if (count >= 6){
        clearInterval(timer);
      }
    }, 1000);
  }
});
 

 

 

Recommended