本文整理汇总了Python中gpio_pins.GPIO.input方法的典型用法代码示例。如果您正苦于以下问题:Python GPIO.input方法的具体用法?Python GPIO.input怎么用?Python GPIO.input使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gpio_pins.GPIO
的用法示例。
在下文中一共展示了GPIO.input方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_rain
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def check_rain():
"""
Checks status of an installed rain sensor.
Handles normally open and normally closed rain sensors
Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
"""
global pi
try:
if gv.sd['rst'] == 1: # Rain sensor type normally open (default)
if gv.use_pigpio:
if not pi.read(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
else:
if not GPIO.input(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
elif gv.sd['rst'] == 0: # Rain sensor type normally closed
if gv.use_pigpio:
if pi.read(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
else:
if GPIO.input(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
except NameError:
pass
示例2: check_rain
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def check_rain():
"""
Checks status of an installed rain sensor.
Handles normally open and normally closed rain sensors
Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
"""
global pi
try:
if gv.sd['rst'] == 1: # Rain sensor type normally open (default)
if gv.use_pigpio:
if not pi.read(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
else:
if GPIO.input(pin_rain_sense) == gv.sd['rs']: # Rain sensor changed, reading and gv.sd['rs'] are inverse.
report_rain_changed()
gv.sd['rs'] = 1 - gv.sd['rs'] # toggle
elif gv.sd['rst'] == 0: # Rain sensor type normally closed
if gv.use_pigpio:
if pi.read(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
else:
if GPIO.input(pin_rain_sense) != gv.sd['rs']: # Rain sensor changed
report_rain_changed()
gv.sd['rs'] = 1 - gv.sd['rs'] # toggle
except NameError:
pass
示例3: check_rain
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def check_rain():
try:
if gv.sd['rst'] == 0:
if GPIO.input(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
elif gv.sd['rst'] == 1:
if not GPIO.input(pin_rain_sense):
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
except NameError:
pass
示例4: check_rain
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def check_rain():
try:
if gv.sd['rst'] == 1: # Rain sensor type normally open (default)
if not GPIO.input(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
elif gv.sd['rst'] == 0: # Rain sensor type normally closed
if GPIO.input(pin_rain_sense): # Rain detected
gv.sd['rs'] = 1
else:
gv.sd['rs'] = 0
except NameError:
pass
示例5: get_pressure_sensor
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def get_pressure_sensor():
if GPIO.input(pin_pressure) != 1:
press = ('Pressure sensor is not active.') # sensor pin is connected to ground
else:
press = ('Pressure sensor is active - pressure in pipeline is OK.') # sensor pin is unconnected
return str(press)
示例6: get_check_pressure
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def get_check_pressure():
datapressure = get_pressure_options()
try:
if datapressure['normally'] != 'off':
if GPIO.input(pin_pressure): # pressure detected
press = 1
else:
press = 0
elif datapressure['normally'] != 'on':
if not GPIO.input(pin_pressure):
press = 1
else:
press = 0
return press
except NameError:
pass
示例7: run
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def run(self):
time.sleep(randint(3, 10)) # Sleep some time to prevent printing before startup information
print "Pressure plugin is active"
send = False
SUBJ = "Reporting from ospi" # Subject in email
self.add_status('Waiting...')
while True:
try:
datapressure = get_pressure_options() # load data from file
if datapressure['press'] != 'off': # if pressure plugin is enabled
if (gv.sd['mas'] != 0) and not (gv.sd['mm']): # if is use master station and not manual control
if gv.srvals[gv.sd['mas']] != 0: # if master station is ON
if GPIO.input(pin_pressure) == 0: # if sensor is open
self._sleep(int(datapressure['time'])) # wait to activated pressure sensor
if GPIO.input(pin_pressure) == 0: # if sensor is current open
stop_stations()
self.add_status('Pressure sensor is not activated in time -> stops all stations and sends email.')
if datapressure['sendeml'] != 'off': # if enabled send email
send = True
else: # if not used master station
self.status = ''
self.add_status('Not used master station.')
if send:
TEXT = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(
time.time())) + ' System detected error: pressure sensor.')
try:
from plugins.email_adj import email
email(SUBJ, TEXT) # send email without attachments
self.add_status('Email was sent: ' + TEXT)
send = False
except Exception as err:
self.add_status('Email was not sent! ' + str(err))
self._sleep(1)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
self.add_status('Pressure plugin encountered error: ' + err_string)
self._sleep(60)
示例8: get_check_power
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def get_check_power():
dataUPS = get_ups_options()
try:
if GPIO.input(pin_power_ok): # power line detected
pwr = 1
else:
pwr = 0
return pwr
except NameError:
pass
示例9: get_pressure_sensor_str
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def get_pressure_sensor_str():
if GPIO.input(pin_pressure) == 0:
press = ('GPIO Pin = 0 is closed.')
else:
press = ('GPIO Pin = 1 is open.')
return str(press)
示例10: get_check_power_str
# 需要导入模块: from gpio_pins import GPIO [as 别名]
# 或者: from gpio_pins.GPIO import input [as 别名]
def get_check_power_str():
if GPIO.input(pin_power_ok) == 0:
pwr = ('GPIO Pin = 0 Power line is OK.')
else:
pwr = ('GPIO Pin = 1 Power line ERROR.')
return str(pwr)