Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import machine, time, gc
- def get_signals(pin):
- global count, time_prev, sig_buff
- #print("irq:", count)
- time_now = time.ticks_us()
- sig_buff.append((int(not pin.value()), time_now - time_prev))
- time_prev = time_now
- count += 1
- def show_signals():
- global sig_buff
- start = sig_buff[0][0]
- for i in sig_buff:
- if i[0] != start:
- return
- start = int(not start)
- print("r.write_pulses(%r, %r)\n%s\n" % ([i[1] for i in sig_buff[1:]], bool(sig_buff[1][0]), line))
- p1 = machine.Pin(27, machine.Pin.IN, machine.Pin.PULL_DOWN)
- p1.irq(handler = get_signals, trigger = machine.Pin.IRQ_FALLING | machine.Pin.IRQ_RISING)
- sig_buff = []; count = time_prev = 0; line = 20 * "_____"
- while True:
- gc.collect()
- while count < 300:
- pass
- irq_state = machine.disable_irq()
- show_signals()
- sig_buff.clear()
- count = 0
- machine.enable_irq(irq_state)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement