Migrate docs from the other repo
This commit is contained in:
57
docs/lessons/glowing-pendulum/activity.md
Normal file
57
docs/lessons/glowing-pendulum/activity.md
Normal file
@ -0,0 +1,57 @@
|
||||
# glowing pendulum block activity
|
||||
|
||||
Construct a pendulum that glows using acceleration.
|
||||
|
||||
To create a new script, go to the [Create Code](/microbit/create-code) page and tap `New Project` under `Block Editor`.
|
||||
|
||||
Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
|
||||
|
||||
Create a **forever** loop that will constantly display the appropriate brightness on the LED display.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration(Dimension.Y);
|
||||
});
|
||||
```
|
||||
|
||||
Since the micro:bit will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
|
||||
|
||||

|
||||
|
||||
```blocks
|
||||
let acceleration = 0;
|
||||
basic.forever(() => {
|
||||
acceleration = input.acceleration(Dimension.Y);
|
||||
acceleration = Math.abs(acceleration)
|
||||
});
|
||||
```
|
||||
|
||||
The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
|
||||
|
||||

|
||||
|
||||
Now let's use our acceleration value to set the brightness on the micro:bit.
|
||||
|
||||

|
||||
|
||||
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
|
||||
|
||||

|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/glowing-pendulum/challenges)!
|
||||
|
||||
### ~
|
||||
|
20
docs/lessons/glowing-pendulum/challenges.md
Normal file
20
docs/lessons/glowing-pendulum/challenges.md
Normal file
@ -0,0 +1,20 @@
|
||||
# glowing pendulum blocks challenges
|
||||
|
||||
Coding challenges for the glowing pendulum tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [glowing pendulum activity](/microbit/lessons/glowing-pendulum/activity) and your code should look like this:
|
||||
|
||||

|
||||
|
||||
**Challenge 1**
|
||||
|
||||

|
||||
|
||||
Hold the micro:bit in your hand in a dark room. Move the micro:bit like a pendulum and produce a slow image that captures the pattern of the micro:bit LEDs.
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Replace "y" in `acceleration(y)` with "x" or "z". Changing the axis will cause the micro:bit to measure the force in a different direction. What differences in the resulting pattern does this replacement make?
|
||||
|
Reference in New Issue
Block a user