From 4a446d11c76d0dc6011e8e915e39a8994a3eba27 Mon Sep 17 00:00:00 2001 From: Martin Aronsen Date: Wed, 3 Sep 2025 11:14:18 +0200 Subject: [PATCH 1/2] =?UTF-8?q?F=C3=A5tt=20til=20sensor=20funksjonalitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fått til både touch og ultrasonic sensor. --- oving_2/main.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/oving_2/main.py b/oving_2/main.py index 9e9700f..57a77b2 100644 --- a/oving_2/main.py +++ b/oving_2/main.py @@ -18,3 +18,23 @@ # Write your program here. ev3.speaker.beep() + + +startBtn = TouchSensor(port=Port.S1) +usSensor = UltrasonicSensor(port=Port.S3) + +isPressed = False + +while True: + + if(startBtn.pressed() and isPressed == False): + print("Knapp funker\n", + "Starter program.") + isPressed = True + + elif(isPressed == True): + print(usSensor.distance()) + + + +print("The end..") \ No newline at end of file From a398e81d5a779d46930a457d430069d55aa05509 Mon Sep 17 00:00:00 2001 From: Martin Aronsen Date: Wed, 3 Sep 2025 12:00:52 +0200 Subject: [PATCH 2/2] Skrevet ferdig funksjonalitet --- oving_2/main.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/oving_2/main.py b/oving_2/main.py index 57a77b2..44ec493 100644 --- a/oving_2/main.py +++ b/oving_2/main.py @@ -20,21 +20,41 @@ ev3.speaker.beep() + +leftMotor = Motor(port=Port.A) +rightMotor = Motor(port=Port.C) +robotDriveBase = DriveBase(leftMotor, rightMotor, wheel_diameter=56, axle_track=110) + startBtn = TouchSensor(port=Port.S1) usSensor = UltrasonicSensor(port=Port.S3) isPressed = False +next_turn = 0 + while True: - if(startBtn.pressed() and isPressed == False): - print("Knapp funker\n", - "Starter program.") + ev3.speaker.say("Excercise 2") + wait(500) isPressed = True + next_turn = 1 elif(isPressed == True): - print(usSensor.distance()) - + if startBtn.pressed(): + isPressed = False + break + + elif(usSensor.distance() >= 75): + 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") + print("The end..") \ No newline at end of file