event1.py 553 B

1234567891011121314151617181920212223242526
  1. import TemplateDevice
  2. import time
  3. io1 = TemplateDevice.GPIO()
  4. io1.setPin('PA8')
  5. io1.setMode('in')
  6. io1.enable()
  7. EVENT_SIGAL_IO_RISING_EDGE = 0x01
  8. EVENT_SIGAL_IO_FALLING_EDGE = 0x02
  9. callback_times = 0
  10. def callBack1(signal):
  11. global callback_times
  12. callback_times += 1
  13. print('callback_times: %d' % callback_times)
  14. if signal == EVENT_SIGAL_IO_RISING_EDGE:
  15. print('get rising edge!')
  16. elif signal == EVENT_SIGAL_IO_FALLING_EDGE:
  17. print('get falling edge!')
  18. else:
  19. return signal
  20. io1.addEventCallBack(callBack1)