Class: Denko::PulseIO::IRTransmitter

Inherits:
Object
  • Object
show all
Includes:
Behaviors::OutputPin
Defined in:
lib/denko/pulse_io/ir_transmitter.rb

Instance Attribute Summary

Attributes included from Behaviors::SinglePin

#mode, #pin

Attributes included from Behaviors::Component

#board

Instance Method Summary collapse

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#initialize, #state

Instance Method Details

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



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

def emit(pulses=[], frequency: 38)
  if pulses.length > 256 || pulses.length < 1
    raise ArgumentError, 'wrong number of IR pulses (expected 1 to 256)'
  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