class FFI::WiringPi::SoftPwm::Pin

Public Class Methods

new(pin, initial_state = 0, range = 100) click to toggle source
# File lib/ffi/wiring_pi/soft_pwm.rb, line 12
def initialize(pin, initial_state = 0, range = 100)
  raise ArgumentError, 'Range should be Integer > 0' unless range.is_a?(Integer) && range > 0
  raise ArgumentError, 'State should be within the range' unless initial_state.is_a?(Integer) && (0..range).cover?(initial_state)
  @pin = pin
  @range = range
  FFI::WiringPi::SoftPwm.soft_pwm_create pin, initial_state, range
end

Public Instance Methods

write(value) click to toggle source
# File lib/ffi/wiring_pi/soft_pwm.rb, line 20
def write(value)
  raise ArgumentError, 'Value should be within the range' unless value.is_a?(Integer) && (0..@range).cover?(value)
  FFI::WiringPi::SoftPwm.soft_pwm_write @pin, value
end