From c322ffdc17dfe74d4f5b5bb4889946a5bdbe9799 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 9 Dec 2019 16:16:01 +0100 Subject: [PATCH] snippets/ev3/buttons: initial example --- snippets/ev3/buttons/.gitignore | 3 +++ snippets/ev3/buttons/.vscode/extensions.json | 13 +++++++++++++ snippets/ev3/buttons/.vscode/launch.json | 14 ++++++++++++++ snippets/ev3/buttons/.vscode/settings.json | 6 ++++++ snippets/ev3/buttons/main.py | 20 ++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 snippets/ev3/buttons/.gitignore create mode 100644 snippets/ev3/buttons/.vscode/extensions.json create mode 100644 snippets/ev3/buttons/.vscode/launch.json create mode 100644 snippets/ev3/buttons/.vscode/settings.json create mode 100644 snippets/ev3/buttons/main.py diff --git a/snippets/ev3/buttons/.gitignore b/snippets/ev3/buttons/.gitignore new file mode 100644 index 0000000..9b5f630 --- /dev/null +++ b/snippets/ev3/buttons/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.pyc +venv/ diff --git a/snippets/ev3/buttons/.vscode/extensions.json b/snippets/ev3/buttons/.vscode/extensions.json new file mode 100644 index 0000000..f8f1a44 --- /dev/null +++ b/snippets/ev3/buttons/.vscode/extensions.json @@ -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" + ] +} \ No newline at end of file diff --git a/snippets/ev3/buttons/.vscode/launch.json b/snippets/ev3/buttons/.vscode/launch.json new file mode 100644 index 0000000..af12883 --- /dev/null +++ b/snippets/ev3/buttons/.vscode/launch.json @@ -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" + } + ] +} diff --git a/snippets/ev3/buttons/.vscode/settings.json b/snippets/ev3/buttons/.vscode/settings.json new file mode 100644 index 0000000..37c9a5d --- /dev/null +++ b/snippets/ev3/buttons/.vscode/settings.json @@ -0,0 +1,6 @@ +// Place your settings in this file to overwrite default and user settings. +{ + "files.eol": "\n", + "debug.openDebug": "neverOpen", + "python.linting.enabled": false +} diff --git a/snippets/ev3/buttons/main.py b/snippets/ev3/buttons/main.py new file mode 100644 index 0000000..254bc79 --- /dev/null +++ b/snippets/ev3/buttons/main.py @@ -0,0 +1,20 @@ +#!/usr/bin/env pybricks-micropython + +from pybricks.hubs import EV3Brick +from pybricks.tools import wait, print +from pybricks.parameters import Button + +# Initialize the EV3 +ev3 = EV3Brick() + +# Wait until any of the buttons are pressed +while not any(ev3.buttons.pressed()): + wait(10) + +# Do something if the left button is pressed +if Button.LEFT in ev3.buttons.pressed(): + print("The left button is pressed.") + +# Wait until all buttons are released +while any(ev3.buttons.pressed()): + wait(10)