mirror of
https://github.com/pybricks/pybricks-projects.git
synced 2026-09-14 18:44:20 +00:00
snippets/ev3/buttons_quickstart: initial project
This is a demo of: - multi-file project - using images - creating a "menu" This program can be started away from the competition table. Then a mission can be quickly activated by pressing one of the buttons.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
venv/
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
"lego-education.ev3-micropython"
|
||||
],
|
||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||
"unwantedRecommendations": [
|
||||
"ms-python.python"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Download and Run",
|
||||
"type": "ev3devBrowser",
|
||||
"request": "launch",
|
||||
"program": "/home/robot/${workspaceRootFolderName}/main.py"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.eol": "\n",
|
||||
"debug.openDebug": "neverOpen",
|
||||
"python.linting.enabled": false,
|
||||
"ev3devBrowser.download.exclude": "{**/.*,**/*.svg}"
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="178"
|
||||
height="128"
|
||||
viewBox="0 0 47.095832 33.866668"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="0.92.3 (2405546, 2018-03-11)"
|
||||
sodipodi:docname="buttons.svg"
|
||||
inkscape:export-filename="buttons.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="1"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="3.959798"
|
||||
inkscape:cx="95.61633"
|
||||
inkscape:cy="59.069332"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1172"
|
||||
inkscape:window-x="1920"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
units="px" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-263.13332)">
|
||||
<g
|
||||
id="g902"
|
||||
transform="matrix(0.95808471,0,0,0.95808471,2.2603677,8.2065667)">
|
||||
<path
|
||||
sodipodi:nodetypes="ccccccccccccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path826"
|
||||
d="m 16.426577,278.66756 v -3.65654 l -2.03331,-2.0333 5.407037,-5.45361 h 6.57702 l 5.276386,5.27638 -1.936759,1.93676 v 3.93031 H 27.55869 v -2.63536 c -0.02145,-0.56645 -0.457827,-1.225 -1.215443,-1.21545 l -6.472149,0.0466 c -0.859483,0.0241 -1.289242,0.61856 -1.289277,1.28929 v 2.53879 z"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.09010255;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<rect
|
||||
ry="0.48594931"
|
||||
rx="0.48594931"
|
||||
y="276.09946"
|
||||
x="19.694563"
|
||||
height="6.7310009"
|
||||
width="6.7310009"
|
||||
id="rect830"
|
||||
style="fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.09010255;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path832"
|
||||
d="m 36.519182,276.14245 a 3.1807595,3.1807595 0 0 0 -0.225076,0.008 h -5.220895 v 6.34453 h 5.265875 a 3.1807595,3.1807595 0 0 0 0.180096,0.009 3.1807595,3.1807595 0 0 0 3.180785,-3.18078 3.1807595,3.1807595 0 0 0 -3.180785,-3.18061 z"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.09010255;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.09010255;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 9.6389609,276.14245 a 3.1807595,3.1807595 0 0 1 0.2250761,0.008 h 5.220895 v 6.34453 H 9.8190572 a 3.1807595,3.1807595 0 0 1 -0.1800963,0.009 3.1807595,3.1807595 0 0 1 -3.1807864,-3.18078 3.1807595,3.1807595 0 0 1 3.1807864,-3.18061 z"
|
||||
id="path841" />
|
||||
<path
|
||||
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.09010255;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 16.426577,280.20003 v 3.65654 l -2.03331,2.0333 5.407037,5.45361 h 6.57702 l 5.276386,-5.27638 -1.936759,-1.93676 v -3.93031 H 27.55869 v 2.63536 c -0.02145,0.56645 -0.457827,1.225 -1.215443,1.21545 l -6.472149,-0.0466 c -0.859483,-0.0241 -1.289242,-0.61856 -1.289277,-1.28929 v -2.53879 z"
|
||||
id="path822"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="ccccccccccccccc" />
|
||||
</g>
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
||||
d="M 2.2049736,289.18236 H 44.567193"
|
||||
id="path818"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.5 KiB |
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env pybricks-micropython
|
||||
|
||||
from pybricks.hubs import EV3Brick
|
||||
from pybricks.parameters import Button
|
||||
|
||||
from menu import wait_for_button
|
||||
|
||||
# Initialize the EV3.
|
||||
ev3 = EV3Brick()
|
||||
|
||||
while True:
|
||||
# Show the menu and wait for one button to be selected.
|
||||
button = wait_for_button(ev3)
|
||||
|
||||
# Now you can do something, based on which button was pressed.
|
||||
|
||||
# In this demo, we just play a different sound for each button.
|
||||
if button == Button.LEFT:
|
||||
ev3.speaker.beep(200)
|
||||
elif button == Button.RIGHT:
|
||||
ev3.speaker.beep(400)
|
||||
elif button == Button.UP:
|
||||
ev3.speaker.beep(600)
|
||||
elif button == Button.DOWN:
|
||||
ev3.speaker.beep(800)
|
||||
elif button == Button.CENTER:
|
||||
ev3.speaker.beep(1000)
|
||||
@@ -0,0 +1,30 @@
|
||||
def wait_for_button(ev3):
|
||||
"""
|
||||
This function shows a picture of the buttons on the EV3 screen.
|
||||
|
||||
Then it waits until you press a button.
|
||||
|
||||
It returns which button was pressed.
|
||||
"""
|
||||
|
||||
# Show a picture of the buttons on the screen.
|
||||
ev3.screen.load_image('buttons.png')
|
||||
|
||||
# Tip: add text or icons to the image to help you
|
||||
# remember what each button will do in your program.
|
||||
|
||||
# Wait for a single button to be pressed and save the result.
|
||||
pressed = []
|
||||
while len(pressed) != 1:
|
||||
pressed = ev3.buttons.pressed()
|
||||
button = pressed[0]
|
||||
|
||||
# Print which button was pressed
|
||||
ev3.screen.draw_text(2, 100, button)
|
||||
|
||||
# Now wait for the button to be released.
|
||||
while any(ev3.buttons.pressed()):
|
||||
pass
|
||||
|
||||
# Return which button was pressed.
|
||||
return button
|
||||
Reference in New Issue
Block a user