I used to equip an EV3 with three ultrasonic sensors for the purpose of navigating through a landscape with obstacles. Using nested if statements I had the EV3 stop when it came across an obstacle after which it tested left and right for obstacles with the other two ultrasonic sensors, before turning in one of the directions. This worked fine in the Lego Mindstorms programming environment but I haven’t managed to achieve the same in the MakeCode environment.
So far I haven’t found a way of making nested if statements based on ultrasonic sensor information. Perhaps any of you can see a way of achieving the desired functionality with or without if statements.
I would be really grateful for some help with this.
I probably need to be more clear in my explanations. Sorry for that! The question in not about nested if-statements and ultrasonic sensors separately, but rather about nested if-statements based on ultrasonic sensor information. For example I have no problem creating nested if statements based on color sensor information. Here is a short example code with nested if-statements polling two color sensors and requiring the one to detect blue color and the other red color before running a motor:
What I am looking for is a way to achieve the same functionality, but with ultrasonic sensors instead. For ultrasonic sensors I can’t find the corresponding hexagonal code inlays (found in the example above), compatible with if-statements. Is there perhaps something I have missed when it comes to if-statements in conjunction with ultrasonic sensors or is there a way of achieving this functionality?
Thank you so much for helping me out! It’s working and now I can see how it’s done block side too.
To anyone who is involved with the Make Code platform I still would like to put forward a wish. Couldn’t there be a ready hexagonal inlay for ultrasound sensors that fits directly into the if-statement, similar to what exist for say color sensors, instead of having to make it work through the comparison inlay?
I have no problem doing it, but for my students it’s already a great challenge to understand the straightforward way that I am proposing, so I guess they will end up a bit confused, since there is no logical reason why it couldn’t work the same way for ultrasonic sensors as for color sensors, or perhaps there is?
It is quite easy to make your own functions that will make the ultrasonic sensor to have similar usage than the color sensor. For a simple implementation, you can do that in main.ts either by using block or JavaScript. You can hide the implementation and gain some additional features by implementing it in custom.ts using JavaScript.