Sha256: 6a17584b82eee2009469762f301ba7428255240bdb31a6d29d000ce0d74c7c76

Contents?: true

Size: 669 Bytes

Versions: 3

Compression:

Stored size: 669 Bytes

Contents

require 'artoo'

connection :sphero, :adaptor => :sphero, :port => '/dev/rfcomm0' #linux
#connection :sphero, :adaptor => :sphero, :port => '127.0.0.1:4567'
device     :sphero, :driver  => :sphero

connection :pebble, :adaptor => :pebble
device     :watch,  :driver  => :pebble, :name => 'pebble'

api :host => '0.0.0.0', :port => '8080'

name 'pebble'

work do
  on pebble, :accel => :set_direction

  every(1.seconds) do
    sphero.roll 100, heading
  end
end

def set_direction(*data)
  x, y = data[1].split(",")

  @heading = direction(x.to_i, y.to_i)
end

def direction(x, y)
  (180.0 - (Math.atan2(y,x) * (180.0 / Math::PI)))
end

def heading
  @heading || 0
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
artoo-sphero-1.5.1 examples/sphero_pebble_accelerometer.rb
artoo-sphero-1.5.0 examples/sphero_pebble_accelerometer.rb
artoo-sphero-1.4.0 examples/sphero_pebble_accelerometer.rb