Skip to content

Commit

Permalink
Fjerna multi thread
Browse files Browse the repository at this point in the history
  • Loading branch information
martaron committed Sep 17, 2025
1 parent 1638ff4 commit 9d59503
Showing 1 changed file with 25 additions and 38 deletions.
63 changes: 25 additions & 38 deletions oving_2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile

import threading
import sys


# This program requires LEGO EV3 MicroPython v2.0 or higher.
# Click "Open user guide" on the EV3 extension tab for more information.
Expand All @@ -26,48 +23,38 @@

leftMotor = Motor(port=Port.A)
rightMotor = Motor(port=Port.C)
robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=110)
robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=160)

startBtn = TouchSensor(port=Port.S1)
usSensor = UltrasonicSensor(port=Port.S3)

isPressed = False

def startStrop():
global isPressed
while True:
if(startBtn.pressed()):
if isPressed == False:
ev3.speaker.say("Excercise 2")
wait(500)
isPressed = True
next_turn = 1
else:
isPressed = False
robotDriveBase.stop()
ev3.speaker.say("Excercise done")

break
next_turn = 0

while True:
if(startBtn.pressed() and isPressed == False):
ev3.speaker.say("Excercise 2")
wait(500)
isPressed = True
next_turn = 1

print("The end..")
sys.exit()
elif(isPressed == True):
if startBtn.pressed():
isPressed = False
break

elif(usSensor.distance() >= 150):
robotDriveBase.drive(-250, 0)
else:
robotDriveBase.turn(90 * next_turn)
robotDriveBase.straight(-150)
robotDriveBase.turn(90 * next_turn)
next_turn *= -1

robotDriveBase.stop()
ev3.speaker.say("Excercise done")


def runRobot() :
next_turn = 0

while True:
if(isPressed == True):
if(usSensor.distance() >= 75):
robotDriveBase.drive(-250, 0)
else:
robotDriveBase.turn(90 * next_turn)
robotDriveBase.straight(-150)
robotDriveBase.turn(90 * next_turn)
next_turn *= -1

t1 = threading.Thread(target=startStrop)
t2 = threading.Thread(target=runRobot)

t1.start()
t2.start()
print("The end..")

0 comments on commit 9d59503

Please sign in to comment.