Module: PiFacer

Extended by:
PiFacer
Included in:
PiFacer
Defined in:
lib/pi_facer.rb,
lib/pi_facer/io.rb

Defined Under Namespace

Classes: FIO

Instance Method Summary collapse

Instance Method Details

#waitObject

Prevents the main thread from exiting. Required when using PiFacer.watch



24
25
26
# File 'lib/pi_facer.rb', line 24

def wait
	loop do sleep 1 end
end

#watch(options, &block) ⇒ Object

Defines an event block to be executed when an event occurs.

Parameters:

options:

Options hash. Options include `:pin`, `:invert` and `:direction`.


13
14
15
16
17
18
19
20
21
# File 'lib/pi_facer.rb', line 13

def watch(options, &block)
	Thread.new do
		pin = PiFacer::FIO.new(options)
		loop do
			pin.wait_for_change 
			yield pin
		end 
	end.abort_on_exception = true  
end