def wait_until_bumped(self, wait_timer=500):
        """Wait until the TouchSensor is bumped

        :param wait_timer: Time to wait (milliseconds) to consider a press and release a bump,
                           defaults to 500
        :type wait_timer: int, float, optional
        """
        if not isinstance(wait_timer, (int, float)):
            return
        my_watch = StopWatch()
        while True:
            self.wait_until_pressed()
            my_watch.reset()
            my_watch.resume()
            self.wait_until_released()
            my_watch.pause()
            if my_watch.time() > wait_timer:
                continue
            return
    def wait_until_button_bumped(self, button, channel, wait_timer=500):
        """Waits until a specified button has been bumped

        ''NOTE: using a list, tuple or dict for buttons will make this function act the same as
        wait_until_button_pressed if all of the buttons listed are pressed at once''

        :param button: Button or Buttons to wait for
        :type button: Button, list, tuple, dict
        :param channel: Channel number of the remote
        :type channel: int
        """
        if not isinstance(wait_timer, (int, float)):
            return
        my_watch = StopWatch()
        while True:
            self.wait_until_button_pressed(button, channel)
            my_watch.reset()
            my_watch.resume()
            self.wait_until_button_released(button, channel)
            my_watch.pause()
            if my_watch.time() > wait_timer:
                continue
            return
Ejemplo n.º 3
0
from pybricks.parameters import Icon, Side
from pybricks.geometry import Matrix
from pybricks import version

print(version)

from urandom import randint

hub = InventorHub()

# Display random pixels, in and out of bounds
ITERATIONS = 5000
watch = StopWatch()
for i in range(ITERATIONS):
    hub.display.pixel(row=randint(-30, 30), column=randint(-30, 30), brightness=randint(-20, 150))
watch.pause()
print("Showing", ITERATIONS, "random pixels took", watch.time(), "ms, or ", watch.time()/ITERATIONS*1000, "us per pixel.")

# Turn display off
hub.display.off()

# Display some images in different orientations
for side in (Side.TOP, Side.LEFT, Side.BOTTOM, Side.RIGHT, Side.FRONT):
    hub.display.orientation(side)
    hub.display.image(Icon.UP)
    wait(500)

# Display image composites
hub.display.image(Icon.ARROW_LEFT_DOWN + Icon.ARROW_RIGHT_UP)
wait(1000)