Class: Denko::Motor::L298

Inherits:
Object
  • Object
show all
Includes:
Behaviors::MultiPin
Defined in:
lib/denko/motor/l298.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

#speedObject

Returns the value of attribute speed.



6
7
8
# File 'lib/denko/motor/l298.rb', line 6

def speed
  @speed
end

Instance Method Details

#after_initialize(options = {}) ⇒ Object



14
15
16
# File 'lib/denko/motor/l298.rb', line 14

def after_initialize(options={})
  off
end

#brakeObject



42
43
44
45
46
# File 'lib/denko/motor/l298.rb', line 42

def brake
  direction1.high
  direction2.high
  self.speed = board.pwm_high
end

#forward(value = nil) ⇒ Object



23
24
25
26
27
# File 'lib/denko/motor/l298.rb', line 23

def forward(value=nil)
  direction1.high
  direction2.low
  self.speed = value if value
end

#idleObject Also known as: off



35
36
37
38
39
# File 'lib/denko/motor/l298.rb', line 35

def idle
  direction1.low
  direction2.low
  self.speed = 0
end

#initialize_pins(options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/denko/motor/l298.rb', line 8

def initialize_pins(options={})
  proxy_pin :direction1,  DigitalIO::Output
  proxy_pin :direction2,  DigitalIO::Output
  proxy_pin :enable,      PulseIO::PWMOutput 
end

#reverse(value = nil) ⇒ Object



29
30
31
32
33
# File 'lib/denko/motor/l298.rb', line 29

def reverse(value=nil)
  direction1.low
  direction2.high
  self.speed = value if value
end