Class: ServoCalibrateContinuous

Inherits:
ArduinoSketch show all
Defined in:
lib/examples/servo_calibrate_continuous.rb

Instance Attribute Summary

Attributes inherited from ArduinoSketch

#pins

Instance Method Summary collapse

Methods inherited from ArduinoSketch

#add, add_to_setup, #array, #assembler, #comment_box, #compose_setup, #define, #delay, #digitalWrite, #formatted_print, #initialize, #input_pin, #input_pins, output_pin, #output_pin, post_process_ruby_to_c_methods, pre_process, #serial_begin

Methods included from ExternalVariableProcessing

#c_type, #check_variable_type, #post_process_arrays, #post_process_vars, #pre_process_vars, #process_external_vars, #translate_variables

Constructor Details

This class inherits a constructor from ArduinoSketch

Instance Method Details

#delay_servo(t) ⇒ Object



85
86
87
88
89
90
# File 'lib/examples/servo_calibrate_continuous.rb', line 85

def delay_servo(t)
  t.times do
    delay 1
    servo_refresh
  end
end

#loopObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/examples/servo_calibrate_continuous.rb', line 50

def loop
  if @test_state == 2

    40.times { blink led, 50 }    # 40 x 50 ms is a 2 second blinking light
                                  #  ** Warning! **  "... danger Will Robinson!"
    toggle led                    # turn it on keep it on -- keep hands away
    servo1.speed -90
    servo2.speed -90
    servo3.speed -90
    servo4.speed -90
    delay_servo 2000              # two full seconds max clockwise
    servo1.speed 90
    servo2.speed 90
    servo3.speed 90
    servo4.speed 90
    delay_servo 2000              # two full seconds max counter clockwise
    
    @test_state = 1               # setup for zero speed test/adjust
    @cycle_time = millis + 20000
    servo1.speed 0
    servo2.speed 0
    servo3.speed 0
    servo4.speed 0
    toggle led                    # lights off, OK  you have 20 seconds to adjust
  end

  if @cycle_time - millis <= 0
      @test_state = 2
  else
      servo_refresh
  end
      
end