import RPi.GPIO as GPIO def my_callback(channel): print("Pin state changed on channel %d" % channel) GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN) GPIO.add_event_detect(23, GPIO.BOTH, callback=my_callback) while True: pass
pip install RPi.GPIOOverall, the add_event_callback function is a powerful tool for creating responsive and interactive applications on the Raspberry Pi. With it, users can easily monitor and respond to changes in input, turning their projects into dynamic and flexible systems.