Skip to content

Kode | Prosjekt 3

Oskar Filip Kotula edited this page Nov 18, 2026 · 2 revisions

Dette er koden vi brukte til LEGO-prosjekt 3

import runloop
import color_sensor
import motor
import color
import time
 
async def main():
    runde = 1
    start_tid = 0
    varighet_ms = 10000
 
    while True:
        motor.run(port.E, 1000)
        farge_venstre = color_sensor.color(port.D)
        farge_høyre = color_sensor.color(port.C)
 
        if runde == 1:
            tid_har_gått = time.ticks_diff(time.ticks_ms(), start_tid) >= varighet_ms
 
            if tid_har_gått and farge_venstre == color.BLACK and farge_høyre == color.BLACK:
                print("Utfører runde 1")
                motor.run_for_degrees(port.B, -22, 100)
                await motor.run_for_degrees(port.A, 67, 350)
 
 
                start_tid = time.ticks_ms()
                runde = 2
 
        elif runde == 2:
            tid_har_gått = time.ticks_diff(time.ticks_ms(), start_tid) >= varighet_ms
 
            if tid_har_gått and farge_venstre == color.BLACK and farge_høyre == color.BLACK:
                print("Utfører runde 2")
                motor.run_for_degrees(port.B, -67, 350)
                await motor.run_for_degrees(port.A, 22, 100)
 
                start_tid = time.ticks_ms()
                runde = 1
 
        if farge_venstre == color.WHITE and farge_høyre == color.WHITE:
            motor.run(port.A, 460)
            motor.run(port.B, -460)
 
        elif farge_venstre == color.BLACK:
            motor.run(port.A, 500)
            motor.run(port.B, -150)
 
        elif farge_høyre == color.BLACK:
            motor.run(port.A, 150)
            motor. run(port.B, -500)
 
 
runloop.run(main())
Clone this wiki locally