Class: Beaglebone::AINPin
- Inherits:
-
Object
- Object
- Beaglebone::AINPin
- Defined in:
- lib/beaglebone/ain.rb
Overview
Object Oriented AIN Implementation. This treats the pin as an object.
Instance Method Summary collapse
-
#disable_analog_pin ⇒ Object
Disable analog pin.
-
#initialize(pin) ⇒ AINPin
constructor
Initialize a Analog pin Return’s an AINPin object.
-
#read ⇒ Integer
Read from an analog pin.
-
#run_on_change(callback, mv_change = 10, interval = 0.01, repeats = nil) ⇒ Object
Runs a callback after voltage changes by specified amount.
-
#run_on_threshold(callback, mv_lower, mv_upper, mv_reset = 10, interval = 0.01, repeats = nil) ⇒ Object
Runs a callback after voltage changes beyond a certain threshold.
-
#run_once_on_change(callback, mv_change = 10, interval = 0.01) ⇒ Object
Runs a callback once after specified change in voltage detected Convenience method for run_on_change.
-
#run_once_on_threshold(callback, mv_lower, mv_upper, mv_reset = 10, interval = 0.01) ⇒ Object
Runs a callback once after voltage crosses a specified threshold.
-
#stop_wait ⇒ Object
Stops any threads waiting for data on this pin.
-
#wait_for_change(mv_change, interval, mv_last = nil) ⇒ Object
Returns when voltage changes by specified amount.
-
#wait_for_threshold(mv_lower, mv_upper, mv_reset = 10, interval = 0.01, mv_last = nil, state_last = nil) ⇒ Object
Returns when voltage changes by specified amount.
Constructor Details
#initialize(pin) ⇒ AINPin
Initialize a Analog pin Return’s an AINPin object
362 363 364 |
# File 'lib/beaglebone/ain.rb', line 362 def initialize(pin) @pin = pin end |
Instance Method Details
#disable_analog_pin ⇒ Object
Disable analog pin
473 474 475 |
# File 'lib/beaglebone/ain.rb', line 473 def disable_analog_pin AIN::disable_analog_pin(@pin) end |
#read ⇒ Integer
Read from an analog pin
373 374 375 |
# File 'lib/beaglebone/ain.rb', line 373 def read AIN::read(@pin) end |
#run_on_change(callback, mv_change = 10, interval = 0.01, repeats = nil) ⇒ Object
Runs a callback after voltage changes by specified amount. This creates a new thread that runs in the background and polls at specified interval.
This method should take 4 arguments: the pin, the previous voltage, the current voltage, and the counter
391 392 393 |
# File 'lib/beaglebone/ain.rb', line 391 def run_on_change(callback, mv_change=10, interval=0.01, repeats=nil) AIN::run_on_change(callback, @pin, mv_change, interval, repeats) end |
#run_on_threshold(callback, mv_lower, mv_upper, mv_reset = 10, interval = 0.01, repeats = nil) ⇒ Object
Runs a callback after voltage changes beyond a certain threshold. This creates a new thread that runs in the background and polls at specified interval. When the voltage crosses the specified thresholds the callback is run.
421 422 423 |
# File 'lib/beaglebone/ain.rb', line 421 def run_on_threshold(callback, mv_lower, mv_upper, mv_reset=10, interval=0.01, repeats=nil) AIN::run_on_threshold(callback, @pin, mv_lower, mv_upper, mv_reset, interval, repeats) end |
#run_once_on_change(callback, mv_change = 10, interval = 0.01) ⇒ Object
Runs a callback once after specified change in voltage detected Convenience method for run_on_change
397 398 399 |
# File 'lib/beaglebone/ain.rb', line 397 def run_once_on_change(callback, mv_change=10, interval=0.01) AIN::run_once_on_change(callback, @pin, mv_change, interval) end |
#run_once_on_threshold(callback, mv_lower, mv_upper, mv_reset = 10, interval = 0.01) ⇒ Object
Runs a callback once after voltage crosses a specified threshold. Convenience method for run_on_threshold
428 429 430 |
# File 'lib/beaglebone/ain.rb', line 428 def run_once_on_threshold(callback, mv_lower, mv_upper, mv_reset=10, interval=0.01) AIN::run_once_on_threshold(callback, @pin, mv_lower, mv_upper, mv_reset, interval) end |
#stop_wait ⇒ Object
Stops any threads waiting for data on this pin
468 469 470 |
# File 'lib/beaglebone/ain.rb', line 468 def stop_wait AIN::stop_wait(@pin) end |
#wait_for_change(mv_change, interval, mv_last = nil) ⇒ Object
Returns when voltage changes by specified amount
463 464 465 |
# File 'lib/beaglebone/ain.rb', line 463 def wait_for_change(mv_change, interval, mv_last=nil) AIN::wait_for_change(@pin, mv_change, interval, mv_last) end |
#wait_for_threshold(mv_lower, mv_upper, mv_reset = 10, interval = 0.01, mv_last = nil, state_last = nil) ⇒ Object
Returns when voltage changes by specified amount
448 449 450 |
# File 'lib/beaglebone/ain.rb', line 448 def wait_for_threshold(mv_lower, mv_upper, mv_reset=10, interval=0.01, mv_last=nil, state_last=nil) AIN::wait_for_threshold(@pin, mv_lower, mv_upper, mv_reset, interval, mv_last, state_last) end |