- #!/usr/bin/env pybricks-micropython
- 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
- # This program requires LEGO EV3 MicroPython v2.0 or higher.
- # Click "Open user guide" on the EV3 extension tab for more information.
- # Create your objects here.
- ev3 = EV3Brick()
- eye = UltrasonicSensor(Port.S4)
- left_motor = Motor(Port.B)
- right_motor = Motor(Port.C)
- gun = Motor(Port.A)
- # Write your program here.
- #ev3.speaker.beep()
- ev3.speaker.play_file(SoundFile.LASER)
- ev3.screen.print("Ya")
- wait(1000)
- while True:
- ev3.screen.print(eye.distance())
- left_motor.run(25)
- right_motor.run(-25)
- if eye.distance() <= 700:
- wait(600)
- #left_motor.stop()
- #right_motor.stop()
- #ev3.speaker.say("fire")
- #left_motor.run_time(-50, 1000, Stop.HOLD, True)
- #right_motor.run_time(50, 1000, Stop.HOLD, True)
- gun.run_time(800, 500, Stop.HOLD, True)
- gun.run_time(-800, 500, Stop.HOLD, True)
- while not ev3.buttons.pressed():
- pass
[text] ev3
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new:
File Description
- ev3
- Paste Code
- 24 Sep-2021
- 1.36 Kb
You can Share it:
Latest Code Pastes