Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
lego nxt sample script
$LOAD_PATH.unshift('./lib').uniq!
require 'lego_nxt/usb_connection'
require 'lego_nxt/constants'
@subject = LegoNXT::UsbConnection.new
ops = [LegoNXT::DirectOps::NO_RESPONSE,
LegoNXT::DirectOps::PLAYTONE,
500,
500].pack('CCvv')
@subject.transmit(ops)
@subject.close
@subject = LegoNXT::UsbConnection.new
motor_activate = [LegoNXT::DirectOps::NO_RESPONSE,
LegoNXT::DirectOps::SETOUTPUTSTATE,
0xFF, # output port
100, # power set point
0x01, # mode; 0x01 => Motor On
0x00, # Regulation Mode
0, # Turn Ratio (-100 - 100)
0x20, # Run State? - Idle/Ramp-up/Running/Ramp-down
1000].pack('C*') # TachoLimit (run time?)
puts motor_activate.inspect
@subject.transmit(motor_activate)
@subject.close
sleep 0.5
@subject = LegoNXT::UsbConnection.new
motor_activate = [LegoNXT::DirectOps::NO_RESPONSE,
LegoNXT::DirectOps::SETOUTPUTSTATE,
0xFF, # output port
-100, # power set point
0x01, # mode; 0x01 => Motor On
0x00, # Regulation Mode
0x00, # Turn Ratio (-100 - 100)
0x20, # Run State? - Idle/Ramp-up/Running/Ramp-down
1000].pack('C*') # TachoLimit (run time?)
puts motor_activate.inspect
@subject.transmit(motor_activate)
@subject.close
sleep 0.5
@j3j3

This comment has been minimized.

Copy link

commented May 16, 2012

{comment}

@j3j3

This comment has been minimized.

Copy link

commented May 16, 2012

I'm inside you.

@j3j3

This comment has been minimized.

Copy link

commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.