Skip to content

Commit 0b88c20

Browse files
committed
add smallcar
1 parent 2c9b880 commit 0b88c20

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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()

0 commit comments

Comments
 (0)