Class: Denko::Motor::Stepper

Inherits:
Object
  • Object
show all
Includes:
Behaviors::MultiPin
Defined in:
lib/denko/motor/stepper.rb

Instance Attribute Summary collapse

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::MultiPin

#before_initialize, #convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#initialize, #state

Instance Attribute Details

#microstepsObject

Returns the value of attribute microsteps.



16
17
18
# File 'lib/denko/motor/stepper.rb', line 16

def microsteps
  @microsteps
end

Instance Method Details

#after_initialize(options = {}) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/denko/motor/stepper.rb', line 18

def after_initialize(options={})
  wake; on;
  
  if (ms1 && ms2)
    self.microsteps = 8
  end
end

#initialize_pins(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/denko/motor/stepper.rb', line 6

def initialize_pins(options={})
  proxy_pin :step,      DigitalIO::Output
  proxy_pin :direction, DigitalIO::Output
  
  proxy_pin :ms1,    DigitalIO::Output, optional: true
  proxy_pin :ms2,    DigitalIO::Output, optional: true
  proxy_pin :enable, DigitalIO::Output, optional: true
  proxy_pin :slp,    DigitalIO::Output, optional: true        
end

#offObject



34
35
36
# File 'lib/denko/motor/stepper.rb', line 34

def off
  enable.high if enable
end

#onObject



38
39
40
# File 'lib/denko/motor/stepper.rb', line 38

def on
  enable.low if enable
end

#sleepObject



26
27
28
# File 'lib/denko/motor/stepper.rb', line 26

def sleep
  slp.low if slp
end

#step_ccObject Also known as: step_ccw



56
57
58
59
60
# File 'lib/denko/motor/stepper.rb', line 56

def step_cc
  direction.high unless direction.high?
  step.high
  step.low
end

#step_cwObject



62
63
64
65
66
# File 'lib/denko/motor/stepper.rb', line 62

def step_cw
  direction.low unless direction.low?
  step.high
  step.low
end

#wakeObject



30
31
32
# File 'lib/denko/motor/stepper.rb', line 30

def wake
  slp.high if slp
end