linking in maker activities
This commit is contained in:
1 parent
f8e80e6a9d
commit
56301d2d6f
9 files changed
+79
-50
No files matched your search
+4
-4
@@ -22,15 +22,15 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Music
|
## [Hack your headphones](/lessons/hack-your-headphones/activity)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Conductive
|
## [Banana keyboard](/lessons/banana-keyboard/activity)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Network
|
## [Telegraph](/lessons/telegraph/activity)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Watch
|
## [Watch](/lessons/the-watch/activity)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
+75
-46
@@ -1,83 +1,112 @@
|
|||||||
|
# compass activity
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
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
|
## 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
|
```blocks
|
||||||
let degrees = 0;
|
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
degrees = input.compassHeading();
|
|
||||||
});
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## Step 2
|
## 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
|
```blocks
|
||||||
let degrees = 0;
|
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
degrees = input.compassHeading();
|
let degrees = input.compassHeading()
|
||||||
if (degrees <= 45) {
|
})
|
||||||
basic.showString("N");
|
|
||||||
} else if (false) { } else { }
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 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
|
```blocks
|
||||||
let degrees = 0;
|
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
degrees = input.compassHeading();
|
let degrees = input.compassHeading();
|
||||||
if (degrees <= 45) {
|
if (degrees < 45) {
|
||||||
basic.showString("N");
|
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
|
```blocks
|
||||||
let degrees = 0;
|
|
||||||
basic.forever(() => {
|
basic.forever(() => {
|
||||||
degrees = input.compassHeading();
|
let degrees = input.compassHeading();
|
||||||
if (degrees <= 45) {
|
if (degrees < 45) {
|
||||||
basic.showString("N");
|
basic.showString("N");
|
||||||
} else if (degrees <= 135) {
|
}
|
||||||
|
else if (degrees < 135) {
|
||||||
basic.showString("E");
|
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");
|
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");
|
basic.showString("W");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### ~avatar avatar
|
||||||
|
|
||||||
|
Excellent, you're ready to continue with the [challenges](/lessons/compass/challenges)!
|
||||||
|
|
||||||
|
### ~
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user