本文整理汇总了Python中dht.DHT22属性的典型用法代码示例。如果您正苦于以下问题:Python dht.DHT22属性的具体用法?Python dht.DHT22怎么用?Python dht.DHT22使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类dht
的用法示例。
在下文中一共展示了dht.DHT22属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def main():
# Wemos D1 Mini NeoPixel Shield is on pin 4 (D2)
pin = machine.Pin(4, machine.Pin.OUT)
# There is just 1 Neopixel LED on Shield
n = neopixel.NeoPixel(pin, 1)
# Wemos D1 Mini DHT Shield is on pin 2 (D4)
d = dht.DHT22(machine.Pin(2))
while True:
d.measure()
h = d.humidity()
print(h)
if (h < 45):
# RGB values
n[0] = (127, 0, 0)
else:
n[0] = (0, 127, 0)
# Write value to LEDs
n.write()
time.sleep(10)
示例2: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def __init__(self, pin, precision_temp=2, precision_humid=1,
offset_temp=0, offset_humid=0,
interval_publish=None, interval_reading=None, mqtt_topic=None,
friendly_name_temp=None, friendly_name_humid=None,
discover=True, expose_intervals=False, intervals_topic=None):
# This makes it possible to use multiple instances of MySensor and have unique identifier
global _unit_index
_unit_index += 1
super().__init__(COMPONENT_NAME, __version__, _unit_index, discover, interval_publish,
interval_reading, mqtt_topic, _log, expose_intervals, intervals_topic)
self._addSensorType(SENSOR_TEMPERATURE, precision_temp, offset_temp, _VAL_T_TEMPERATURE,
"°C", friendly_name_temp)
self._addSensorType(SENSOR_HUMIDITY, precision_humid, offset_humid, _VAL_T_HUMIDITY, "%",
friendly_name_humid)
##############################
# create sensor object
self.sensor = Sensor(Pin(pin)) # add neccessary constructor arguments here
##############################
gc.collect()
示例3: read_handler
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def read_handler(vpin):
temperature = 0.0
humidity = 0.0
# read sensor data
try:
dht22.measure()
temperature = dht22.temperature()
humidity = dht22.humidity()
except OSError as o_err:
print("Unable to get DHT22 sensor data: '{}'".format(o_err))
# change widget values and colors according read results
if temperature != 0.0 and humidity != 0.0:
blynk.set_property(T_VPIN, 'color', T_COLOR)
blynk.set_property(H_VPIN, 'color', H_COLOR)
blynk.virtual_write(T_VPIN, temperature)
blynk.virtual_write(H_VPIN, humidity)
else:
# show widgets aka 'disabled' that mean we had errors during read sensor operation
blynk.set_property(T_VPIN, 'color', ERR_COLOR)
blynk.set_property(H_VPIN, 'color', ERR_COLOR)
示例4: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def __init__(self, name="Temp & Humid", pin=4, interval=60, pull=-1):
super().__init__(id="dht22", name=name, type="dht22")
self.dht22 = dht.DHT22(Pin(pin, Pin.IN, pull))
self.interval = interval
self.temp_property = HomieNodeProperty(
id="temperature",
name="Temperature",
datatype=FLOAT,
format="-40:80",
unit="°C",
)
self.add_property(self.temp_property)
self.hum_property = HomieNodeProperty(
id="humidity",
name="Humidity",
datatype=FLOAT,
format="0:100",
unit="%",
)
self.add_property(self.hum_property)
loop = get_event_loop()
loop.create_task(self.update_data())
示例5: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def __init__(self, pin, interval, handler = None):
self.last_measurement = time.ticks_ms()
self.dht22 = dht.DHT22(machine.Pin(pin))
self.interval = util.string_to_millis(interval)
self.iterations = 0
self.handler = handler
# mesures temperature and humidity
示例6: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def __init__(self, name, pin, on_change=None, filter=None):
# TODO: also handle an I2C object here
import dht
_HTDHT.__init__(self, name, pin, dht.DHT22(pin), 2000,
on_change=on_change, filter=filter)
示例7: __init__
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def __init__(self, type, pin):
self.type = type
if self.type == 0:
self.sensor = dht.DHT11(Pin(pin))
elif self.type == 1:
self.sensor = dht.DHT22(Pin(pin))
else:
log.error("Unknown sensor type '{}'. Cannot instantiate it.".format(self.type))
# @timed_function
示例8: main
# 需要导入模块: import dht [as 别名]
# 或者: from dht import DHT22 [as 别名]
def main():
# Homie device setup
homie = HomieDevice(settings)
# Add dht22 node
homie.add_node(DHT22(pin=4))
# run forever
homie.run_forever()