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


Python GPIO.BOTH属性代码示例

本文整理汇总了Python中RPi.GPIO.BOTH属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.BOTH属性的具体用法?Python GPIO.BOTH怎么用?Python GPIO.BOTH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在RPi.GPIO的用法示例。


在下文中一共展示了GPIO.BOTH属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pin, real_true = GPIO.HIGH):
        '''
        Init the tact
        :param pin: pin number in array
        :param real_true: GPIO.HIGH or GPIO.LOW
        :return: void
        '''
        self.__pin = pin
        self.__real_true = real_true

        if self.__real_true:
            self.__status = GPIO.input(self.__pin)
        else:
            self.__status = not GPIO.input(self.__pin)

        GPIO.add_event_detect(pin, GPIO.BOTH, callback = self.make_event, bouncetime = 1)

        try:
            t1 = Thread(target = self.watching)
            t1.setDaemon(True)
        except:
            print "Error: Unable to start thread by Tact"


    #Stauts. 
开发者ID:spoonysonny,项目名称:SAKS-tutorials,代码行数:27,代码来源:tact.py

示例2: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, port="5550"):
        self.__bind_addr = "tcp://*:%s" % port
        app.logger.info("Bind address: " + self.__bind_addr)

        self.__relay_lock = threading.Lock()

        self.__db = GarageDb(app.instance_path, app.resource_path)

        # Get initial reed state and subscribe to events
        GPIO.setup(app.config['REED_PIN'], GPIO.IN)
        GPIO.add_event_detect(app.config['REED_PIN'], GPIO.BOTH, callback=self.door_opened_or_closed)
        self.__door_state = None                            # 1 for open, 0 for closed, None for uninitialized
        self.door_opened_or_closed(app.config['REED_PIN'])  # force update

        # Set up warning timer if there's a setting
        if app.config['DOOR_OPEN_WARNING_TIME']:
            app.logger.info('Starting schedule to check door at {0}...'.format(app.config['DOOR_OPEN_WARNING_TIME']))
            schedule.every().day.at(app.config['DOOR_OPEN_WARNING_TIME']).do(self.check_door_open_for_warning)
            t = Thread(target=self.run_schedule)
            t.start()
        else:
            app.logger.info('No schedule to run.') 
开发者ID:nathanpjones,项目名称:GaragePi,代码行数:24,代码来源:controller.py

示例3: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self):
        # Set GPIO mode to Broadcom SOC numbering
        GPIO.setmode(GPIO.BCM)

        # Listen for rotary movements
        GPIO.setup(self.pin_rotary, GPIO.IN)
        GPIO.add_event_detect(self.pin_rotary, GPIO.BOTH, callback = self.NumberCounter)
        
        # Listen for on/off hooks
        GPIO.setup(self.pin_onhook, GPIO.IN)
        GPIO.add_event_detect(self.pin_onhook, GPIO.BOTH, callback = self.HookEvent, bouncetime=100)
        
        self.onhook_timer = Timer(2, self.verifyHook)
        self.onhook_timer.start()

    # Handle counting of rotary movements and respond with digit after timeout 
开发者ID:hnesland,项目名称:aselektriskbureau,代码行数:18,代码来源:RotaryDial.py

示例4: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, config):

        # Config
        self.relay_pin = config['relay']
        self.state_pin = config['state']
        self.id = config['id']
        self.mode = int(config.get('state_mode') == 'normally_closed')
        self.invert_relay = bool(config.get('invert_relay'))

        # Setup
        self._state = None
        self.onStateChange = EventHook()

        # Set relay pin to output, state pin to input, and add a change listener to the state pin
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.relay_pin, GPIO.OUT)
        GPIO.setup(self.state_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(self.state_pin, GPIO.BOTH, callback=self.__stateChanged, bouncetime=300)


        # Set default relay state to false (off)
        GPIO.output(self.relay_pin, self.invert_relay)

    # Release rpi resources 
开发者ID:Jerrkawz,项目名称:GarageQTPi,代码行数:27,代码来源:garage.py

示例5: _setup_callback

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def _setup_callback(self, bouncetime):
        if self.has_callback:
            return False

        def handle_callback(pin):
            if self.read() == 1 and callable(self.handle_pressed):
                self.handle_pressed(self)
            elif self.read() == 0 and callable(self.handle_released):
                self.handle_released(self)
            if callable(self.handle_changed):
                self.handle_changed(self)

        self._setup_gpio()
        GPIO.add_event_detect(self.pin, GPIO.BOTH, callback=handle_callback, bouncetime=bouncetime)
        self.has_callback = True
        return True 
开发者ID:pimoroni,项目名称:explorer-hat,代码行数:18,代码来源:__init__.py

示例6: init

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def init(self, switch_pin=None, clock_pin=None, data_pin=None, **kwargs):
        _log.info("setup")
        self._switch_pin = switch_pin
        self._clock_pin = clock_pin
        self._data_pin = data_pin
        
        gpio.setmode(gpio.BCM)

        if self._switch_pin:
            _log.info("Setting up button pin")
            gpio.setup(self._switch_pin, gpio.IN, gpio.PUD_UP)
            gpio.add_event_detect(self._switch_pin, gpio.BOTH, callback=self._switch_cb, bouncetime=2)
            
        if self._data_pin:
            _log.info("Setting up data pin")
            gpio.setup(self._data_pin, gpio.IN)

        if self._clock_pin:
            gpio.setup(self._clock_pin, gpio.IN, gpio.PUD_UP)
            gpio.add_event_detect(self._clock_pin, gpio.FALLING, callback=self._knob_cb, bouncetime=2)
            
        self._values = []
        
        _log.info("Systems are go") 
开发者ID:EricssonResearch,项目名称:calvin-base,代码行数:26,代码来源:GPIOKY040.py

示例7: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, hw_model):
        self.callback = None
        self.button_sequence = 0
        self.button_timer = None
        self.button_sequence_lock = Lock()
        self.button_state = "up"
        GPIO.setwarnings(True)
        GPIO.setmode(GPIO.BCM)
        if hw_model == NabIO.MODEL_2018:
            self.button_channel = ButtonGPIO.BUTTON_CHANNEL_2018
        else:
            self.button_channel = ButtonGPIO.BUTTON_CHANNEL_2019
        GPIO.setup(self.button_channel, GPIO.IN)
        try:
            GPIO.add_event_detect(
                self.button_channel, GPIO.BOTH, callback=self._button_event
            )
        except RuntimeError:
            print("Could not set edge detection (please reboot ?)")
            sys.exit(1) 
