Created
February 12, 2012 06:36
-
-
Save hatone/1806795 to your computer and use it in GitHub Desktop.
[ruby+ardunio]twitterのリプライをarduinoのLEDで通知する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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