Created
August 4, 2015 19:23
-
-
Save nanosplit/b11b33b94d3ad16dd603 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 'sinatra' | |
require 'sinatra/activerecord' | |
require './config/environments' | |
require './models/flick' | |
require 'pi_piper' | |
include PiPiper | |
set :bind, '192.168.1.75' | |
set :port, '5678' | |
Thread.new do | |
distance = 10 | |
loop do sleep 1 | |
PiPiper.watch :pin => pin1 do | |
pin1_time = Time.now | |
end | |
PiPiper.watch :pin => pin2 do | |
pin2_time = Time.now | |
end | |
time_diff = pin2_time - pin1_time | |
flick_speed = distance / time_diff | |
Flick.create!(speed: flick_speed) | |
end | |
end | |
get '/' do | |
@flicks = Flick.all | |
erb :flicks | |
end | |
get "/flick/:id" do | |
@flick = Flick.find_by_id(params[:id]) | |
erb :flick | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment