move lessons out of web site
will move select lessons back to "educators" section
This commit is contained in:
98
olddocs/lessons/compass/activity.md
Normal file
98
olddocs/lessons/compass/activity.md
Normal file
@ -0,0 +1,98 @@
|
||||
# compass activity
|
||||
|
||||
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!
|
||||
|
||||
### ~
|
||||
|
||||
Create a loop that will continuously update the reading of the compass.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
Store the reading of the micro:bit in a variable called `degrees`.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading()
|
||||
})
|
||||
```
|
||||
|
||||
If `degrees` is less than `45`, then the compass heading is mostly pointing toward North. Display `N` on the micro:bit.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
If `degrees` is less than 135, the micro:bit is mostly pointing East. Display `E` on the micro:bit.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("N");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
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");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
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)!
|
||||
|
||||
### ~
|
||||
|
88
olddocs/lessons/compass/challenges.md
Normal file
88
olddocs/lessons/compass/challenges.md
Normal file
@ -0,0 +1,88 @@
|
||||
# compass challenges
|
||||
|
||||
Display the direction that the micro:bit is facing using the compass
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/compass/activity), your code should look like this:
|
||||
|
||||
```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 {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Instead of displaying `N` when the BBC micro:bit is pointing North, display a star to indicate the north star.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showLeds(`
|
||||
# . # . #
|
||||
. # # # .
|
||||
# # # # #
|
||||
. # # # .
|
||||
# . # . #`);
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("E");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S");
|
||||
}
|
||||
else {
|
||||
basic.showString("W");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Instead of displaying just `N`, `W`, `S`, or `E`, display the full word.
|
||||
|
||||
```blocks
|
||||
let degrees = 0;
|
||||
basic.forever(() => {
|
||||
degrees = input.compassHeading();
|
||||
if (degrees < 45) {
|
||||
basic.showString("NORTH");
|
||||
}
|
||||
else if (degrees < 135) {
|
||||
basic.showString("EAST");
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("SOUTH");
|
||||
}
|
||||
else {
|
||||
basic.showString("WEST");
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Display your own unique message for each direction.
|
||||
|
54
olddocs/lessons/compass/quiz-answers.md
Normal file
54
olddocs/lessons/compass/quiz-answers.md
Normal file
@ -0,0 +1,54 @@
|
||||
# compass quiz answers
|
||||
|
||||
Create an actual compass to show your direction: North, South, East, or West
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [compass tutorial](/lessons/compass/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the purpose of the 'compass heading' block?
|
||||
|
||||
Gets the compass heading of the micro:bit in degrees
|
||||
|
||||
|
||||
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
```
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 45) {
|
||||
basic.showString("N", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 135) {
|
||||
basic.showString("E", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
|
||||
|
||||
|
||||
```blocks
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 225) {
|
||||
basic.showString("S", 150)
|
||||
}
|
||||
```
|
||||
|
26
olddocs/lessons/compass/quiz.md
Normal file
26
olddocs/lessons/compass/quiz.md
Normal file
@ -0,0 +1,26 @@
|
||||
# compass quiz
|
||||
|
||||
Create an actual compass to show your direction: North, South, East, or West
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [compass activity](/lessons/compass/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the purpose of the 'compass heading' block?
|
||||
|
||||
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
|
||||
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
|
||||
|
||||
|
||||
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
|
||||
|
||||
|
||||
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
|
||||
|
||||
|
Reference in New Issue
Block a user