Advertisement
Guest User

picoledsboton

a guest
May 4th, 2023
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | Source Code | 0 0
  1. import machine
  2. import utime
  3. import urandom
  4.  
  5. pressed = False
  6. led_verde = machine.Pin(15, machine.Pin.OUT)
  7. led_rojo = machine.Pin(11, machine.Pin.OUT)
  8. led_amarillo = machine.Pin(13, machine.Pin.OUT)
  9. button = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)
  10.  
  11. def button_handler(pin):
  12. global pressed
  13. if not pressed:
  14. pressed=True
  15. timer_reaction = utime.ticks_diff(utime.ticks_ms(), timer_start)
  16. print ("tu reacción fue " + str(timer_reaction) +
  17. " milliseconds!")
  18.  
  19. led_verde.value(1)
  20. utime.sleep(urandom.uniform(5, 10))
  21. led_verde.value(0)
  22. timer_start = utime.ticks_ms()
  23. button.irq(trigger=machine.Pin.IRQ_RISING, handler=button_handler)
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement