本文整理汇总了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)
示例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------------------------------------------
示例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)
示例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)
示例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)