Migrate docs from the other repo
This commit is contained in:
55
docs/lessons/strobe-light/activity.md
Normal file
55
docs/lessons/strobe-light/activity.md
Normal file
@ -0,0 +1,55 @@
|
||||
# strobe light activity
|
||||
|
||||
Develop shapes with a for loop.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/strobe-light-0
|
||||
|
||||
Welcome! This guided tutorial will teach how to develop shapes with a for loop. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Create a `for loop` that will loop from 0 to 4 to indicate the x-coordinates of the micro:bit display.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Create another for loop that will loop from 0 to 4, indicating the y-coordinates of the micro:bit instead. This for loop will light each LED by column.
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
We will light up each LED by plotting them individually.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
basic.pause(200)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
The pause will add a delay between lighting each LED.
|
||||
|
||||

|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/strobe-light/challenges)!
|
||||
|
||||
### ~
|
||||
|
73
docs/lessons/strobe-light/challenges.md
Normal file
73
docs/lessons/strobe-light/challenges.md
Normal file
@ -0,0 +1,73 @@
|
||||
# strobe light challenges
|
||||
|
||||
Coding challenges for strobe light.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/microbit/lessons/strobe-light/activity), your code should look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
basic.pause(200)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/strobe-light-1
|
||||
|
||||
Make the LEDs light up faster by changing the **pause** from 200 to 100 milliseconds:
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
basic.pause(100)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/strobe-light-2
|
||||
|
||||
Make the board light up by rows instead of by columns by swapping the `i` and `j` variables in `plot(i, j)`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(j, i)
|
||||
basic.pause(100)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/strobe-light-ultimate
|
||||
|
||||
Now that all the LEDs are lit up, let's make them turn off by reversing the strobe light pattern! You can use `unplot` to turn off a single LED.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(j, i)
|
||||
basic.pause(100)
|
||||
}
|
||||
}
|
||||
for (let k = 0; k < 5; k++) {
|
||||
for (let l = 0; l < 5; l++) {
|
||||
led.unplot(4 - l, 4 - k)
|
||||
basic.pause(100)
|
||||
}
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user