[text] ev3

Viewer

  1. #!/usr/bin/env pybricks-micropython
  2. from pybricks.hubs import EV3Brick
  3. from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
  4.                                  InfraredSensor, UltrasonicSensor, GyroSensor)
  5. from pybricks.parameters import Port, Stop, Direction, Button, Color
  6. from pybricks.tools import wait, StopWatch, DataLog
  7. from pybricks.robotics import DriveBase
  8. from pybricks.media.ev3dev import SoundFile, ImageFile
  9.  
  10.  
  11. # This program requires LEGO EV3 MicroPython v2.0 or higher.
  12. # Click "Open user guide" on the EV3 extension tab for more information.
  13.  
  14.  
  15. # Create your objects here.
  16. ev3 = EV3Brick()
  17. eye = UltrasonicSensor(Port.S4)
  18. left_motor = Motor(Port.B)
  19. right_motor = Motor(Port.C)
  20. gun = Motor(Port.A)
  21.  
  22. # Write your program here.
  23. #ev3.speaker.beep()
  24. ev3.speaker.play_file(SoundFile.LASER)
  25. ev3.screen.print("Ya")
  26. wait(1000)
  27. while True:
  28.     ev3.screen.print(eye.distance())
  29.  
  30.     left_motor.run(25)
  31.     right_motor.run(-25)
  32.     if eye.distance() <= 700:
  33.         wait(600)
  34.         #left_motor.stop()
  35.         #right_motor.stop()
  36.         #ev3.speaker.say("fire")
  37.         #left_motor.run_time(-50, 1000, Stop.HOLD, True)
  38.         #right_motor.run_time(50, 1000, Stop.HOLD, True)
  39.         gun.run_time(800, 500, Stop.HOLD, True)
  40.         gun.run_time(-800, 500, Stop.HOLD, True)
  41.         while not ev3.buttons.pressed():
  42.             pass
  43.  

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: