Migrate docs from the other repo
This commit is contained in:
75
docs/reference/js/lessons/glowing-pendulum/activity.md
Normal file
75
docs/reference/js/lessons/glowing-pendulum/activity.md
Normal file
@ -0,0 +1,75 @@
|
||||
# glowing pendulum activity
|
||||
|
||||
construct a pendulum that glows using acceleration. #docs
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This guided activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**.
|
||||
|
||||
Create a **forever** loop that will constantly display the appropriate brightness on the LED display.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
})
|
||||
```
|
||||
|
||||
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `input->acceleration("y")` function will provide the value.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration("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.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let acceleration1 = input.acceleration("y")
|
||||
acceleration1 = math.abs(acceleration1)
|
||||
})
|
||||
```
|
||||
|
||||
The function `input->acceleration("y")` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `led->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.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let acceleration2 = input.acceleration("y")
|
||||
acceleration2 = math.abs(acceleration2)
|
||||
acceleration2 = acceleration2 / 4
|
||||
})
|
||||
```
|
||||
|
||||
Now let's use our acceleration value to set the brightness on the BBC micro:bit.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let acceleration3 = input.acceleration("y")
|
||||
acceleration3 = math.abs(acceleration3)
|
||||
acceleration3 = acceleration3 / 4
|
||||
led.setBrightness(acceleration3)
|
||||
})
|
||||
```
|
||||
|
||||
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let acceleration4 = input.acceleration("y")
|
||||
acceleration4 = math.abs(acceleration4)
|
||||
acceleration4 = acceleration4 / 4
|
||||
led.setBrightness(acceleration4)
|
||||
led.plotAll()
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/glowing-pendulum/challenges)!
|
||||
|
||||
### ~
|
||||
|
32
docs/reference/js/lessons/glowing-pendulum/challenges.md
Normal file
32
docs/reference/js/lessons/glowing-pendulum/challenges.md
Normal file
@ -0,0 +1,32 @@
|
||||
# glowing pendulum challenges
|
||||
|
||||
Coding challenges for the glowing pendulum tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/glowing-pendulum/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let acceleration = input.acceleration("y")
|
||||
acceleration = math.abs(acceleration)
|
||||
acceleration = acceleration / 4
|
||||
led.setBrightness(acceleration)
|
||||
led.plotAll()
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||

|
||||
|
||||
Hold the BBC micro:bit in your hand in a dark room. Move the BBC micro:bit like a pendulum, and produce a slow image that captures the pattern of the BBC micro:bit LEDs.
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Replace "y" in `[input->acceleration("y")] with "x" or "z". Changing the axis will cause the BBC micro:bit to measure the force in a different direction. What differences in the resulting pattern does this replacement make?
|
||||
|
53
docs/reference/js/lessons/glowing-pendulum/quiz-answers.md
Normal file
53
docs/reference/js/lessons/glowing-pendulum/quiz-answers.md
Normal file
@ -0,0 +1,53 @@
|
||||
# glowing pendulum quiz answers
|
||||
|
||||
construct a pendulum that glows using acceleration #LED #number #math #acceleration #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/microbit/lessons/glowing-pendulum/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let acceleration = input.acceleration("y")
|
||||
```
|
||||
|
||||
## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
acceleration = math.abs(acceleration)
|
||||
```
|
||||
|
||||
## 4. Write the code that uses the acceleration value from question #3 to set the brightness on the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
acceleration = acceleration / 4
|
||||
led.setBrightness(acceleration)
|
||||
```
|
||||
|
||||
## 5. Write the code that tuns all the LEDs on (as the image displays below)
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plotAll()
|
||||
```
|
||||
|
34
docs/reference/js/lessons/glowing-pendulum/quiz.md
Normal file
34
docs/reference/js/lessons/glowing-pendulum/quiz.md
Normal file
@ -0,0 +1,34 @@
|
||||
# glowing pendulum quiz
|
||||
|
||||
construct a pendulum that glows using acceleration #LED #number #math #acceleration #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing pendulum tutorial](/microbit/lessons/glowing-pendulum/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Why are you creating a 'forever' loop?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that uses the acceleration value from question #3 to set the brightness on the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code that tuns all the LEDs on (as the image displays below)
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
Reference in New Issue
Block a user