-
-
Save maxhawkins/3bbbafd00eb89b40ecf3 to your computer and use it in GitHub Desktop.
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' | |
HUG_THRESHOLD = 0.85 | |
hug_bot = SerialPort.new "/dev/tty.usbserial-A4001hsG", 9600 | |
httpauth = Twitter::HTTPAuth.new('pillowtweets', '--password--') | |
@client = Twitter::Base.new(httpauth) | |
def tweet_a_hug(name) | |
phrases = ["Tell me about it, #{name}!", "It's OK, #{name}. Let it all out.", "There, there, #{name}.", | |
"Now that feels better, doesn't it #{name}?", "Just take a deep breath, #{name}.", | |
"Isn't this nice, #{name}?", "#{name}, we should do this more often.", | |
"You're the best, #{name}!", "#{name}, I wish this hug could last forever.", | |
"I completetely understand, #{name}.", "I feel you, #{name}.", | |
"Don't worry, #{name}. everything is gonna be all right."] | |
begin | |
@client.update(phrases[rand(phrases.size)]) | |
rescue | |
end | |
end | |
print "Please enter your name: " | |
name = gets.chomp | |
puts "Calibrating. Don't hug the pillow just yet!" | |
calibration_values = [] | |
15.times do | |
calibration_values << hug_bot.getc | |
end | |
sum = calibration_values.inject(0){|s,v| s+=v } | |
average = sum / calibration_values.size | |
puts "Ready to go. Hug away!" | |
hugging = false | |
loop do | |
fan_value = hug_bot.getc | |
if(fan_value < HUG_THRESHOLD * average) | |
if(!hugging) | |
puts "We gots a hug! Preparing a tweet just for you, #{name}." | |
tweet_a_hug(name) | |
hugging = true | |
end | |
else | |
hugging = false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment