mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 09:05:07 +00:00
all: Format with ruff.
This commit is contained in:
@@ -12,7 +12,6 @@ hub.system.set_stop_button(None)
|
||||
# Check the button for 5 seconds.
|
||||
watch = StopWatch()
|
||||
while watch.time() < 5000:
|
||||
|
||||
# Set light to green if pressed, else red.
|
||||
if hub.buttons.pressed():
|
||||
hub.light.on(Color.GREEN)
|
||||
|
||||
@@ -9,7 +9,6 @@ hub = ThisHub()
|
||||
# Get the acceleration or angular_velocity along a single axis.
|
||||
# If you need only one value, this is more memory efficient.
|
||||
while True:
|
||||
|
||||
# Read the forward acceleration.
|
||||
forward_acceleration = hub.imu.acceleration(Axis.X)
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ SIDE_COLORS = {
|
||||
|
||||
# Keep updating the color based on detected up side.
|
||||
while True:
|
||||
|
||||
# Check which side of the hub is up.
|
||||
up_side = hub.imu.up()
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ hub = ThisHub()
|
||||
|
||||
# Turn the light on and off 5 times.
|
||||
for i in range(5):
|
||||
|
||||
hub.light.on(Color.RED)
|
||||
wait(1000)
|
||||
|
||||
|
||||
@@ -13,9 +13,7 @@ file_paths = [f for f in dir_path.glob("*.py") if f.stem != "make_examples"]
|
||||
|
||||
# Go through all template scripts
|
||||
for file_path in file_paths:
|
||||
|
||||
with open(file_path) as template:
|
||||
|
||||
# First line contains hub info
|
||||
hubs = template.readline().strip().split()[3:]
|
||||
|
||||
@@ -31,9 +29,7 @@ for file_path in file_paths:
|
||||
|
||||
# Open destination script:
|
||||
with open(gen_path, "w") as dest_file:
|
||||
|
||||
# Read script line by line.
|
||||
for line in template.readlines():
|
||||
|
||||
# Replace hub name if present.
|
||||
dest_file.writelines(line.replace("ThisHub", hub))
|
||||
|
||||
@@ -10,7 +10,6 @@ hub.system.set_stop_button((Button.CENTER, Button.BLUETOOTH))
|
||||
|
||||
# Now we can use the center button as a normal button.
|
||||
while True:
|
||||
|
||||
# Play a sound if the center button is pressed.
|
||||
if Button.CENTER in hub.buttons.pressed():
|
||||
hub.speaker.beep()
|
||||
|
||||
@@ -9,7 +9,6 @@ hub = PrimeHub()
|
||||
hub.display.orientation(up=Side.RIGHT)
|
||||
|
||||
while True:
|
||||
|
||||
# Start with random left brow: up or down.
|
||||
if randint(0, 100) < 70:
|
||||
brows = Icon.EYE_LEFT_BROW * 0.5
|
||||
|
||||
@@ -6,7 +6,6 @@ from pybricks.tools import wait
|
||||
hub = PrimeHub()
|
||||
|
||||
while True:
|
||||
|
||||
# Check which side of the hub is up.
|
||||
up_side = hub.imu.up()
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ except AttributeError:
|
||||
|
||||
# Go through all available ports.
|
||||
for port in ports:
|
||||
|
||||
# Try to get the device, if it is attached.
|
||||
try:
|
||||
device = PUPDevice(port)
|
||||
|
||||
@@ -6,7 +6,6 @@ from pybricks.tools import wait
|
||||
example_motor = Motor(Port.A)
|
||||
|
||||
while True:
|
||||
|
||||
# Get the default angle value.
|
||||
angle = example_motor.angle()
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ example_motor.run(300)
|
||||
|
||||
# Display the angle and speed 50 times.
|
||||
for i in range(100):
|
||||
|
||||
# Read the angle (degrees) and speed (degrees per second).
|
||||
angle = example_motor.angle()
|
||||
speed = example_motor.speed()
|
||||
|
||||
@@ -9,7 +9,6 @@ try:
|
||||
# Here you can write code that uses the remote.
|
||||
|
||||
except OSError:
|
||||
|
||||
print("Could not find the remote.")
|
||||
|
||||
# Here you can make your robot do something
|
||||
|
||||
@@ -7,7 +7,6 @@ sensor = ColorSensor(Port.A)
|
||||
|
||||
# Repeat forever.
|
||||
while True:
|
||||
|
||||
# Get the ambient color values. Instead of scanning the color of a surface,
|
||||
# this lets you scan the color of light sources like lamps or screens.
|
||||
hsv = sensor.hsv(surface=False)
|
||||
|
||||
@@ -7,7 +7,6 @@ sensor = ColorSensor(Port.A)
|
||||
|
||||
# Repeat forever.
|
||||
while True:
|
||||
|
||||
# Turn on one light at a time, at half the brightness.
|
||||
# Do this for all 3 lights and repeat that 5 times.
|
||||
for i in range(5):
|
||||
|
||||
@@ -15,7 +15,6 @@ def wait_for_color(desired_color):
|
||||
|
||||
# Now we use the function we just created above.
|
||||
while True:
|
||||
|
||||
# Here you can make your train/vehicle go forward.
|
||||
|
||||
print("Waiting for red ...")
|
||||
|
||||
@@ -7,10 +7,8 @@ sensor = ColorDistanceSensor(Port.A)
|
||||
|
||||
# Repeat forever.
|
||||
while True:
|
||||
|
||||
# If the sensor sees an object nearby.
|
||||
if sensor.distance() <= 40:
|
||||
|
||||
# Then blink the light red/blue 5 times.
|
||||
for i in range(5):
|
||||
sensor.light.on(Color.RED)
|
||||
|
||||
@@ -15,7 +15,6 @@ def wait_for_color(desired_color):
|
||||
|
||||
# Now we use the function we just created above.
|
||||
while True:
|
||||
|
||||
# Here you can make your train/vehicle go forward.
|
||||
|
||||
print("Waiting for red ...")
|
||||
|
||||
Reference in New Issue
Block a user