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


Python GPIO.add_event_detect方法代码示例

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


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

示例1: event_loop

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

            count =0

            keys_per_rev=5
            key_press_delay=0.05
            inter_key_delay=0.1
            last_time=0
            current_time=0

            GPIO.add_event_detect(DeskCycle.PIN, GPIO.FALLING, callback=self.pin_event,bouncetime=100) 

            while True:

                if(self.hitCount >0):
                    count+=1
                    print "Hit ",count
                    self.hitCount-=1

                time.sleep(0.01) 
开发者ID:yaptb,项目名称:BlogCode,代码行数:22,代码来源:deskcycle_test.py

示例2: startKeyEvent

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def startKeyEvent(self):
        print('Start Key Event Catcher')
        # Add return key to interrupt callback
        pins = [27, 23, 4, 17, 22, 5, 6]  # [L, R, C, U, D, A, B]
        # Add each to to key detect
        for i in pins:
            GPIO.add_event_detect(i, GPIO.RISING)

        # GPIO.add_event_callback(27, callback=self._semitone_down)
        # GPIO.add_event_callback(23, callback=self._semitone_up)
        # GPIO.add_event_callback(4, callback=self._reset_change)
        # GPIO.add_event_callback(17, callback=self._octave_up)
        # GPIO.add_event_callback(22, callback=self._octave_down)
        GPIO.add_event_callback(5, callback=self.stopInterruptCallBack)
        # GPIO.add_event_callback(6, callback=self.stopInterruptCallBack)

        # GPIO.add_event_callback(27, callback=self.leftKey)
        # GPIO.add_event_callback(23, callback=self.rightKey)
        # GPIO.add_event_callback(4, callback=self.centerKey)
        # GPIO.add_event_callback(17, callback=self.upKey)
        # GPIO.add_event_callback(22, callback=self.downKay)
        # GPIO.add_event_callback(5, callback=self.aKey)
        # GPIO.add_event_callback(6, callback=self.bKey) 
开发者ID:adwuard,项目名称:OP_Manager,代码行数:25,代码来源:Midi.py

示例3: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def setup():
    global _is_setup

    if _is_setup:
        return True

    atexit.register(_exit)

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup([DAT, CLK], GPIO.OUT)
    GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    for button in BUTTONS:
        GPIO.add_event_detect(button, GPIO.FALLING, callback=_handle_button, bouncetime=200)

    _is_setup = True 
开发者ID:pimoroni,项目名称:phat-beat,代码行数:19,代码来源:__init__.py

示例4: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [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

示例5: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [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

示例6: main

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def main():
    global pulses

    ## We're using BCM Mode
    GPIO.setmode(GPIO.BCM)

    ## Setup coin interrupt channel
    GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    # GPIO.setup(PIN_COIN_INTERRUPT,GPIO.IN)
    GPIO.add_event_detect(6, GPIO.FALLING, callback=coinEventHandler)

    while True:
        time.sleep(0.5)
        if (time.time() - lastImpulse > 0.5) and (pulses > 0):
            if pulses == 1:
                print("Coin 1")
            pulses = 0

    GPIO.cleanup()


# handle the coin event 
开发者ID:21isenough,项目名称:LightningATM,代码行数:24,代码来源:acceptor_test.py

示例7: on

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def on(buttons, bounce=BOUNCE):
    """Handle a joystick direction or button push

    Decorator. Use with @joystick.on(joystick.UP)

    :param buttons: List, or single instance of joystick button constant
    :param bounce: Debounce delay in milliseconds: default 300

    """

    buttons = buttons if isinstance(buttons, list) else [buttons]

    def register(handler):
        for button in buttons:
            GPIO.remove_event_detect(button)
            GPIO.add_event_detect(button, GPIO.FALLING, callback=handler, bouncetime=bounce)

    return register 
开发者ID:pimoroni,项目名称:displayotron,代码行数:20,代码来源:joystick.py

示例8: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [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

示例9: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [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

示例10: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def __init__(self):
        self.__RESET = 26

        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)

        GPIO.setup(self.__RESET, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # Do not proceed unless the reset signal has turned off
        # attempt to prevent restart storm in systemd

        print("waiting for reset to complete.")
        while GPIO.input(self.__RESET) != 1:
            time.sleep(0.100)
            pass

        GPIO.add_event_detect(
            self.__RESET, GPIO.FALLING, callback=onReset, bouncetime=100
        )
        print("GPIO initialized.") 
开发者ID:jedimatt42,项目名称:tipi,代码行数:21,代码来源:TipiWatchDogService.py

示例11: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def setup():
	global counter
	global Last_RoB_Status, Current_RoB_Status
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(RoAPin, GPIO.IN)
	GPIO.setup(RoBPin, GPIO.IN)
	GPIO.setup(RoSPin,GPIO.IN, pull_up_down=GPIO.PUD_UP)
	# Set up a falling edge detect to callback clear
	GPIO.add_event_detect(RoSPin, GPIO.FALLING, callback=clear)

	# Set up a counter as a global variable
	counter = 0
	Last_RoB_Status = 0
	Current_RoB_Status = 0

# Define a function to deal with rotary encoder 
开发者ID:sunfounder,项目名称:SunFounder_Super_Kit_V3.0_for_Raspberry_Pi,代码行数:18,代码来源:12_rotaryEncoder.py

示例12: _setup_callback

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [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

示例13: start_filament_detection

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def start_filament_detection(self):
        self.stop_filament_detection()
        try:
            for filament_sensor in list(filter(
                    lambda item: item['input_type'] == 'gpio' and item['action_type'] == 'printer_control' and item[
                        'printer_action'] == 'filament', self.rpi_inputs)):
                edge = GPIO.RISING if filament_sensor['edge'] == 'rise' else GPIO.FALLING
                if GPIO.input(self.to_int(filament_sensor['gpio_pin'])) == (edge == GPIO.RISING):
                    self._printer.pause_print()
                    self._logger.info("Started printing with no filament.")
                else:
                    self.last_filament_end_detected.append(dict(index_id=filament_sensor['index_id'], time=0))
                    self._logger.info("Adding GPIO event detect on pin %s with edge: %s", filament_sensor['gpio_pin'],
                        edge)
                    GPIO.add_event_detect(self.to_int(filament_sensor['gpio_pin']), edge,
                        callback=self.handle_filamment_detection, bouncetime=200)
        except Exception as ex:
            self.log_error(ex) 
开发者ID:vitormhenrique,项目名称:OctoPrint-Enclosure,代码行数:20,代码来源:__init__.py

示例14: setup_sensor

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def setup_sensor(self):
		try:
			GPIO.setup(self.gpio, GPIO.IN)
			GPIO.add_event_detect(self.gpio, GPIO.RISING, callback=self.cb_alarm, bouncetime=self.bouncetime)
		except ValueError as ve: # GPIO pin number or bouncetime is not in valid range
			logging.error("GPIOSensor: The given pin number or bouncetime is not in a valid range: %s" % ve)
			return
		logging.debug("GPIOSensor: Registered sensor at pin %s!" % self.gpio) 
开发者ID:SecPi,项目名称:SecPi,代码行数:10,代码来源:gpio_sensor.py

示例15: haltSystem

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_detect [as 别名]
def haltSystem():
    print 'Halt...'
    os.system("sudo halt")
    
# GPIO.add_event_detect(HALT_PIN, GPIO.FALLING, callback = haltSystem, bouncetime = 2000) 
开发者ID:pierre-muth,项目名称:polapi-zero,代码行数:7,代码来源:polapizero_09.py


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