Created
September 9, 2012 22:37
-
-
Save msonnabaum/3687733 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
#!/usr/bin/env ruby | |
require 'serialport' | |
class Maestro | |
def initialize | |
@sp = SerialPort.new("/dev/ttyACM0") | |
end | |
def send(servo, position) | |
mess = "#{0x84.chr}#{servo.chr}#{(position & 0x7f).chr}#{((position >> 7) & 0x7F).chr}" | |
@sp.write mess | |
end | |
end | |
m = Maestro.new | |
loop do | |
(4000..8000).step(10) do |n| | |
m.send(0, n) | |
sleep 0.05 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment