Class: Denko::Motor::L298

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

Constant Summary

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary collapse

Attributes included from Behaviors::MultiPin

#pin, #pins, #proxies

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::State

#state

Instance Method Summary collapse

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::MultiPin

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

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#update_state

Instance Attribute Details

#speedObject

Returns the value of attribute speed.



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

def speed
  @speed
end

Instance Method Details

#brakeObject



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

def brake
  direction1.high
  direction2.high
  self.speed = 100
end

#forward(value = nil) ⇒ Object



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

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

#idleObject Also known as: off



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

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

#initialize_pins(options = {}) ⇒ Object



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

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

#reverse(value = nil) ⇒ Object



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

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