Created
December 15, 2012 08:44
-
-
Save jewel12/4292185 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
int incomingByte = 0; | |
int firstLedPinNum = 10; | |
int lastLedPinNum = 13; | |
int ledBlinkFactorSec = 100 | |
void setup() { | |
Serial.begin(9600); | |
for(int i = firstLedPinNum; i <= lastLedPinNum; i++) { | |
pinMode(i, OUTPUT); | |
} | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
incomingByte = Serial.read(); | |
int ledBlinkTime = incomingByte * ledBlinkFactorSec; | |
while(Serial.available() == 0) { | |
for(int i=firstLedPinNum; i <= lastLedPinNum; i++) { | |
digitalWrite(i, HIGH); | |
delay(ledBlinkTime); | |
digitalWrite(i, LOW); | |
} | |
} | |
} | |
} |
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 'serialport' | |
require File.expand_path(File.dirname(__FILE__)) + "/tweet_counter" | |
class TLVelocitySender | |
def initialize(serial_port_path) | |
@serial_port_path = serial_port_path | |
@measure = TweetCounter.new | |
@max_velocity = 10 | |
end | |
def periodically_send(period_sec) | |
sp = SerialPort.new(@serial_port_path, 9600) | |
@measure.start_periodic_count(period_sec) do |count| | |
velocity = count > @max_velocity ? @max_velocity : count | |
led_blink_time = (@max_velocity - velocity) + 1 | |
sp.print led_blink_time.chr | |
end | |
end | |
end | |
if __FILE__ == $0 | |
sender = TLVelocitySender.new("/dev/tty.usbmodem1431") | |
sender.periodically_send(30) | |
end |
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 "tweetstream" | |
class TweetCounter | |
def initialize | |
TweetStream.configure do |config| | |
config.consumer_key = '__CONSUMER_KEY__' | |
config.consumer_secret = '__CONSUMER_SECRET__' | |
config.oauth_token = '__OAUTH_TOKEN__' | |
config.oauth_token_secret = '__OAUTH_TOKEN_SECRET__' | |
config.auth_method = :oauth | |
end | |
@tweet_counter = 0 | |
end | |
def start_periodic_count(period_sec) | |
Thread.new do | |
loop do | |
sleep(period_sec) | |
yield @tweet_counter | |
@tweet_counter = 0 | |
end | |
end | |
TweetStream::Client.new.userstream do |status| | |
warn status.text | |
@tweet_counter += 1 | |
end | |
end | |
end | |
if __FILE__ == $0 | |
measure = TweetCounter.new | |
measure.start_periodic_count(10) {|velocity| puts velocity } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment