Create a KittenBot Compass Using FutureBoard Onboard Sensor
KC Coding Camp, Day 3
As part of the next project we will work with the magnetic sensor on the KittenBot to determine the cardinal directions that the device is pointing. In order to do this we have to use some coding structures such as If.. Then Statements.
Start by coding a basic numerical comparison:
Start by coding a basic decision block:
Now the trick will be deciding what values to place in the comparison tags. Look at the chart below of the compass and the degrees. Remember that we want the sensor to read a certain direction based on a heading so we will need to report one direction as the compass moves toward and away from the main direction.
Here is what the blocks will look like. You will have one for each Cardinal and Intermediate direction.
The chart of cardinal directions will look like this:
337-0 N
1-22 N
23-67 NE
68-112 E
113-157 SE
158-202 S
203-248 SW
249-294 W
295-336 NW
Why do you think there are two sets for North?
Use your coding skills to change the screen text based on the direction.
We will go outside and test our projects.