1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile from pybricks.messaging import BluetoothMailboxClient, TextMailbox
ev3 = EV3Brick() ev3.buttons.pressed() ev3.light.on(Color.RED) ev3.light.off()
ev3.speaker.beep() ev3.speaker.play_notes(['C4/4', 'C4/4', 'G4/4', 'G4/4'], tempo=120) ev3.speaker.play_file("123.mp3") ev3.speaker.say("hello,world") ev3.speaker.set_volume(60)
ev3.screen.clear() ev3.screen.draw_text(x, y, text, text_color=Color.BLACK, background_color=None) ev3.screen.print("hello,world")
ev3_img = Image(ImageFile.EV3_ICON) ev3.screen.load_image(ev3_img) ev3.screen.draw_image(10, 10, ev3_img, transparent=Color.RED) ev3.screen.draw_pixel(10, 10, color=Color.BLACK) ev3.screen.draw_line(x1, y1, x2, y2, width=1, color=Color.BLACK) ev3.screen.draw_box(x1, y1, x2, y2, r=0, fill=False, color=Color.BLACK) ev3.screen.draw_circle(x, y, r, fill=False, color=Color.BLACK)
ev3.battery.voltage() ev3.battery.current()
motor1 = Motor("A", positive_direction=Direction.CLOCKWISE, gears=None) motor1.speed() motor1.angle() motor1.reset_angle(angle) motor1.stop() motor1.brake() motor1.hold() motor1.run(5) motor1.run_time(5, 1000, then=Stop.HOLD, wait=True) motor1.run_angle(5, 60, then=Stop.HOLD, wait=True) motor1.run_target(5, 60, then=Stop.HOLD, wait=True) motor1.run_until_stalled(5, then=Stop.COAST, duty_limit=None)
touch_sensor = TouchSensor("S1") touch_sensor.pressed()
color_sensor = ColorSensor("S2") color_sensor.color() color_sensor.ambient() color_sensor.reflection() color_sensor.rgb()
ultrasonic_sensor = UltrasonicSensor("S3") ultrasonic_sensor.distance(silent=False) ultrasonic_sensor.presence()
gyro_sensor = GyroSensor("S4", positive_direction=Direction.CLOCKWISE) gyro_sensor.speed() gyro_sensor.angle() gyro_sensor.reset_angle(60)
wait(1000)
stop_watch = StopWatch() stop_watch.time() stop_watch.pause() stop_watch.resume() stop_watch.reset()
server = BluetoothMailboxServer() mbox = TextMailbox('greeting', server) print('waiting for connection...') server.wait_for_connection() print('connected!') mbox.wait() print(mbox.read()) mbox.send('hello to you!')
SERVER = 'ev3dev' client = BluetoothMailboxClient() mbox = TextMailbox('greeting', client) print('establishing connection...') client.connect(SERVER) print('connected!') mbox.send('hello!') mbox.wait() print(mbox.read())
|