Created
May 8, 2012 17:24
-
-
Save nefo-mi/2637610 to your computer and use it in GitHub Desktop.
twitterのリプライをArduinoで通知してみた
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
#!/usr/bin/env ruby | |
# encoding : utf-8 | |
require 'userstream' | |
require 'yaml' | |
require 'serialport' | |
sp = SerialPort.new("/dev/ttyACM0", 9600, 8, 1, SerialPort::NONE) | |
stream_config = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/config.yml')) | |
UserStream.configure do |config| | |
config.consumer_key = stream_config[:consumer_key] | |
config.consumer_secret = stream_config[:consumer_secret] | |
config.oauth_token = stream_config[:oauth_token] | |
config.oauth_token_secret = stream_config[:oauth_token_secret] | |
end | |
client = UserStream.client | |
client.user do |status| | |
if status.has_key? "text" | |
if status.in_reply_to_screen_name == "nefo_mi" | |
sp.puts "@#{status.user.screen_name} " | |
end | |
end | |
end | |
sp.close |
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
#include <LiquidCrystal.h> | |
int incomingByte; | |
char inByte; | |
String inMsg; | |
boolean led; | |
int light; | |
LiquidCrystal lcd(7,8,9,10,11,12,13); | |
void setup() | |
{ | |
lcd.begin(2, 16); | |
lcd.clear(); | |
lcd.print("Twitter Mention"); | |
lcd.setCursor(0, 1); | |
lcd.print("Notification"); | |
Serial.begin(9600); | |
Serial.println("setupDone"); | |
led = false; | |
light = 0; | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
inByte = Serial.read(); | |
if((inByte >= 65 && inByte <= 90) || (inByte >= 97 && inByte <= 122) | |
|| (inByte >= 48 && inByte <= 57) || (inByte == 64) || (inByte == 95)){ | |
inMsg.concat(inByte); | |
} | |
if (inByte == 10 || inByte == 13){ | |
inByte = 0; | |
lcd.clear(); | |
lcd.print(inMsg); | |
inMsg = ""; | |
led = true; | |
light = 0; | |
} | |
} | |
if (led){ | |
if (light % 2 == 0){ | |
digitalWrite(5, HIGH); | |
digitalWrite(6, LOW); | |
}else{ | |
digitalWrite(5, LOW); | |
digitalWrite(6, HIGH); | |
} | |
delay(500); | |
if(++light >= 100){ | |
led = false; | |
digitalWrite(5, LOW); | |
digitalWrite(6, LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment