“Like” on Twitter Makes Soap Bubbles Blowed

Make things

The bubble gun will blow soap bubbles each time your tweet gets like on Twitter.

Materials

  • obniz Board
  • power supply for obniz
  • bubble gun
  • soapy water

How to make

Hardware connection

Open the battery case and connect the electrode plate to the obniz Board.

obniz bubble gun
0 positive
1 negative

(Please be careful not to apply excessive voltage.)

Connect the obniz to power, and then dip bubble gun in soapy water.

Software

The bubble gun will blow soap bubbles each time your newest tweet gets like on Twitter.

Apply for a Twitter developer account and be approved in order to use Twitter API. Then, get “consumer_key“, “consumer_secret“, “access_token_key” and access_token_secret. Save as “secret.json” as below and put the file at the same directory as the program.

{
  "consumer_key"        :"YOUR_CONSUMER_KEY",
  "consumer_secret"     :"YOUR_CONSUMER_SECRET",
  "access_token_key"    :"YOUR_ACCESS_TOKEN_KEY",
  "access_token_secret" :"YOUR_ACCESS_TOKEN_SECRET"
}

The program gets the Twitter timeline at this part.

await client.get(
  "statuses/user_timeline",
  async (error, tweets, response) => {
    ...
  }
);

You can get the amount of like of your newest tweet if you write let currentLikeCount = tweets[0].favorite_count; in this function.

Program

This program is written in node.js. Not runnable on the browser.

const fs = require(“fs”); const Obniz = require(“obniz”); const obniz = new Obniz(“OBNIZ_ID_HERE”); const Twitter = require(“twitter”); const client = new Twitter(JSON.parse(fs.readFileSync(“secret.json”, “utf-8”))); let connected = await obniz.connectWait({ timeout: 10 }); const ROTATE_TIME = 1500; const STOP_TIME = 1000; let isBlowing = false; let prevLikeCount = 0; if (connected) { obniz.repeat(async () => { if (isBlowing) { return; } await client.get( “statuses/user_timeline”, async (error, tweets, response) => { if (error) { console.log(error); return; } let currentLikeCount = tweets[0].favorite_count; console.log(“currentLikeCount:” + currentLikeCount); if (currentLikeCount <= prevLikeCount) { console.log("not like added"); prevLikeCount = currentLikeCount; return; } let diffLikeCount = currentLikeCount - prevLikeCount; //blow bubbles depending on like increase await blowBubbles(diffLikeCount); console.log("like added!"); console.log("like count:" + currentLikeCount); prevLikeCount = currentLikeCount; } ); }, 10000); async function blowBubbles(count) { isBlowing = true; for (let i = 0; i < count; i++) { await obniz.com0.output(true); await obniz.com1.output(false); await obniz.wait(ROTATE_TIME); await obniz.com0.output(false); await obniz.wait(STOP_TIME); } isBlowing = false; } }