GPIO.add.event.detect alternative for Automation Hat input

Hello,
I´m new newbie in programming Automation Hat in Python, and I would like to know how/or with replace GPIO.add.event.detect command in my python program? I have set some def and I want callback this event when I press button connected to Hat input.
I try while cycle, but this is unsuitable for me, because I want get signal just once to def.
I want something like this when I using GPIO:

def pressbutton(channel):
my def subprogram
.
.
.
GPIO.add_event_detect(8,GPIO.BOTH,callback=pressbutton)

Using RPi.GPIO directly is the best way, you can find the GPIO pin for various inputs here: https://pinout.xyz/pinout/automation_hat

Thank you for your replying.
I try use directly GPIO, but I cant set GPIO and automation hat at the same time to one .py, or is it some way how to set using GPIO together with AutomationHat commands?
When I run program I get error:
Traceback (most recent call last):
File “pokus.py”, line 20, in program
AutomationHat()
File “pokus.py”, line 30, in AutomationHat
hat.relay.one.on()
File “/usr/lib/python2.7/dist-packages/automationhat/init.py”, line 230, in on
self.write(1)
File “/usr/lib/python2.7/dist-packages/automationhat/init.py”, line 273, in write
self.setup()
File “/usr/lib/python2.7/dist-packages/automationhat/init.py”, line 259, in setup
setup()
File “/usr/lib/python2.7/dist-packages/automationhat/init.py”, line 343, in setup
GPIO.setmode(GPIO.BCM)
ValueError: A different mode has already been set!

Ooh, looks like you’ve found a bug with Automation HAT’s deferred loading. I’ll have to catch that error and ignore it.

For the time being, rather than calling GPIO.setmode(GPIO.BCM) in your user code, you could run automationhat.setup()

Actually you should only see this error if you’re using a mode other than GPIO.BCM, if you just use BCM it’ll go away.

The modes are not compatible with each other, so you can’t use BOARD pin numberings while Automation HAT uses GPIO or Automation HAT will get confused about what pins it’s accessing.

1 Like

Great, when I changed to BCM, .py run correct.
Thank you.