Skip to content

Instantly share code, notes, and snippets.

@todoubled
Last active October 13, 2015 20:07
Show Gist options
  • Save todoubled/4248417 to your computer and use it in GitHub Desktop.
Save todoubled/4248417 to your computer and use it in GitHub Desktop.
Controlling Meatspace With Arduino and Twitter
kue = require 'kue'
jobs = kue.createQueue()
kue.app.enable 'jsonp callback'
assembleJob = (data) ->
type = 'tweet'
jobData =
title:data.text
handle:data.user.screen_name
avatar:data.user.profile_image_url
jobs.create(type, jobData).save()
data = {}
assembleJob data
jobs.process 'tweet', (job, done) ->
done()
arduino = require 'arduino'
# You can figure out your modem path by using the Arduino mac
# software
board = arduino.connect '/dev/tty.usbmodemfa131'
offState = arduino.LOW
onState = arduino.HIGH
# Establish pin 2 as writable
board.pinMode 2, arduino.OUTPUT
board.pinMode 2, offState
# Write the off state to the arduino board
turnOff = (pin) ->
board.digitalWrite pin, offState
# Write the on state to the arduino board
turnOn = (pin) ->
board.digitalWrite pin, onState
# Turn pin 2 on and turn it off after 10 seconds
turnOn 2
setTimeout turnOff, 10000, 2
twitter = require 'ntwitter'
users = ['toddjlarsen']
keys =
consumer_key:process.env.CONSUMER_KEY
consumer_secret:process.env.CONSUMER_SECRET
access_token_key:process.env.ACCCESS_TOKEN_KEY
access_token_secret:process.env.ACCESS_TOKEN_SECRET
onTweet = (stream) ->
stream.on 'data' (tweet) ->
console.dir tweet
twitterAPI = new twitter keys
twitterAPI.stream 'user', track:users, onTweet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment