Class: Rotor::Stepper
- Inherits:
-
Object
- Object
- Rotor::Stepper
- Defined in:
- lib/rotor/motor.rb
Instance Method Summary collapse
- #backwards(delay = 5, steps = 100) ⇒ Object
- #forward(delay = 5, steps = 100) ⇒ Object
-
#initialize(coil_A_1_pin, coil_A_2_pin, coil_B_1_pin, coil_B_2_pin, enable_pin) ⇒ Stepper
constructor
A new instance of Stepper.
- #set_step(w1, w2, w3, w4) ⇒ Object
Constructor Details
#initialize(coil_A_1_pin, coil_A_2_pin, coil_B_1_pin, coil_B_2_pin, enable_pin) ⇒ Stepper
Returns a new instance of Stepper.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rotor/motor.rb', line 4 def initialize(coil_A_1_pin, coil_A_2_pin, coil_B_1_pin, coil_B_2_pin, enable_pin) @io = WiringPi::GPIO.new(WPI_MODE_GPIO) @coil_A_1_pin = coil_A_1_pin @coil_A_2_pin = coil_A_2_pin @coil_B_1_pin = coil_B_1_pin @coil_B_2_pin = coil_B_2_pin @enable_pin = enable_pin [coil_A_1_pin, coil_A_2_pin, coil_B_1_pin, coil_B_2_pin, enable_pin].each do |pin| `echo #{pin} > /sys/class/gpio/unexport` @io.mode(pin,OUTPUT) @io.write(pin,LOW) end @io.write(enable_pin,HIGH) end |
Instance Method Details
#backwards(delay = 5, steps = 100) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rotor/motor.rb', line 33 def backwards(delay=5,steps=100) delay_time = delay/1000.0 (0..steps).each do |i| set_step(1, 0, 0, 1) sleep delay_time set_step(0, 1, 0, 1) sleep delay_time set_step(0, 1, 1, 0) sleep delay_time set_step(1, 0, 1, 0) sleep delay_time end end |
#forward(delay = 5, steps = 100) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rotor/motor.rb', line 19 def forward(delay=5,steps=100) delay_time = delay/1000.0 (0..steps).each do |i| set_step(1, 0, 1, 0) sleep delay_time set_step(0, 1, 1, 0) sleep delay_time set_step(0, 1, 0, 1) sleep delay_time set_step(1, 0, 0, 1) sleep delay_time end end |
#set_step(w1, w2, w3, w4) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rotor/motor.rb', line 47 def set_step(w1, w2, w3, w4) @io.write(@coil_A_1_pin, w1) @io.write(@coil_A_2_pin, w2) @io.write(@coil_B_1_pin, w3) @io.write(@coil_B_2_pin, w4) end |