Skip to content

Instantly share code, notes, and snippets.

@hatone
Created February 12, 2012 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatone/1806795 to your computer and use it in GitHub Desktop.
Save hatone/1806795 to your computer and use it in GitHub Desktop.
[ruby+ardunio]twitterのリプライをarduinoのLEDで通知する
int incomingByte = 0;
int ledPin = 13; //ardunioのLEDは13番ピン
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
for(int i= 0; i< (incomingByte - 48); i++ )
{
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
}
require 'rubygems'
require 'serialport'
require 'twitter'
require 'pp'
require 'date'
Twitter.configure do |config|
config.consumer_key = 'hoge'
config.consumer_secret = 'hoge'
config.oauth_token = 'hoge'
config.oauth_token_secret = 'hoge'
end
men = Twitter.mentions
port = "/dev/cu.usbmodemfd121"
open("twitid.txt") {|id|
LASTID = id.readlines.first.to_i
}
sp = SerialPort.new(port, 9600, 8, 1, SerialPort::NONE)
if LASTID != men.last.id
print "new mention \n"
f = File.open("twitid.txt",'w')
f.print men.last.id.to_s
f.close
start = Time.now.sec
now = start
while true
line = '9'
sp.putc line
sleep(1)
now = Time.now.sec
break if now > start+5
end
end
sp.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment