Class: Denko::Sensor::HCSR04
- Inherits:
-
Object
- Object
- Denko::Sensor::HCSR04
- Includes:
- Behaviors::MultiPin, Behaviors::Poller
- Defined in:
- lib/denko/sensor/hcsr04.rb
Constant Summary collapse
- SPEED_OF_SOUND =
Speed of sound in meters per second.
343.0
Instance Attribute Summary
Attributes included from Behaviors::Threaded
Attributes included from Behaviors::Callbacks
Attributes included from Behaviors::MultiPin
Attributes included from Behaviors::Component
Instance Method Summary collapse
- #_read ⇒ Object
- #after_initialize(options = {}) ⇒ Object
- #initialize_pins(options = {}) ⇒ Object
- #pre_callback_filter(us) ⇒ Object
Methods included from Behaviors::Poller
Methods included from Behaviors::Threaded
#enable_interrupts, included, #stop, #stop_thread, #threaded, #threaded_loop
Methods included from Behaviors::Reader
#read, #read_using, #wait_for_read
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #initialize, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::MultiPin
#before_initialize, #convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins
Methods included from Behaviors::Component
Instance Method Details
#_read ⇒ Object
22 23 24 |
# File 'lib/denko/sensor/hcsr04.rb', line 22 def _read board.hcsr04_read(echo.pin, trigger.pin) end |
#after_initialize(options = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/denko/sensor/hcsr04.rb', line 15 def after_initialize(={}) super() # Receive values from echo pin. echo.add_callback { |data| self.update(data) } end |
#initialize_pins(options = {}) ⇒ Object
10 11 12 13 |
# File 'lib/denko/sensor/hcsr04.rb', line 10 def initialize_pins(={}) proxy_pin :trigger, DigitalIO::Output proxy_pin :echo, DigitalIO::Input end |
#pre_callback_filter(us) ⇒ Object
26 27 28 29 30 |
# File 'lib/denko/sensor/hcsr04.rb', line 26 def pre_callback_filter(us) # Data is microseconds roundtrip time. Convert to mm. um = (us/2) * SPEED_OF_SOUND mm = um / 1000.0 end |