fushi

lightgoboingboing ver 2

Nov 12th, 2025 (edited)
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.75 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.  
  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. ev3 = EV3Brick()
  15. sensor = ColorSensor(Port.S2              )
  16. my_left_kidney_ran_away_from_home_and_i_am_really_sad = Motor(Port.C)
  17. right_motor = Motor(Port.B)
  18. sacrifice = Motor(Port.A)
  19. devil = DriveBase(my_left_kidney_ran_away_from_home_and_i_am_really_sad, right_motor, wheel_diameter=57.15, axle_track=88.9)
  20.  
  21. # This loop is for debugging. You can view the current reflection and adjust values based off it.
  22. # You can hit center to exit debugger. In Visual Code, highlighting it and pressing Ctrl+/ will uncomment it.
  23. ev3.speaker.beep()
  24. print('Program start')
  25. # while True:
  26. #     ev3.screen.print(sensor.reflection())
  27. #     print(sensor.reflection())
  28. #     if Button.CENTER in ev3.buttons.pressed():
  29. #         ev3.screen.clear()
  30. #         break
  31. #     else:
  32. #         wait(100)
  33. #         ev3.screen.clear()
  34.  
  35. one = 2
  36. two = 3
  37. t = 60
  38. w = 500
  39. a = 1
  40.  
  41. # W is wait time, T is turn radius to decide how much sensitivity is placed in the turn.
  42. # One decides the first loop's threshold (meaning it will trigger if reflectively is less or equal to value)
  43. # Two decides the second loop's threshold (it will only trigger if reflectively is equal to or higher than 3)
  44. # I think I can shorten it by just stating "greater than (one)"
  45.  
  46. while True:
  47.     print ('#1,', sensor.reflection())
  48.     if sensor.reflection() <= one:
  49.         t = 60
  50.         w = 500
  51.         devil.drive(150, 0)
  52.         a = 1
  53.     else:
  54.         while sensor.reflection() >= two:
  55.             print ('#2,', sensor.reflection())
  56.             devil.drive(0, t)
  57.             if sensor.reflection() <= one:
  58.                 break
  59.             wait(w)
  60.             devil.drive(0, -t)
  61.             if sensor.reflection() <= one:
  62.                 break
  63.             wait(w)
  64.             # devil.turn(0,-t)
  65.             # if sensor.reflection() <= one:
  66.             #     break
  67.             # wait(w)
  68.             # devil.turn(0,t)
  69.             # if sensor.reflection() <= one:
  70.             #     break
  71.             t = t + 5
  72.             w = w + 10
  73.             # Updates values by 5 and 10 respectively. The wait gets a higher value to prevent overswing going bby a value.
  74.             # This code likely isn't as efficient as it can be, but it functions.
Advertisement
Add Comment
Please, Sign In to add comment