Module Commands
In: lib/commands.rb

Command object based interface that implements the "blocks" in NXT-G. This should be easy to understand if you are familiar with the NXT-G graphical programming system. This is automatically included in NXTComm.


  require 'nxt_comm'

  @nxt ='/dev/tty.NXT-DevB-1')

  # more examples can be found in examples/commands.rb

  us =
  us.mode = :centimeters
  puts "Distance: #{us.distance}cm"
  us.mode = :inches
  puts "Distance: #{us.distance}in"

  us.comparison = "<"
  us.trigger_point = 5

  while us.logic == false
    puts "Move #{us.comparison} #{us.trigger_point} #{us.mode} from the sensor..."
    puts "Distance: #{us.distance}in"

  puts "Got it!"

Classes and Modules

Class Commands::LightSensor
Class Commands::Motor
Class Commands::Move
Class Commands::RotationSensor
Class Commands::Sound
Class Commands::SoundSensor
Class Commands::TouchSensor
Class Commands::UltrasonicSensor