Coding help


#1

I am not sure how to have the mbot keep track of the total number of turns made using a variable


#2

Hi Whitney,

The mBot does not have a lot of sensors, let alone a GPS.
It’s possible but it depends on your track.

  1. What shape does the track have? (Square, round, oval, …)
  2. Does the track have the object ?

Here is a possible track (line tracking):
track1

If not with Ultrasonic (easier):
Track2

You turn in circles and when the ultrasonic decreases below a value then the mBlot has made a turn.
You take a variable and you have your answer


#3

If you are have the mbot performing a distinct turn command, you can create a variable and then add 1 to the variable every time the turn command is performed. My son is doing something similar with a program to search for an object in a grid but he is using the variable as a step to move from one function to another.

He created a variable and set it to 0 at the start of the program. After each distinct action he used the block Change “variable” by 1.


#4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.