Class: Denko::PulseIO::IROutput

Inherits:
Object
  • Object
show all
Includes:
Behaviors::Lifecycle, Behaviors::SinglePin
Defined in:
lib/denko/pulse_io/ir_output.rb

Constant Summary

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary

Attributes included from Behaviors::SinglePin

#mode, #pin

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::SinglePin

#convert_pins, #initialize_pins

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#update_state

Instance Method Details

#write(pulses = [], frequency: 38) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/denko/pulse_io/ir_output.rb', line 7

def write(pulses=[], frequency: 38)
  if pulses.length > 255 || pulses.length < 1
    raise ArgumentError, 'wrong number of IR pulses (expected 1 to 255)'
  end

  pulses.each_with_index do |pulse, index|
    raise ArgumentError, 'non Numeric data in IR signal' unless pulse.is_a? Numeric
    pulses[index] = pulse.round unless pulse.is_a? Integer
    raise ArgumentError, 'pulse too long (max 65535 ms)' if pulse > 65535
  end

  board.infrared_emit(pin, frequency, pulses)
end