fushi

lightgoboingboing ver 1

Nov 11th, 2025 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.08 KB | None | 0 0
  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. # This program requires LEGO EV3 MicroPython v2.0 or higher.
  11. # Click "Open user guide" on the EV3 extension tab for more information.
  12.  
  13. my_left_kidney_ran_away_from_home_and_i_am_really_sad = Motor(Port.C)
  14. right_motor = Motor(Port.B)
  15. sacrifice = Motor(Port.A)
  16. devil = DriveBase(my_left_kidney_ran_away_from_home_and_i_am_really_sad, right_motor, wheel_diameter=57.15, axle_track=88.9)
  17. sensor = ColorSensor(Port.S1)
  18. # Color sensor is defined. It is in Sensor Port 1 (frontend) so we are putting S1.
  19.  
  20. # Defining values below so I don't have to do it later.
  21. one = 30
  22. # first sensor value
  23. two = 35
  24. # second sensor value
  25. w = 3
  26. # wait
  27. t = 10
  28. # turn
  29.  
  30. # This loop is for debugging. You can view the current reflection and adjust values based off it.
  31. # You can hit center to exit debugger. Alternatively, you can disable this section.
  32. while True:
  33.     ev3.screen.print(sensor.reflection)
  34.     if Button.CENTER in ev3.buttons.pressed():
  35.         ev3.screen.clear()
  36.         break
  37.     else:
  38.         ev3.screen.clear()
  39.         wait(5)
  40.  
  41. # W is wait time, T is turn radius to decide how much sensitivity is placed in the turn.
  42. # In theory, it should follow values based off one % two (with 5% in the middle as of current)
  43. # It will go forward if sensitivity is to the correct value, and if it is not, it will search for the line.
  44. while True:
  45.     if sensor.reflection > one%:
  46.         check = False
  47.         devil.forward(10)
  48.     elif sensor.reflection < two%:
  49.         check = True
  50.         devil.turn(t)
  51.         wait(w)
  52.         devil.turn(-t)
  53.         wait(w)
  54.         devil.turn(-t)
  55.         wait(w)
  56.         devil.turn(t)
  57.     elif check = False:
  58.         if devil.speed() < 8:
  59.             devil.hold()
  60.  
  61. # Below here is experimental code that may or may not work.
  62. # The point of this code is to automatically exit the loop once go = false (meaning robot is considered to be at a dead end.)
  63. # If robot is found to not be at a dead end (anymore) it will return to the line-searching loop.
  64.  
  65. # while True:
  66. #     while go = True:
  67. #         if sensor.reflection > one%:
  68. #             check = False
  69. #             devil.forward(10)
  70. #         elif sensor.reflection < two%:
  71. #             check = True
  72. #             devil.turn(t)
  73. #             wait(w)
  74. #             devil.turn(-t)
  75. #             wait(w)
  76. #             devil.turn(-t)
  77. #             wait(w)
  78. #             devil.turn(t)
  79. #         elif check = False
  80. #             if devil.speed < 8:
  81. #                 go = False
  82. #     while go = False:
  83. #         if sensor.reflection > one%:
  84. #             devil.forward(10)
  85. #             if devil.speed < 8:
  86. #                 devil.hold()
  87. #         else:
  88. #             wait(5)
Advertisement
Add Comment
Please, Sign In to add comment