linking in maker activities
@ -22,15 +22,15 @@
|
||||
|
||||
![](/static/mb/projects/a5-compass.png)
|
||||
|
||||
## Music
|
||||
## [Hack your headphones](/lessons/hack-your-headphones/activity)
|
||||
|
||||
![](/static/mb/projects/a6-music.png)
|
||||
|
||||
## Conductive
|
||||
## [Banana keyboard](/lessons/banana-keyboard/activity)
|
||||
|
||||
![](/static/mb/projects/a7-conductive.png)
|
||||
|
||||
## Network
|
||||
## [Telegraph](/lessons/telegraph/activity)
|
||||
|
||||
![](/static/mb/projects/a8-network.png)
|
||||
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
![](/static/mb/projects/a9-radio.png)
|
||||
|
||||
## Watch
|
||||
## [Watch](/lessons/the-watch/activity)
|
||||
|
||||
![](/static/mb/projects/a10-watch.png)
|
||||
|
||||
|
@ -1,83 +1,112 @@
|
||||
# compass activity
|
||||
|
||||
![](/static/mb/projects/a5-compass.png)
|
||||
|
||||
Use the compass to determine which direction you are heading.
|
||||
Display the direction that the micro:bit is facing using the compass
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This guided tutorial will show you how to program a script that displays the direction the micro:bit is pointing. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
|
||||
## Step 1
|
||||
|
||||
Continuously sample the compass heading and store in the variable `degrees`:
|
||||
Create a loop that will continuously update the reading of the compass.
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
});
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2
|
||||
|
||||
If the degrees is less than 45, we are heading North:
|
||||
Store the reading of the micro:bit in a variable called `degrees`.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees <= 45) {
|
||||
basic.showString("N");
|
||||
} else if (false) { } else { }
|
||||
});
|
||||
let degrees = input.compassHeading()
|
||||
})
|
||||
```
|
||||
|
||||
### Step 3
|
||||
## Step 3
|
||||
|
||||
Otherwise, if the degrees is less than 135, we are heading East:
|
||||
If `degrees` is less than `45`, then the compass heading is mostly pointing toward North. Display `N` on the micro:bit.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees <= 45) {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
} else if (degrees <= 135) {
|
||||
basic.showString("E");
|
||||
} else { }
|
||||
});
|
||||
```
|
||||
|
||||
### Step 4
|
||||
|
||||
Otherwise, if the degrees is less than 225, we are heading East:
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees <= 45) {
|
||||
basic.showString("N");
|
||||
} else if (degrees <= 135) {
|
||||
basic.showString("E");
|
||||
} else if (degrees <= 225) {
|
||||
basic.showString("S");
|
||||
} else {
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Step 5
|
||||
## Step 4
|
||||
|
||||
If `degrees` is less than 135, the micro:bit is mostly pointing East. Display `E` on the micro:bit.
|
||||
|
||||
Otherwise, we are heading west.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees <= 45) {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
} else if (degrees <= 135) {
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
} else if (degrees <= 225) {
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Step 5
|
||||
|
||||
If `degrees` is less than 225, the micro:bit is mostly pointing South. Display `S` on the micro:bit.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
} else {
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Step 6
|
||||
|
||||
If none of these conditions returned true, then the micro:bit must be pointing West. Display `W` on the micro:bit.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
else {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/compass/challenges)!
|
||||
|
||||
### ~
|
||||
|
||||
|
Before Width: | Height: | Size: 156 KiB After Width: | Height: | Size: 156 KiB |
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 163 KiB |
Before Width: | Height: | Size: 220 KiB After Width: | Height: | Size: 220 KiB |
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 97 KiB |
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 164 KiB |