Your mBot is also equipped with an ultrasonic sensor. This means that it has the ability to sense how far it is from various obstacles. Add the following code to your project:
Then click the Green Flag to start the program. The value picked up by the ultrasonic sensor will now constantly be displayed on the screen (just like we did with the light sensor in the previous stage). While the program is running, try moving the mBot really close to an obstacle (like a wall). This will give you an idea of what the readings are when the mBot gets really close to an object.
Now, you need to program your mBot so that you can drive it around (as normal). However, in addition to this, you need to set it up so that whenever it gets really close to an obstacle, it will stop, beep, and then move backwards for 2 seconds before stopping again.
As before, try to figure this out on your own first. Don't give up too easily. If you REALLY need help, let Mr. Locke know and he might show you a hint. If he has to. He doesn't really want to though.
Now, you need to program your mBot so that you can drive it around (as normal). However, in addition to this, you need to set it up so that whenever it gets really close to an obstacle, it will stop, beep, and then move backwards for 2 seconds before stopping again.
As before, try to figure this out on your own first. Don't give up too easily. If you REALLY need help, let Mr. Locke know and he might show you a hint. If he has to. He doesn't really want to though.
Show Mr. Locke that you have successfully completed this stage and then you can move on to the next one. |