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


Python GPIO.add_event_callback方法代码示例

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


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

示例1: startKeyEvent

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

示例2: __init__

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_callback [as 别名]
def __init__(self, gpio = None, trigger = GPIO.FALLING, resistorpull = GPIO.PUD_UP, log = None, callback = None, uselibcallbacks = False, bouncetime = None):
        super(MyGPIOInput, self).__init__()
        self.Trigger = trigger
        self.ResistorPull = resistorpull
        self.GPIO = gpio
        self.log = log
        self.TimeoutSeconds = 1
        self.BounceTime = bouncetime
        self.Callback = callback
        self.UseLibCallbacks = uselibcallbacks
        self.Exiting = False

        try:

            GPIO.setmode(GPIO.BOARD)
            GPIO.setwarnings(True)
            GPIO.setup(gpio, GPIO.IN, pull_up_down=resistorpull)

            if callback != None and callable(callback):
                if self.BounceTime > 0:
                    GPIO.add_event_detect(gpio  = self.GPIO, edge = self.Trigger, bouncetime = self.BounceTime)
                else:
                    GPIO.add_event_detect(gpio  = self.GPIO, edge = self.Trigger)
                if self.UseLibCallbacks:
                    GPIO.add_event_callback(gpio = self.GPIO, callback = self.Callback)
                else:
                    # setup callback
                    self.Threads["GPIOInputMonitor"] = MyThread(self.GPIOInputMonitor, Name = "GPIOInputMonitor", start = False)
                    self.Threads["GPIOInputMonitor"].Start()

        except Exception as e1:
            self.LogErrorLine("Error in MyGPIOInput:init: " + str(gpio) + " : " + str(e1))

    #-----------------GPIOInputMonitor------------------------------------------ 
开发者ID:jgyates,项目名称:genmon,代码行数:36,代码来源:gengpioin.py

示例3: collect_temperature

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_callback [as 别名]
def collect_temperature():    
    humidity, temperature = Adafruit_DHT.read_retry(sensor_temperature, channel_temperature)
    logger.info("humidity: {} temperature: {}".format(humidity, temperature))
    if humidity is not None and temperature is not None:
        return humidity, temperature
    logger.error("Falha ao ler dados do DHT11")
    return 0, 0
    

#GPIO.add_event_detect(channel, GPIO.BOTH)
#GPIO.add_event_callback(channel, collect_moisture) 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:13,代码来源:moistureHandler.py

示例4: collect_moisture

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_callback [as 别名]
def collect_moisture(channel):
    # Efetua a leitura do sensor
    umid, temp = 0,0
    #umid, temp = Adafruit_DHT.read_retry(sensor, 4)    
    # Caso leitura esteja ok, mostra os valores na tela
    if umid is not None and temp is not None:
        print ("Temperatura = {0:0.1f}  Umidade = {1:0.1f}n").format(temp, umid)
        print ("Aguarda 5 segundos para efetuar nova leitura...n")
        publishTemperature(temp, umid)
    else:
        # Mensagem de erro de comunicacao com o sensor
        print("Falha ao ler dados do DHT11 !!!")

#GPIO.add_event_detect(channel, GPIO.BOTH)
#GPIO.add_event_callback(channel, collect_moisture) 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:17,代码来源:temperatureHandler.py

示例5: setup

# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import add_event_callback [as 别名]
def setup(robot_config):
    global mh
    global motorA
    global motorB
    global turningSpeedActuallyUsed
    global dayTimeDrivingSpeedActuallyUsed
    global nightTimeDrivingSpeedActuallyUsed
    global secondsToCharge
    global secondsToDischarge
    global chargeIONumber
    global forward
    global backward
    global left
    global right
    global straightDelay
    global turnDelay

    GPIO.setmode(GPIO.BCM)
    chargeIONumber = robot_config.getint('motor_hat', 'chargeIONumber')
    GPIO.setup(chargeIONumber, GPIO.IN)
    secondsToCharge = 60.0 * 60.0 * robot_config.getfloat('motor_hat', 'charge_hours')
    secondsToDischarge = 60.0 * 60.0 * robot_config.getfloat('motor_hat', 'discharge_hours')

    forward = json.loads(robot_config.get('motor_hat', 'forward'))
    backward = times(forward, -1)
    left = json.loads(robot_config.get('motor_hat', 'left'))
    right = times(left, -1)

    straightDelay = robot_config.getfloat('robot', 'straight_delay')
    turnDelay = robot_config.getfloat('robot', 'turn_delay')


    if motorsEnabled:
        # create a default object, no changes to I2C address or frequency
        mh = Adafruit_MotorHAT(addr=0x60)
        #mhArm = Adafruit_MotorHAT(addr=0x61)
        atexit.register(turnOffMotors)
        motorA = mh.getMotor(1)
        motorB = mh.getMotor(2)

    # Initialise the PWM device
#    pwm = PWM(0x42)
#    pwm.setPWMFreq(60)    # Set frequency to 60 Hz
    
    turningSpeedActuallyUsed = robot_config.getint('motor_hat', 'turning_speed')
    dayTimeDrivingSpeedActuallyUsed = robot_config.getint('motor_hat', 'day_speed')
    nightTimeDrivingSpeedActuallyUsed = robot_config.getint('motor_hat', 'night_speed')

    if robot_config.getboolean('motor_hat', 'slow_for_low_battery'):
        GPIO.add_event_detect(chargeIONumber, GPIO.BOTH)
        GPIO.add_event_callback(chargeIONumber, sendChargeStateCallback)
        chargeCheckInterval = int(robot_config.getint('motor_hat', 'chargeCheckInterval'))
    
        if (robot_config.get('tts', 'type') != 'none'):
            schedule.repeat_task(60, reportBatteryStatus_task)
            schedule.repeat_task(17, reportNeedToCharge)
            schedule.task(chargeCheckInterval, sendChargeState_task) 
开发者ID:letsRobot,项目名称:letsrobot,代码行数:59,代码来源:motor_hat.py


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