Advertisement
Guest User

Untitled

a guest
Jun 21st, 2020
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Initialize hub and sensor
  2. from pybricks.pupdevices import *
  3. from pybricks.parameters import Port
  4. from pybricks.tools import wait
  5.  
  6. ultraschallsensor = UltrasonicSensor(Port.C)
  7. motor1 = Motor(Port.A)
  8. motor2 = Motor(Port.D)
  9. licht = Light(Port.B)
  10. speed = 30
  11. repitions = 10
  12. #A: Ultraschallsensor
  13. #B: Lichter
  14. #C: First motor
  15. #D: Second motor
  16.  
  17. print('start')
  18. while True:
  19.     wait(100)
  20.    
  21.     if ultraschallsensor.distance() < 235:
  22.         print(ultraschallsensor.distance())
  23.         wait (100)
  24.        
  25.         for x in range(repitions):
  26.             for y in range(80):
  27.                 licht.on(y+10)
  28.                 wait(10)
  29.             for y in range(80):
  30.                 licht.on(90-y)
  31.                 wait(10)
  32.            
  33.             if x == 1:
  34.                 motor1.dc(20)
  35.                 motor2.dc(20)
  36.             elif x == repitions-2:
  37.                 motor1.dc(-40)
  38.                 motor2.dc(-40)
  39.             else:
  40.                 motor1.stop()
  41.                 motor2.stop()
  42.         licht.off()
  43.         wait(200)
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement