Bag Of Cows

RoboCadets

Here are some code examples of how to use different sensors on the robot.

At the top of your code, you need to import all the libraries that will be needed, and set up constants for the pins used for the sensors, and also global variables which will be used to store the state of the sensors.

Then for each sensor, you create a subroutine which is run in its own thread, continually checking the state of the sensor, and updating a global variable with its state, and perhaps calling a special subroutine when the value of the sensor changes.

In another part of your program, you will have a while True loop which checks what the sensors are doing, and makes decisions about how to respond.


Standard code for the start of your program

Code to make the motors work

Code to monitor the bumpers

Code to monitor the line follower

Show a pattern on the microbit

Use the Sonar distance detector

Here is the code for the libraries used, which are in the 'lib' folder. You shouldn't need to change these, but it is here just in case...