Skip to content

Instantly share code, notes, and snippets.

@karledurante
Created August 12, 2013 21:19
Show Gist options
  • Save karledurante/6215387 to your computer and use it in GitHub Desktop.
Save karledurante/6215387 to your computer and use it in GitHub Desktop.
RubyLoco Hack Night: Sphero!
require 'sphero'
require 'pry'
FORWARD = 0
RIGHT = 90
BACKWARD = 180
LEFT = 270
SLOW = 100
FAST = 200
tty = `ls -d /dev/* | grep tty.Sphero`.chomp
puts "Connecting to #{tty}"
Sphero.start tty do
puts ping
binding.pry
# you will now be kicked into an "irb" like session where you can use the commands:
# roll FORWARD, SLOW
# stop
end
@karledurante
Copy link
Author

Change the color of your sphero:

Turn red for 1 second

sphero.rgb 0, 204, 0
sphero.keep_going 1

@karledurante
Copy link
Author

"ping" the sphero and output the result so you know you're connected:

puts sphero.ping

@karledurante
Copy link
Author

# simple circle program
require 'sphero'
require './common'

FORWARD = 0
RIGHT = 90
BACKWARD = 180
LEFT = 270

SLOW = 100
FAST = 200

# you're sphero's serial port
tty = '/dev/tty.Sphero-RWR-RN-SPP'
Sphero.start tty do
    puts ping 

    roll SLOW, FORWARD
    keep_going 1

    roll SLOW, RIGHT
    keep_going 1

    roll SLOW, BACKWARD
    keep_going 1

    roll SLOW, LEFT
    keep_going 1

    roll SLOW, FORWARD
    keep_going 1

    stop
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment