Skip to content

Instantly share code, notes, and snippets.

@nefo-mi
Created November 15, 2012 21:28
Show Gist options
  • Save nefo-mi/4081397 to your computer and use it in GitHub Desktop.
Save nefo-mi/4081397 to your computer and use it in GitHub Desktop.
シリアルポートに入力があったらTwitterにつぶやく
#include <Bounce.h>
int btPin = 8;
int ledPin = 13;
int pinState = LOW;
Bounce bn = Bounce(btPin, 20);
void setup(){
pinMode(btPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
if(bn.update()){
if(bn.risingEdge()){
digitalWrite(ledPin, HIGH);
Serial.println("push");
}
if(bn.fallingEdge()){
digitalWrite(ledPin, LOW);
Serial.println("off");
}
}
}
#!/usr/bin/env ruby
# encoding : utf-8
require 'twitter'
require 'yaml'
require 'serialport'
sp = SerialPort.new("/dev/tty.usbmodem1421", 9600, 8, 1, SerialPort::NONE)
config_path = File.expand_path(File.dirname(__FILE__) + '/config.yml')
twitter_config = YAML.load_file(config_path)
Twitter.configure do |config|
config.consumer_key = twitter_config[:consumer_key]
config.consumer_secret = twitter_config[:consumer_secret]
config.oauth_token = twitter_config[:oauth_token]
config.oauth_token_secret = twitter_config[:oauth_token_secret]
end
message_path = File.expand_path(File.dirname(__FILE__) + '/message.yml')
message = YAML.load_file(message_path)
while(sp.gets) do
Twitter.update message.sample
end
sp.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment