var run_behavior = STOP #var l[8] var speed = 300 # Ab wann wird schwarz/weiß erkannt var black_level = 200 var white_level = 400 var states[2] var direction # Wenn der mittlere Knopf gedrückt wird: onevent button.center if button.center == 1 then if run_behavior == STOP then run_behavior = START speed = SPEED_LINE else motor.left.target = 0 motor.right.target = 0 call leds.circle(0,0,0,0,0,0,0,0) call leds.bottom.left(0,0,0) call leds.bottom.right(0,0,0) run_behavior = STOP call prox.comm.enable(0) end end onevent prox if run_behavior == START then # Line Follower Code if prox.ground.delta[0] < black_level then states[0] = STATE_BLACK end if prox.ground.delta[0] > white_level then states[0] = STATE_WHITE end if prox.ground.delta[1] < black_level then states[1] = STATE_BLACK end if prox.ground.delta[1] > white_level then states[1] = STATE_WHITE end if states[0] == STATE_BLACK and states[1] == STATE_BLACK then # Die Schwarze Linie ist direkt unter uns direction = DIR_FRONT elseif states[0] == STATE_WHITE and states[1] == STATE_BLACK then direction = DIR_RIGHT elseif states[1] == STATE_WHITE and states[0] == STATE_BLACK then direction = DIR_LEFT else # Lost if direction > 0 then direction = DIR_L_RIGHT elseif direction < 0 then direction = DIR_L_LEFT else direction = DIR_LOST end end if direction == DIR_FRONT then motor.left.target = speed motor.right.target = speed call leds.circle(32,0,0,0,32,0,0,0) elseif direction == DIR_RIGHT then motor.left.target = speed motor.right.target = 0 call leds.circle(0,32,0,32,0,0,0,0) elseif direction == DIR_LEFT then motor.left.target = 0 motor.right.target = speed call leds.circle(0,0,0,0,0,32,0,32) elseif direction == DIR_L_LEFT then motor.left.target = -speed motor.right.target = speed call leds.circle(0,0,0,0,0,0,32,0) elseif direction == DIR_L_RIGHT then motor.left.target = speed motor.right.target = -speed call leds.circle(0,0,32,0,0,0,0,0) elseif direction == DIR_LOST then motor.left.target = speed motor.right.target = -speed end end