lib/denko/motor/l298.rb in denko-0.13.6 vs lib/denko/motor/l298.rb in denko-0.14.0

- old
+ new

@@ -1,49 +1,50 @@ module Denko module Motor class L298 include Behaviors::MultiPin + include Behaviors::Lifecycle attr_reader :speed - + def initialize_pins(options={}) proxy_pin :direction1, DigitalIO::Output proxy_pin :direction2, DigitalIO::Output - proxy_pin :enable, PulseIO::PWMOutput + proxy_pin :enable, PulseIO::PWMOutput end - - def after_initialize(options={}) + + after_initialize do off end def speed=(value) - enable.write(value) + enable.duty = value @speed = value end - + def forward(value=nil) direction1.high direction2.low self.speed = value if value end - + def reverse(value=nil) direction1.low direction2.high self.speed = value if value end - + def idle direction1.low direction2.low self.speed = 0 end alias :off :idle - + def brake direction1.high direction2.high - self.speed = board.pwm_high + self.speed = 100 end end end end