GeezerVison is showing github.com — add smallcar · WangLeGeWang/learn-python3@0b88c20
File treeExpand file treeCollapse file tree Open diff view settings samples/micropython/smallcar
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + // See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | | 3 | + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | | 4 | + | | 5 | + // List of extensions which should be recommended for users of this workspace. | | 6 | + "recommendations": [ | | 7 | + "lego-education.ev3-micropython" | | 8 | + ], | | 9 | + // List of extensions recommended by VS Code that should not be recommended for users of this workspace. | | 10 | + "unwantedRecommendations": [ | | 11 | + "ms-python.python" | | 12 | + ] | | 13 | +} |
Collapse file Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +{ | | 2 | + // Use IntelliSense to learn about possible attributes. | | 3 | + // Hover to view descriptions of existing attributes. | | 4 | + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | | 5 | + "version": "0.2.0", | | 6 | + "configurations": [ | | 7 | + { | | 8 | + "name": "Download and Run", | | 9 | + "type": "ev3devBrowser", | | 10 | + "request": "launch", | | 11 | + "program": "/home/robot/${workspaceRootFolderName}/main.py" | | 12 | + } | | 13 | + ] | | 14 | +} |
Collapse file Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Place your settings in this file to overwrite default and user settings. | | 2 | +{ | | 3 | + "files.eol": "\n", | | 4 | + "debug.openDebug": "neverOpen", | | 5 | + "python.linting.enabled": false, | | 6 | + "python.formatting.provider": "autopep8" | | 7 | +} |
Collapse file Copy file name to clipboard +51Lines changed: 51 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +#!/usr/bin/env pybricks-micropython | | 2 | + | | 3 | +from pybricks import ev3brick as brick | | 4 | +from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) | | 5 | +from pybricks.parameters import (Port, Stop, Direction, Button, Color, SoundFile, ImageFile, Align) | | 6 | +from pybricks.tools import print, wait, StopWatch | | 7 | +from pybricks.robotics import DriveBase | | 8 | + | | 9 | +# Write your program here | | 10 | + | | 11 | +motor = Motor(Port.B) | | 12 | +ultrasonic = UltrasonicSensor(Port.S4) | | 13 | + | | 14 | +brick.sound.beep() | | 15 | +brick.light(None) | | 16 | + | | 17 | +speed = 0 | | 18 | +colors = [None, Color.GREEN, Color.YELLOW, Color.RED] | | 19 | + | | 20 | +def setSpeed(acc): | | 21 | + global speed | | 22 | + if acc < 0: | | 23 | + speed = max(0, speed - 1) | | 24 | + elif acc > 0: | | 25 | + speed = min(3, speed + 1) | | 26 | + else: | | 27 | + speed = 0 | | 28 | + if speed > 0: | | 29 | + motor.run(speed * 90) | | 30 | + else: | | 31 | + motor.stop() | | 32 | + brick.light(colors[speed]) | | 33 | + | | 34 | +while True: | | 35 | + if not any(brick.buttons()): | | 36 | + wait(10) | | 37 | + else: | | 38 | + if Button.LEFT in brick.buttons(): | | 39 | + setSpeed(-1) | | 40 | + elif Button.RIGHT in brick.buttons(): | | 41 | + setSpeed(1) | | 42 | + elif Button.CENTER in brick.buttons(): | | 43 | + setSpeed(0) | | 44 | + elif Button.UP in brick.buttons(): | | 45 | + setSpeed(0) | | 46 | + break | | 47 | + wait(500) | | 48 | + if ultrasonic.distance() < 200: | | 49 | + setSpeed(0) | | 50 | + | | 51 | +brick.sound.beep() |
|