42.4k views
4 votes
Using Microbit Blocks Write a program that will make your robotic car to move forward over a black line. Once it reaches the end of the line, it will turn around (i.e., rotate by 180 degrees) and come back to the point where it started. 10

If your car detects any obstacle on the line while moving, it will turn around (i.e., rotate by 180 degrees) and come back to the point where it started. (Hints: use

User Nateirvin
by
9.1k points

1 Answer

5 votes

Final answer:

To make a robotic car move forward over a black line using Microbit Blocks, you can use a program that detects the light level under the car and determines whether it is over a black line. If the car detects an obstacle, it can turn around and come back to the starting point. Here is an example code snippet to accomplish this task.

Step-by-step explanation:

To make a robotic car move forward over a black line using Microbit Blocks, you can use the following program:

  1. Set the car's LED lights to detect light levels.
  2. Use a loop to continuously check the light level under the car.
  3. If the light level is below a certain threshold, it means the car is over a black line, and you can make it move forward.
  4. If the car detects an obstacle on the line, use a rotation command to make it turn around 180 degrees.
  5. Continue the loop until the car reaches the end of the line.

Here is an example code snippet:

let

threshold = 100

basic.forever

(

() => {

let

lightLevel =

input.lightLevel

()

if

(lightLevel < threshold) {

driveForward

()

}

else if

(lightLevel >= threshold) {

turnAround

()

}

})

function

driveForward() {

basic.showArrow

(4)

pins.digitalWritePin

(

DigitalPin.P0

, 1)

pins.digitalWritePin

(

DigitalPin.P1

, 0)

}

function

turnAround() {

basic.showArrow

(2)

basic.pause

(1000)

pins.digitalWritePin

(

DigitalPin.P0

, 0)

pins.digitalWritePin

(

DigitalPin.P1

, 1)

basic.pause

(1000)

pins.digitalWritePin

(

DigitalPin.P0

, 0)

pins.digitalWritePin

(

DigitalPin.P1

, 0)

}

User John Skoubourdis
by
7.9k points