2016-03-26 00:47:20 +01:00
|
|
|
# strobe light challenges
|
|
|
|
|
|
|
|
Coding challenges for strobe light.
|
|
|
|
|
|
|
|
## Before we get started
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
Complete the following [guided tutorial](/lessons/strobe-light/activity), your code should look like this:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
for (let j = 0; j < 5; j++) {
|
|
|
|
led.plot(i, j)
|
|
|
|
basic.pause(200)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 1
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-27 00:24:10 +02:00
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 2
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-27 00:24:10 +02:00
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 3
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-05-27 00:24:10 +02:00
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|