简体   繁体   中英

How to make use of events in Python on to call a function when a button is pressed on the HAT?

Apologies if this is the wrong place for this question. Bit of a Python newbie, but I'm getting there with it, I've just hit a bit of a brick wall.

I'm building a Pi project that uses the Pimoroni Display Hat Mini ( https://shop.pimoroni.com/products/display-hat-mini ) and the associated library ( https://github.com/pimoroni/displayhatmini-python ).

What I'm struggling with is making use of Python events to call a function when any of the 4 buttons are pressed.

I've imported the RPi.GPIO library, but what seems to be the issue I'm running into is the Display Hat Mini library already has events created (is that the right term?), so when I try to do that with the GPIO library:

GPIO.setup(display.BUTTON_A, GPIO.IN)
GPIO.add_event_detect(display.BUTTON_A, GPIO.RISING)
GPIO.add_event_callback(display.BUTTON_A, my_callback_one)

I get:

RuntimeError: Conflicting edge detection already enabled for this GPIO channel

I assume this must be from the Display library, but I'm at a bit of a loss as to how to progress from here.

Any advice/pointers greatly appreciated.

Detection of this event is already running. You have two options to remove it:

  1. GPIO.remove_event_detect(display.BUTTON_A)
  2. GPIO.cleanup()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM