General Bloxter help if/then with distance sensor


I would like to use the distance sensor to measure two points, then run to the point that is the shortest distance.
Can Bloxter do this? I am having difficulties reading and storing the values into a variable. I am assuming I could do that, then run an if then statement to compare and make a decision on the shortest or longest value. But I have messed around and can’t figure out how to do this. Any advice would be greatly appreciated. is there a general Bloxter tutorial that tells you how to use the if/then, variables, etc. ?


So here is how I understand what you said:

  1. Take a reading from the distance sensor
  2. Rotate the distance sensor or something to get a new reading
  3. Then go to whichever “reading” was shortest.

Tell me if I was wrong, but the answer is most definitely yes.

The first thing you’ll want to do is click “Code” in bloxter and select “Advanced Bloxter.” This will give us access to variables which we’ll need.

The basics of Bloxter

Most blocks either have at least an input and/or output.

This block has a input for degrees to turn: image
Now we could click on the input and put in a number or we could place block into it.

The distance sensor block “outputs” a value into the turn degrees block.

Simple! :slight_smile:

All about If statements

In the logic tab grab these two blocks and connect them.
This now allows us to compare values and perform an action if the comparison is true.

And in honor of the upcoming Parker Space Probe mission:
Notice that I put the temperature block into the block. So if you sent your robot into the sun it would print out that it is in the corona. If it is still on earth it would do nothing. The block inside the if/then statement is only run if the comparison is true.


Notice that I did use this block in my last and slightly more practical example.


With the advanced version of bloxter enabled you should now see a blue variable tab. In that tab create a new variable and name it whatever you want. In your case you could make two variables. The first named “First Point.”

And finally a practical example:

Hopefully this will be enough for you to get started and start experimenting. Bloxter is based on google’s blockly. So you can find further information on programming blockly here. Just keep in mind it is different in some cases than Bloxter, but it is close enough that the documentation is useful.

Have fun with your project! And of course ask if you have questions. :grinning: