Class: Denko::Sensor::HCSR04
- Inherits:
-
Object
- Object
- Denko::Sensor::HCSR04
- Includes:
- Behaviors::Lifecycle, 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
Constants included from Behaviors::Reader
Behaviors::Reader::READ_WAIT_TIME
Constants included from Behaviors::Lifecycle
Behaviors::Lifecycle::CALLBACK_METHODS
Instance Attribute Summary
Attributes included from Behaviors::Threaded
Attributes included from Behaviors::State
Attributes included from Behaviors::MultiPin
Attributes included from Behaviors::Component
Instance Method Summary collapse
Methods included from Behaviors::Poller
Methods included from Behaviors::Threaded
#enable_interrupts, included, #mruby_thread_check, #stop, #stop_thread, #threaded, #threaded_loop
Methods included from Behaviors::Reader
#read, #read_busy?, #read_nb, #read_raw, #read_using, #update
Methods included from Behaviors::Callbacks
#add_callback, #callbacks, #remove_callback, #update
Methods included from Behaviors::State
Methods included from Behaviors::Lifecycle
Methods included from Behaviors::MultiPin
#convert_pins, #proxy_pin, #proxy_states, #require_pin, #require_pins
Methods included from Behaviors::Component
Instance Method Details
#_read ⇒ Object
24 25 26 |
# File 'lib/denko/sensor/hcsr04.rb', line 24 def _read board.hcsr04_read(echo.pin, trigger.pin) end |
#initialize_pins(options = {}) ⇒ Object
11 12 13 14 |
# File 'lib/denko/sensor/hcsr04.rb', line 11 def initialize_pins(={}) proxy_pin :trigger, DigitalIO::Output proxy_pin :echo, DigitalIO::Input end |
#pre_callback_filter(us) ⇒ Object
28 29 30 31 32 |
# File 'lib/denko/sensor/hcsr04.rb', line 28 def pre_callback_filter(us) # Data is microseconds roundtrip time. Convert to mm. um = (us/2) * SPEED_OF_SOUND mm = um / 1000.0 end |