当前位置: 首页>>代码示例>>Python>>正文


Python GPIO.input方法代码示例

本文整理汇总了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
开发者ID:aocana,项目名称:SIP,代码行数:37,代码来源:helpers.py

示例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
开发者ID:sbruggeman,项目名称:SIP,代码行数:35,代码来源:helpers.py

示例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
开发者ID:alustig,项目名称:OSPi,代码行数:16,代码来源:helpers.py

示例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
开发者ID:ntc490,项目名称:OSPi,代码行数:16,代码来源:helpers.py

示例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)
开发者ID:Dan-in-CA,项目名称:sip_plugins,代码行数:9,代码来源:pressure_adj.py

示例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
开发者ID:teodoryantcheff,项目名称:OSPy,代码行数:18,代码来源:pressure_adj.py

示例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)
开发者ID:Dan-in-CA,项目名称:sip_plugins,代码行数:45,代码来源:pressure_adj.py

示例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
开发者ID:teodoryantcheff,项目名称:OSPy,代码行数:12,代码来源:ups_adj.py

示例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)
开发者ID:teodoryantcheff,项目名称:OSPy,代码行数:8,代码来源:pressure_adj.py

示例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)
开发者ID:teodoryantcheff,项目名称:OSPy,代码行数:8,代码来源:ups_adj.py


注:本文中的gpio_pins.GPIO.input方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。