Files
pybricks-api/doc/ev3dev/ev3brick.rst
T
Laurens Valk 0b67db897e api: generalize buttons
This makes the user code easier to read:

brick.buttons()

brick.buttons.pressed()

It also opens up possibility to add features in the future such as:
brick.buttons.released()  # return which buttons are not pressed
brick.buttons.clicked()  # return which buttons were clicked since we last checked

This follows the same style as the new light API: some devices have specific instances of a KeyPad class.

A good example that nicely demonstrates the concept is the LPF2 RemoteControl, which has instances of a ColorLight and a KeyPad. It's added in this commit.
2019-06-11 21:30:46 +02:00

133 lines
2.7 KiB
ReStructuredText

:mod:`ev3brick` -- The EV3 Programmable Brick
=============================================
.. automodule:: pybricks.ev3brick
:no-members:
Buttons
-------
.. automethod:: pybricks.ev3brick.buttons.pressed
Examples::
# Do something if the left button is pressed
if Button.LEFT in brick.buttons.pressed():
print("The left button is pressed.")
::
# Wait until any of the buttons are pressed
while not any(brick.buttons.pressed()):
wait(10)
# Wait until all buttons are released
while any(brick.buttons.pressed()):
wait(10)
Light
-----
.. automethod:: pybricks.ev3brick.light.on
Example::
# Make the light red
brick.light.on(Color.RED)
# Wait
wait(1000)
# Turn the light off
brick.light.off()
.. automethod:: pybricks.ev3brick.light.off
Sound
-----
.. automethod:: pybricks.ev3brick.sound.beep
Example::
# A simple beep
brick.sound.beep()
# A high pitch (1500 Hz) for one second (1000 ms) at 50% volume
brick.sound.beep(1500, 1000, 50)
.. automethod:: pybricks.ev3brick.sound.beeps
Example::
# Make 5 simple beeps
brick.sound.beeps(5)
.. automethod:: pybricks.ev3brick.sound.file
Example::
# Play one of the built-in sounds
brick.sound.file(SoundFile.HELLO)
# Play a sound file from your project folder
brick.sound.file('mysound.wav')
Display
-------
::
x
-------------->
(0, 0) __________________
| |
| | |
y | | Hello |
| | World |
v | |
|__________________|
(177, 127)
.. automethod:: pybricks.ev3brick.display.clear
Example::
# Clear the display
brick.display.clear()
.. automethod:: pybricks.ev3brick.display.text
Example::
# Print ``Hello`` near the middle of the screen
brick.display.text("Hello", (60, 50))
# Print ``World`` directly underneath it
brick.display.text("World")
.. automethod:: pybricks.ev3brick.display.image
Example::
# Show a built-in image of two eyes looking upward
brick.display.image(ImageFile.UP)
# Display a custom image from your project folder
brick.display.image('pybricks.png')
# Display a custom image at the top right of the screen,
# without clearing the screen first
brick.display.image('arrow.png', Align.TOP_RIGHT, clear=False)
Battery
-------
.. automethod:: pybricks.ev3brick.battery.voltage
.. automethod:: pybricks.ev3brick.battery.current