Module: PiFacer
Defined Under Namespace
Classes: FIO
Instance Method Summary collapse
-
#wait ⇒ Object
Prevents the main thread from exiting.
-
#watch(options, &block) ⇒ Object
Defines an event block to be executed when an event occurs.
Instance Method Details
#wait ⇒ Object
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(, &block) Thread.new do pin = PiFacer::FIO.new() loop do pin.wait_for_change yield pin end end.abort_on_exception = true end |