Skip to content
Discussion options

You must be logged in to vote

Here is an example (based on https://github.com/micropython/micropython/blob/master/examples/bluetooth/ble_uart_repl.py) that runs on a Pyboard and generates an "A" each time the pyboard's button is pressed.

Your code will need to do something different to get the key events, but ultimately implement read/readinto to return characters in a similar way.

import io
import pyb
import os

_MP_STREAM_POLL = const(3)
_MP_STREAM_POLL_RD = const(0x0001)

class ButtonStream(io.IOBase):
    def __init__(self, c):
        pyb.Switch().callback(self._press)
        self._n = 0
        self._c = c

    def _press(self):
        self._n += 1
        if hasattr(os, "dupterm_notify"):
            os.dupte…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jd3096-mpy
Comment options

@jimmo
Comment options

Answer selected by jd3096-mpy
@jd3096-mpy
Comment options

@rkompass
Comment options

@jimmo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #11599 on May 23, 2023 13:43.