Tweet Thanks Flag

Tweet Thanks Flag

How it works

It shake a flag when someone tweet with hashtag “#obniz”.

Materials

  1. obniz – 1
  2. servomotor – 1
  3. flag – 1
  4. battery or usb adaptor & cable – 1

Code

var Obniz = require('obniz');
var Parts = require('obniz-parts');
var obniz = new Obniz("0000-0000");

var Twitter = require('twitter');
var servo = Parts("ServoMotor");

obniz.onconnect = function(){
  servo.wired(obniz, 3, 4, 5);
  servo.angle(10);
}

var client = new Twitter({
  consumer_key: 'vav8M11NdgAblT6wLtKYNIpKB',
  consumer_secret: 'JN2i0eOrAvGf0y7dwvjbs',
  access_token_key: '9045717536319W5xFvNhfEh0dRS9eisWfrG228Y',
  access_token_secret: 'hGrQZHvulgfWSCAp7C4Aa2nFaz0LhQka'
});

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);
  }
});

Leave a Comment

%d bloggers like this: