Migrate docs from the other repo

This commit is contained in:
Michal Moskal
2016-03-25 16:47:20 -07:00
parent 38d2cf06d2
commit a08eb53f92
895 changed files with 36888 additions and 0 deletions

View 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)!
### ~

View 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**
![](/static/mb/lessons/glowing-pendulum-0.jpg)
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?

View 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)
![](/static/mb/lessons/glowing-pendulum-1.png)
<br/>
```
led.plotAll()
```

View 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)
![](/static/mb/lessons/glowing-pendulum-1.png)
<br/>