本文整理汇总了Python中DHT22.read方法的典型用法代码示例。如果您正苦于以下问题:Python DHT22.read方法的具体用法?Python DHT22.read怎么用?Python DHT22.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DHT22
的用法示例。
在下文中一共展示了DHT22.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import DHT22 [as 别名]
# 或者: from DHT22 import read [as 别名]
def main():
##-------------------------------------------------------------------------
## Parse Command Line Arguments
##-------------------------------------------------------------------------
## create a parser object for understanding command-line arguments
parser = argparse.ArgumentParser(
description="Program description.")
## add flags
parser.add_argument("-v", "--verbose",
action="store_true", dest="verbose",
default=False, help="Be verbose! (default = False)")
## add arguments
parser.add_argument("--input",
type=str, dest="input",
help="The input.")
args = parser.parse_args()
##-------------------------------------------------------------------------
## Create logger object
##-------------------------------------------------------------------------
logger = logging.getLogger('MyLogger')
logger.setLevel(logging.DEBUG)
## Set up console output
LogConsoleHandler = logging.StreamHandler()
if args.verbose:
LogConsoleHandler.setLevel(logging.DEBUG)
else:
LogConsoleHandler.setLevel(logging.INFO)
LogFormat = logging.Formatter('%(asctime)23s %(levelname)8s: %(message)s')
LogConsoleHandler.setFormatter(LogFormat)
logger.addHandler(LogConsoleHandler)
## Set up file output
# LogFileName = None
# LogFileHandler = logging.FileHandler(LogFileName)
# LogFileHandler.setLevel(logging.DEBUG)
# LogFileHandler.setFormatter(LogFormat)
# logger.addHandler(LogFileHandler)
# os.system('modprobe w1-gpio')
# os.system('modprobe w1-therm')
##-------------------------------------------------------------------------
## Read DS18B20 Temperature Sensors
##-------------------------------------------------------------------------
temps = DS18B20.read()
for temp in temps:
logger.info('Temperature (DS18B20) = {:.1f} F'.format(temp))
##-------------------------------------------------------------------------
## Read DHT22 Temperature and Humidity Sensor
##-------------------------------------------------------------------------
temp_DHT, humidity = DHT22.read()
logger.info('Temperature (DHT22) = {:.1f} F'.format(temp_DHT))
logger.info('Humidity (DHT22) = {:.0f} %'.format(humidity))