本文整理汇总了Python中RPi.GPIO.RISING属性的典型用法代码示例。如果您正苦于以下问题:Python GPIO.RISING属性的具体用法?Python GPIO.RISING怎么用?Python GPIO.RISING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类RPi.GPIO
的用法示例。
在下文中一共展示了GPIO.RISING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startKeyEvent
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [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 RISING [as 别名]
def __init__(self,
channel,
polarity=GPIO.FALLING,
pull_up_down=GPIO.PUD_UP,
debounce_time=0.08):
if polarity not in [GPIO.FALLING, GPIO.RISING]:
raise ValueError(
'polarity must be one of: GPIO.FALLING or GPIO.RISING')
self.channel = int(channel)
self.polarity = polarity
self.expected_value = polarity == GPIO.RISING
self.debounce_time = debounce_time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(channel, GPIO.IN, pull_up_down=pull_up_down)
self.callback = None
示例3: start_filament_detection
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [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)
示例4: main
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def main():
# report rail info
payload = {
"ip": os.popen('ip addr show eth0').read().split("inet ")[1].split("/")[0]
}
mqttClient.publish(DEVICE_INFO_TOPIC, json.dumps(payload), 0)
# open rail for default
move_servo(RAIL_OPEN)
# add event handler for buttons
GPIO.add_event_detect(GPIO_BTN_OPEN, GPIO.RISING, callback=btn_servo_pressed, bouncetime=BOUNCE_TIME)
GPIO.add_event_detect(GPIO_BTN_CLOSE, GPIO.RISING, callback=btn_servo_pressed, bouncetime=BOUNCE_TIME)
GPIO.add_event_detect(GPIO_BTN_POS1, GPIO.RISING, callback=btn_robot_pressed, bouncetime=BOUNCE_TIME)
GPIO.add_event_detect(GPIO_BTN_POS2, GPIO.RISING, callback=btn_robot_pressed, bouncetime=BOUNCE_TIME)
GPIO.add_event_detect(GPIO_BTN_POS3, GPIO.RISING, callback=btn_robot_pressed, bouncetime=BOUNCE_TIME)
# wait for events
while True:
time.sleep(1)
示例5: pushbutton
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def pushbutton(self):
if GPIOcontrol:
while mutestopbutton:
time.sleep(.1)
if GPIO.event_detected(stoppushbutton):
GPIO.remove_event_detect(stoppushbutton)
now = time.time()
count = 1
GPIO.add_event_detect(stoppushbutton,GPIO.RISING)
while time.time() < now + 1:
if GPIO.event_detected(stoppushbutton):
count +=1
time.sleep(.25)
if count == 2:
self.buttonsinglepress()
GPIO.remove_event_detect(stoppushbutton)
GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
elif count == 3:
self.buttondoublepress()
GPIO.remove_event_detect(stoppushbutton)
GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
elif count == 4:
self.buttontriplepress()
GPIO.remove_event_detect(stoppushbutton)
GPIO.add_event_detect(stoppushbutton,GPIO.FALLING)
示例6: setup_sensor
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [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)
示例7: prepare_irq_pin
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def prepare_irq_pin(self, pin_id):
pin = self.prepare_pin(pin_id, GPIO.IN)
if pin:
pin.set_handler_for_irq_on_rising_edge = \
lambda handler: GPIO.add_event_detect(pin.pin_id,
GPIO.RISING,
callback = handler)
pin.detach_irq = lambda : GPIO.remove_event_detect(pin.pin_id)
return pin
示例8: prepare_irq_pin
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def prepare_irq_pin(self, pin_id):
pin = self.prepare_pin(pin_id, GPIO.IN)
if pin:
pin.set_handler_for_irq_on_rising_edge = \
lambda handler: GPIO.add_event_detect(pin.pin_id,
GPIO.RISING,
callback = handler)
pin.detach_irq = lambda: GPIO.remove_event_detect(pin.pin_id)
return pin
示例9: initialize_gpio
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def initialize_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(Gmail.PIN, GPIO.OUT)
GPIO.setup(CHECK_NOW_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(CHECK_NOW_PIN, GPIO.RISING, callback=check_mail_now, bouncetime=1000)
示例10: user_shutdown_setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def user_shutdown_setup(shutdown_pin):
# setup the pin to check the shutdown switch - use the internal pull down resistor
GPIO.setup(shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# create a trigger for the shutdown switch
GPIO.add_event_detect(shutdown_pin, GPIO.RISING, callback=user_shutdown, bouncetime=1000)
# User has pressed shutdown button - initiate a clean shutdown
示例11: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def setup():
GPIO.setmode(GPIO.BCM) # Numbers GPIOs by physical location
GPIO.setup(SigPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set Pin's mode is input, and pull up to high level(3.3V)
GPIO.add_event_detect(SigPin, GPIO.RISING, callback=count) # wait for rasing
示例12: setup
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(SDI, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(RCLK, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(SRCLK, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(TouchPin, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.add_event_detect(TouchPin, GPIO.RISING, callback = randomISR, bouncetime = 20)
# Shift the data to 74HC595
示例13: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def __init__(self, pin):
super().__init__()
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
self.pin = pin
self.pressed = GPIO.input(self.pin) == GPIO.LOW
# Using a timer to Poll
#self.timer = qtc.QTimer(interval=50, timeout=self.check)
#self.timer.start()
# Using a threaded event handler
GPIO.add_event_detect(
self.pin,
GPIO.RISING,
callback=self.on_event_detect)
示例14: initpins
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def initpins(self):
# GPIO.setwarnings(False)
# GPIO.setmode(GPIO.BCM)
for po in self.colpins:
GPIO.setup(po,GPIO.OUT)
for pi in self.rowpins:
GPIO.setup(pi,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
try:
GPIO.remove_event_detect(pi)
except:
pass
time.sleep(0.05)
GPIO.add_event_detect(pi,GPIO.RISING, callback=self.inthandler,bouncetime=200)
示例15: __init__
# 需要导入模块: from RPi import GPIO [as 别名]
# 或者: from RPi.GPIO import RISING [as 别名]
def __init__(self, pin, name='Control',key=None, resistor=None, edge_detection=None, debounce=None):
self.pin = pin
self.name = name
self.key = key.replace(" ", "_").lower() if key is not None else self.name.replace(" ", "_").lower()
self.gpio = GPIO
self.debounce = debounce if debounce is not None else None
if resistor is not None:
if resistor == "up" or resistor == GPIO.PUD_UP:
self.resistor = GPIO.PUD_UP
elif resistor == "down" or resistor == GPIO.PUD_DOWN:
self.resistor = GPIO.PUD_DOWN
else:
self.resistor = resistor
if edge_detection is not None:
if edge_detection == "falling" or edge_detection == GPIO.FALLING:
self.edge_detection = GPIO.FALLING
elif edge_detection == "rising" or edge_detection == GPIO.RISING:
self.edge_detection = GPIO.RISING
elif edge_detection == "both" or edge_detection == GPIO.BOTH:
self.edge_detection = GPIO.BOTH
else:
self.edge_detection = None
return