class Smalrubot::Components::BaseComponent
Attributes
board[RW]
pin[RW]
pins[R]
pins=[RW]
pullup[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/smalrubot/components/base_component.rb, line 7 def initialize(options={}) self.board = options[:board] self.pin = options[:pin] || options[:pins] self.pullup = options[:pullup] raise 'board and pin or pins are required for a component' if self.board.nil? || self.pin.nil? after_initialize(options) end
Public Instance Methods
after_initialize(options={})
click to toggle source
As BaseComponent
does a lot of work for you with regarding to setting up, it is best not to override initialize and instead define an after_initialize
method within your subclass.
@note This method should be implemented in the BaseComponent
subclass.
# File lib/smalrubot/components/base_component.rb, line 23 def after_initialize(options={}) ; end
Protected Instance Methods
analog_write(pin=self.pin, value)
click to toggle source
# File lib/smalrubot/components/base_component.rb, line 34 def analog_write(pin=self.pin, value) self.board.analog_write(pin, value) end
digital_write(pin=self.pin, value)
click to toggle source
# File lib/smalrubot/components/base_component.rb, line 30 def digital_write(pin=self.pin, value) self.board.digital_write(pin, value) end
set_pin_mode(pin=self.pin, mode)
click to toggle source
# File lib/smalrubot/components/base_component.rb, line 38 def set_pin_mode(pin=self.pin, mode) self.board.set_pin_mode(pin, mode, pullup) end