button_reaction.py 464 B

12345678910111213141516171819
  1. import utime
  2. import machine
  3. from hwconfig import LED, BUTTON
  4. # machine.time_pulse_us() function demo
  5. print("""\
  6. Let's play an interesting game:
  7. You click button as fast as you can, and I tell you how slow you are.
  8. Ready? Cliiiiick!
  9. """)
  10. while 1:
  11. delay = machine.time_pulse_us(BUTTON, 1, 10*1000*1000)
  12. if delay < 0:
  13. print("Well, you're *really* slow")
  14. else:
  15. print("You are as slow as %d microseconds!" % delay)
  16. utime.sleep_ms(10)