Class: IoT::DHTxxSensor
- Inherits:
-
HumitureSensor
- Object
- Receptor
- DigitalReceptor
- DigitalSensor
- TemperatureSensor
- HumitureSensor
- IoT::DHTxxSensor
- Defined in:
- lib/iot/dht_sensor.rb
Overview
DHT11/22 humidity & temperature sensor family
Instance Method Summary collapse
-
#initialize(pin, sensor_model) ⇒ DHTxxSensor
constructor
A new instance of DHTxxSensor.
- #name ⇒ Object
-
#read_data ⇒ Object
Read values by ‘DhtSensor.read’ from ‘dht-sensor-ffi’.
Methods inherited from HumitureSensor
Methods inherited from TemperatureSensor
#celsius, #fahrenheit, #kelvin, #reaumur, #temperature, #to_s
Methods inherited from DigitalReceptor
Methods inherited from Receptor
Constructor Details
#initialize(pin, sensor_model) ⇒ DHTxxSensor
Returns a new instance of DHTxxSensor.
8 9 10 11 12 13 |
# File 'lib/iot/dht_sensor.rb', line 8 def initialize(pin, sensor_model) @pin = pin @sensor_name = 'DHT'+sensor_model.to_s @sensor_model = sensor_model.to_i @temperature, @humidity = read_data end |
Instance Method Details
#name ⇒ Object
15 16 17 |
# File 'lib/iot/dht_sensor.rb', line 15 def name @sensor_name end |
#read_data ⇒ Object
Read values by ‘DhtSensor.read’ from ‘dht-sensor-ffi’
20 21 22 23 24 25 |
# File 'lib/iot/dht_sensor.rb', line 20 def read_data sensor_data = DhtSensor.read(@pin, @sensor_model) @temperature = sensor_data.temp @humidity = sensor_data.humidity [@temperature, @humidity] end |