开发者ID:nabaztag2018,项目名称:pynab,代码行数:22,代码来源:button_gpio.py

示例8: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pins, real_true = GPIO.HIGH):
        '''
        Init the dip switch
        :param pin: pin numbers in array
        :param real_true: GPIO.HIGH or GPIO.LOW
        :return: void
        '''
        self.__pins = pins
        self.__real_true = real_true
        for p in pins:
            self.__status.append(not real_true)

        if self.__real_true:
            self.__status[0] = GPIO.input(self.__pins[0])
            self.__status[1] = GPIO.input(self.__pins[1])
        else:
            self.__status[0] = not GPIO.input(self.__pins[0])
            self.__status[1] = not GPIO.input(self.__pins[1])


        GPIO.add_event_detect(self.__pins[0], GPIO.BOTH, callback = self.make_event, bouncetime = 50)
        GPIO.add_event_detect(self.__pins[1], GPIO.BOTH, callback = self.make_event, bouncetime = 50)

        try:
            t1 = Thread(target = self.watching)
            t1.setDaemon(True)
            #t1.start()
        except:
            print("Error: Unable to start thread by DipSwitch")

    #Stauts. 
开发者ID:spoonysonny,项目名称:SAKS-SDK,代码行数:33,代码来源:dip_switch_2bit.py

示例9: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pin, real_true = GPIO.HIGH):
        '''
        Init the tact
        :param pin: pin number in array
        :param real_true: GPIO.HIGH or GPIO.LOW
        :return: void
        '''
        self.__pin = pin
        self.__real_true = real_true

        if self.__real_true:
            self.__status = GPIO.input(self.__pin)
        else:
            self.__status = not GPIO.input(self.__pin)

        GPIO.add_event_detect(pin, GPIO.BOTH, callback = self.make_event, bouncetime = 1)

        try:
            t1 = Thread(target = self.watching)
            t1.setDaemon(True)
            #t1.start()
        except:
            print("Error: Unable to start thread by Tact")


    #Stauts. 
开发者ID:spoonysonny,项目名称:SAKS-SDK,代码行数:28,代码来源:tact.py

示例10: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def setup(self):
        """Set up the GPIO button."""
        if self._is_setup:
            return

        GPIO.setup(self._gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.add_event_detect(self._gpio_pin, GPIO.BOTH, bouncetime=1, callback=self._handle_button)
        self._is_setup = True 
开发者ID:pimoroni,项目名称:rainbow-hat,代码行数:10,代码来源:touch.py

示例11: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def  __init__(self):
        super(myDriver, self).__init__()
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(PIN_INP, GPIO.IN)
        GPIO.setup(PIN_OUT, GPIO.OUT)
        GPIO.setup(PIN_PWM, GPIO.OUT)
        GPIO.add_event_detect(PIN_INP, GPIO.BOTH, callback=self.input_callback)
        self.pwm = GPIO.PWM(PIN_PWM, 1) # 1 Hz 
开发者ID:paulscherrerinstitute,项目名称:pcaspy,代码行数:10,代码来源:rpi_gpio.py

示例12: initialize_gpio

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def initialize_gpio():
    GPIO.setmode(GPIO.BOARD)
    GPIO.setup([11, 32, 36], GPIO.OUT)  # LEDs: Blue (metronome), Green (ok), Red (error)
    GPIO.setup(31, GPIO.IN)
    GPIO.output([32, 36], GPIO.LOW)
    GPIO.add_event_detect(31, GPIO.BOTH, callback=intercept_morse_code)


# Blink a blue LED on/off (one full cycle per BASE_TIME_SECONDS) 
开发者ID:grantwinney,项目名称:52-Weeks-of-Pi,代码行数:11,代码来源:Transmitter.py

示例13: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import BOTH [as 别名]
def __init__(self, pins, real_true = GPIO.HIGH):
        '''
        Init the dip switch
        :param pin: pin numbers in array
        :param real_true: GPIO.HIGH or GPIO.LOW
        :return: void
        '''
        self.__pins = pins
        self.__real_true = real_true
        for p in pins:
            self.__status.append(not real_true)

        if self.__real_true:
            self.__status[0] = GPIO.input(self.__pins[0])
            self.__status[1] = GPIO.input(self.__pins[1])
        else:
            self.__status[0] = not GPIO.input(self.__pins[0])
            self.__status[1] = not GPIO.input(self.__pins[1])


        GPIO.add_event_detect(self.__pins[0], GPIO.BOTH, callback = self.make_event, bouncetime = 50)
        GPIO.add_event_detect(self.__pins[1], GPIO.BOTH, callback = self.make_event, bouncetime = 50)

        try:
            t1 = Thread(target = self.watching)
            t1.setDaemon(True)
        except:
            print "Error: Unable to start thread by DipSwitch"

    #Stauts. 
开发者ID:spoonysonny,项目名称:SAKS-tutorials,代码行数:32,代码来源:dip_switch_2bit.py


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