Lessons fixes (#1609)
* fixing a bunch of lessons * more fixes * more fixes * more cleanup * Additional fixes
This commit is contained in:
parent
2aa8d0cec6
commit
50367217f3
@ -61,7 +61,7 @@ Notes:
|
||||
|
||||
Looking at our pseudocode, we want to make sure to start a program with a clear screen.
|
||||
|
||||
* We can do this by going to the Basic menu -> More and choosing a ‘clear screen’ block.
|
||||
* We can do this by going to the **Basic** toolbox category and under **...more**, choose a ``||basic:clear screen||`` block.
|
||||
|
||||
>![Clear screen block](/static/courses/csintro/algorithms/clear-screen-block.png)
|
||||
|
||||
|
@ -46,15 +46,16 @@ As we’ll soon see, there are other choices for how the sequences can be ordere
|
||||
|
||||
The micro:bit’s *scheduler* provides the capability to concurrently execute different code sequences, relieving us of a lot of low-level programming. In fact, scheduling is so useful that it is a part of every *operating system*!
|
||||
|
||||
The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses.
|
||||
The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution. For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the program below for counting button presses.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count++;
|
||||
})
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
@ -75,13 +76,13 @@ input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
The third statement queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
|
||||
The third statement queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
// ...
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
@ -92,7 +93,7 @@ The second job of the scheduler is to periodically interrupt execution to read (
|
||||
|
||||
## Cooperative passing of control
|
||||
|
||||
How does the forever loop get to start execution? Furthermore, once the forever loop is running, how does any other subprogram (like the event handler that increments the count) ever get a chance to execute?
|
||||
How does the `forever` loop get to start execution? Furthermore, once the `forever` loop is running, how does any other subprogram (like the event handler that increments the count) ever get a chance to execute?
|
||||
|
||||
The answer is “cooperation” and “passing”. Think of a football team doing a drill – there is one ball and each footballer gets to dribble the ball for a certain number of touches, after which they pass to another footballer. A footballer who never passes prevents all other footballers from dribbling. A cooperative footballer always passes to some other footballer after taking a few touches.
|
||||
|
||||
@ -113,7 +114,7 @@ function forever(body: () => void) {
|
||||
}
|
||||
```
|
||||
|
||||
The `forever` loop actually is a function that takes a subprogram (an *Action* in Touch Develop) as a parameter. The function uses the `control -> in background` function of the micro:bit runtime to queue a `while true` loop for execution by the scheduler. The while loop has two statements. The first statement runs the subprogram represented by the `body` parameter. The second statement passes control to the scheduler (requesting to “sleep” for 20 milliseconds).
|
||||
The `forever` loop actually is a function that takes a subprogram as a parameter. The function uses the `control.inBackground` function of the micro:bit runtime to queue a `while true` loop for execution by the scheduler. The while loop has two statements. The first statement runs the subprogram represented by the `body` parameter. The second statement passes control to the scheduler (requesting to “sleep” for 20 milliseconds).
|
||||
|
||||
Though the `while true` loop will repeatedly execute the body subprogram, between each execution of the body it will permit the scheduler to execute other subprograms. If the while loop did not contain the call to `pause`, then once control passed into the while loop, it would never pass back to the scheduler and no other subprogram would be able to execute (unless the body subprogram contained a call to `pause` itself).
|
||||
|
||||
@ -127,13 +128,13 @@ The property of such round-robin scheduling is that under the assumption that ev
|
||||
|
||||
## Putting it all together
|
||||
|
||||
Let’s go back to the `count button presses` function and revisit its execution based on what we have learned about the micro:bit scheduler. As detailed before, the function executes three steps to: (1) set up the event handler for each press of button A; (2) queue the forever loop to the run queue; (3) initialize the global variable `count` to zero.
|
||||
Let’s go back to the `count button presses` program and revisit its execution based on what we have learned about the micro:bit scheduler. As detailed before, the function executes three steps to: (1) set up the event handler for each press of button A; (2) queue the forever loop to the run queue; (3) initialize the global variable `count` to zero.
|
||||
|
||||
The function then ends execution and control passes back to the scheduler. Let’s assume the user has not pressed any buttons . The scheduler finds the `forever` loop in the run queue and passes control to it. The loop first calls `basic -> show number(0,150)`. In the diagram below, we use “Show 0” to refer to the execution of this function:
|
||||
The function then ends execution and control passes back to the scheduler. Let’s assume the user has not pressed any buttons . The scheduler finds the `forever` loop in the run queue and passes control to it. The loop first calls `basic.showNumber(0)`. In the diagram below, we use “Show 0” to refer to the execution of this function:
|
||||
|
||||
![](/static/mb/device/reactive-3.png)
|
||||
|
||||
While "Show 0" (the blue sequence) is running, periodic interrupts by the scheduler (every 6 milliseconds) poll for button presses and queue an event handler for each press of button A. Let’s say that one button press takes place during this time, as shown above. This will cause an event handler (labelled “inc”) to be queued for later execution by the scheduler. Once the "Show 0" has completed, the loop then calls `basic -> pause(20)` to put the forever loop to sleep for 20 milliseconds and give the scheduler an opportunity to run any newly queued event handler. Control passes to the “inc” event handler which will increment the global variable `count` from 0 to 1 and then complete, returning control to the scheduler. At some point, the `forever` loop moves from the sleep queue to the run queue; the `forever` loop then will resume and call `basic -> show number(1,150)`.
|
||||
While "Show 0" (the blue sequence) is running, periodic interrupts by the scheduler (every 6 milliseconds) poll for button presses and queue an event handler for each press of button A. Let’s say that one button press takes place during this time, as shown above. This will cause an event handler (labelled “inc”) to be queued for later execution by the scheduler. Once the "Show 0" has completed, the loop then calls `basic.pause(20)` to put the forever loop to sleep for 20 milliseconds and give the scheduler an opportunity to run any newly queued event handler. Control passes to the “inc” event handler which will increment the global variable `count` from 0 to 1 and then complete, returning control to the scheduler. At some point, the `forever` loop moves from the sleep queue to the run queue; the `forever` loop then will resume and call `basic.showNumber(1)`.
|
||||
|
||||
## Final thoughts
|
||||
|
||||
@ -148,7 +149,7 @@ function countButtonPressesWithReset() {
|
||||
count = count + 1
|
||||
})
|
||||
basic.forever(() => {
|
||||
basic.showNumber(count, 150)
|
||||
basic.showNumber(count)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
count = 0
|
||||
|
@ -15,7 +15,7 @@ input.onButtonPressed(Button.A, () => {
|
||||
newAction();
|
||||
}
|
||||
})
|
||||
input.onLogoDown(() => {
|
||||
input.onGesture(Gesture.LogoDown, function () {
|
||||
if (action == 1) {
|
||||
game.addScore(1);
|
||||
newAction();
|
||||
@ -36,13 +36,13 @@ input.onButtonPressed(Button.B, () => {
|
||||
|
||||
## Challenge 1
|
||||
|
||||
Now let's add some more types of instructions for the player to follow. Let's add `PRESS PIN 0`.
|
||||
Change the global variable `action` to `math->random(4)` so that we can add a new **IF** statement that checks if `action=3`. If it does, display instructions to press pin 0.
|
||||
Now let's add some more types of instructions for the player to follow. Let's add `"PRESS PIN 0"`.
|
||||
Change the global variable `action` to `math.randomRange(0, 3)` so that we can add a new **IF** statement that checks if `action == 3`. If it does, display instructions to press pin 0.
|
||||
|
||||
```typescript
|
||||
let action = 0;
|
||||
export function newAction() {
|
||||
action = Math.randomRange(0, 4)
|
||||
action = Math.randomRange(0, 3)
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150) // ***
|
||||
}
|
||||
@ -60,7 +60,7 @@ export function newAction() {
|
||||
|
||||
## Challenge 2
|
||||
|
||||
Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`.
|
||||
Now let's implement `PRESS PIN 0` in the main. Create a condition in an `input.onPinPressed` event that, whet pin `P0` is pressed, will add one to the score and then calls the `newAction` function.
|
||||
|
||||
```typescript
|
||||
let action = 0;
|
||||
|
@ -21,7 +21,7 @@ let action = Math.randomRange(0, 3)
|
||||
```blocks
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150)
|
||||
basic.showString("PUSH A")
|
||||
}
|
||||
```
|
||||
|
||||
@ -41,14 +41,14 @@ input.onButtonPressed(Button.A, () => {
|
||||
```blocks
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150)
|
||||
basic.showString("LOGO DOWN")
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Write the code that increments the score if the @boardname@ logo is tilted down when the global variable called 'action' is equal to 1
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
input.onGesture(Gesture.LogoDown, function () {
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
@ -61,14 +61,14 @@ input.onLogoDown(() => {
|
||||
```blocks
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150)
|
||||
basic.showString("SHAKE")
|
||||
}
|
||||
```
|
||||
|
||||
## 7. Write the code that increments the score if the @boardname@ is shaken when the global variable called 'action' is equal to 2
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
input.onGesture(Gesture.LogoDown, function () {
|
||||
let action = Math.randomRange(0, 3)
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
|
@ -15,10 +15,12 @@ Variables
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a catch the egg game game with **plot**, `led->plot` , **unplot**, `led->unplot`, and **acceleration** `input -> acceleration` to turn on and off LED lights on the LED screen. We will be learning how to create a catch the egg game app using global variables, forever loop, local variable, input acceleration, math min, math max, math random, math mod, if (conditionals), game library as well as simple commands, such as led plot, led unplot, and pause.
|
||||
Learn how to create a catch the egg game game with ``||led:plot||`` , ``||led:unplot||``, and ``||input:acceleration||`` to turn on and off LED lights on the screen.
|
||||
|
||||
## Documentation
|
||||
|
||||
The blocks used in this lesson:
|
||||
|
||||
```cards
|
||||
let x = 2;
|
||||
led.unplot(0, 0);
|
||||
|
@ -8,25 +8,22 @@ Welcome! This tutorial will teach how to create a counter with a while loop. Let
|
||||
|
||||
## ~
|
||||
|
||||
Create a variable that acts as a counter and set it to 0.
|
||||
Create a variable that acts as a counter and set it to `0`.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||
Add a while loop that will loop over and over until the variable `count` equals 10.
|
||||
|
||||
Add a while loop that will loop over and over until the variable ``||variables:count||`` equals `10`.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
while (count < 10) {
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Let's add a pause. Then show the value of the the count.
|
||||
|
||||
Let's add a pause. Then show the value of ``||variables:count||``.
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
@ -34,11 +31,9 @@ while (count < 10) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Increase the value of count by one.
|
||||
|
||||
Increase the value of ``||variables:count||`` by one.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
@ -49,10 +44,8 @@ while (count < 10) {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/digi-yoyo/challenges)!
|
||||
|
||||
## ~
|
||||
|
||||
|
@ -19,7 +19,7 @@ while (count < 10) {
|
||||
|
||||
## Challenge 1
|
||||
|
||||
How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0.
|
||||
How about we create a counter that counts backwards from `10` to `1`? Let's add a while loop that executes only when ``||variables:count||`` is greater than `0`.
|
||||
|
||||
|
||||
```blocks
|
||||
@ -33,19 +33,15 @@ while (count < 10) {
|
||||
while (count > 0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Challenge 2
|
||||
|
||||
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!
|
||||
|
||||
|
||||
Inside of the while loop, let's add a ``||basic:pause||`` that waits for one seccond so that we have a pause between each number as it's counting down. Also, let's show ``||variables:count||``!
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
let count = 0;
|
||||
while (count < 10) {
|
||||
basic.pause(100);
|
||||
basic.showNumber(count);
|
||||
@ -62,12 +58,11 @@ while (count > 0) {
|
||||
|
||||
## Challenge 3
|
||||
|
||||
Now, we need `count` to decrease by one after the @boardname@ has displayed the value of `count`.
|
||||
Now, we need ``||variables:count||`` to decrease by one after the @boardname@ has displayed the value of ``||variables:count||``.
|
||||
|
||||
We can do this by adding this line:
|
||||
|
||||
```blocks
|
||||
let count = 0;
|
||||
count = count + (count - 1);
|
||||
|
||||
```
|
||||
|
@ -10,7 +10,7 @@ Use this activity document to guide your work in the [guess the number tutorial]
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what "input -> on button pressed" does?
|
||||
## 1. Describe what ``||input:on button pressed||`` does?
|
||||
|
||||
<br />
|
||||
|
||||
@ -26,7 +26,7 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
|
||||
|
||||
```blocks
|
||||
let randomNumber = Math.randomRange(0, 10)
|
||||
basic.showNumber(randomNumber, 150)
|
||||
basic.showNumber(randomNumber)
|
||||
```
|
||||
|
||||
![](/static/mb/empty-microbit.png)
|
||||
|
@ -12,20 +12,19 @@ Collection
|
||||
* [quiz](/lessons/headbands/quiz)
|
||||
* [quiz answers](/lessons/headbands/quiz-answers)
|
||||
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a charades game with **collections**, ` create -> Collection of` , to store and retrieve data . We will be learning how to create a charades game using global variables, collection of string, add, Boolean, on logo down, on logo up, forever loop, if statements, running time as well as simple commands, such as show string and show number.
|
||||
Learn how to create a charades game using **[arrays](/types/array)** to store and retrieve data. We'll learn how to create a charades game using global variables, a collection of strings, math add, Boolean, on logo down, on logo up, forever loop, if statements, running time as well as simple commands, such as show string and show number.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Algorithm: An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Data: A structured set of numbers, possibly representing digitized text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
@ -117,4 +116,3 @@ Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algor
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
||||
|
@ -11,12 +11,12 @@ coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
input.onGesture(Gesture.LogoUp, function () {
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
basic.showString(word)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
input.onGesture(Gesture.ScreenDown, function () {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(30000)
|
||||
@ -24,7 +24,7 @@ game.startCountdown(30000)
|
||||
|
||||
## Challenge 1
|
||||
|
||||
Let's add more words for the player to act out! But first, we need to increase the time in one round to give the player more time get through all the words. Let's change the `game->start countdown` statement.
|
||||
Let's add more words for the player to act out! But first, we need to increase the time in one round to give the player more time get through all the words. Let's change the ``||game:start countdown||`` statement.
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
@ -33,12 +33,12 @@ coll.push("clock")
|
||||
coll.push("night")
|
||||
coll.push("cat")
|
||||
coll.push("cow")
|
||||
input.onLogoUp(() => {
|
||||
input.onGesture(Gesture.LogoUp, function () {
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
basic.showString(word)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
input.onGesture(Gesture.ScreenDown, function () {
|
||||
game.addScore(1)
|
||||
})
|
||||
|
||||
@ -49,7 +49,7 @@ game.startCountdown(60000)
|
||||
|
||||
## Challenge 2
|
||||
|
||||
Now let's add 5 more words to our list of charade words. Right above the the line `word:=coll->at(index)` add 5 lines that say `coll->add("")`. In this example, we will add the words **bicycle, telephone, sun, car, and ant** but you can add whatever words you like.
|
||||
Now let's add 5 more words to our list of charade words. Right above the the line ``||arrays:get value at index||`` add 5 lines that say ``||arrays:coll add value to end||``. In this example, we will add the words **bicycle, telephone, sun, car, and ant** but you can add whatever words you like.
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
@ -63,12 +63,12 @@ coll.push("telephone")
|
||||
coll.push("sun")
|
||||
coll.push("car")
|
||||
coll.push("ant")
|
||||
input.onLogoUp(() => {
|
||||
input.onGesture(Gesture.LogoUp, function () {
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
basic.showString(word, 150)
|
||||
basic.showString(word)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
input.onGesture(Gesture.ScreenDown, function () {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(30000)
|
||||
@ -78,13 +78,9 @@ game.startCountdown(30000)
|
||||
|
||||
## Challenge 3
|
||||
|
||||
Remove a life using `game->remove life` when the screen is down using the `input->on screen down` event.
|
||||
Remove a life using ``||game.remove life||`` when the screen is down using the ``||input:on screen down||`` event.
|
||||
|
||||
## Challenge 4
|
||||
|
||||
The collection has a function `random` that returns a random element. Update your code to use this function instead of using `math->random`.
|
||||
|
||||
## Challenge 5!
|
||||
## Challenge 4!
|
||||
|
||||
Play the game and try guessing all these words in less than 2 minutes!
|
||||
|
||||
|
@ -24,13 +24,13 @@ coll.push("puppy")
|
||||
coll.push("clock")
|
||||
```
|
||||
|
||||
Write the line of code that will display the string "puppy" using `data->coll`.
|
||||
Write the line of code that will display the string "puppy" using ``||variables:coll||``.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
basic.showString(coll[0], 150)
|
||||
basic.showString(coll[0])
|
||||
```
|
||||
|
||||
## 3. Consider the following lines of code.
|
||||
@ -42,13 +42,13 @@ coll.push("clock")
|
||||
coll.push("cat")
|
||||
```
|
||||
|
||||
Write the line of code that will display the string "cat" using `data->coll`.
|
||||
Write the line of code that will display the string "cat" using ``||variables:coll||``.
|
||||
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
let coll: string[] = []
|
||||
basic.showString(coll[2], 150)
|
||||
basic.showString(coll[2])
|
||||
```
|
||||
|
||||
## 4. Consider the following line of code.
|
||||
@ -57,7 +57,7 @@ basic.showString(coll[2], 150)
|
||||
let coll: string[] = []
|
||||
```
|
||||
|
||||
Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
Write the five (5) lines of code that will add the following five words to ``||variables:coll||``: `"puppy"`, `"clock"`, `"night"`, `"cat"`, and `"cow"`.
|
||||
|
||||
<br/>
|
||||
|
||||
@ -79,4 +79,3 @@ let coll: string[] = []
|
||||
let index = Math.randomRange(0, coll.length)
|
||||
let word = coll[index]
|
||||
```
|
||||
|
||||
|
@ -16,20 +16,20 @@ Answer the questions while completing the tutorial. Pay attention to the dialogu
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code that will display the string "puppy" using "data->coll".
|
||||
## 2. Write the line of code that will display the string "puppy" using `coll`.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
let coll: string[] = []
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the line of code that will display the string "cat" using `"data->coll".
|
||||
## 3. Write the line of code that will display the string "cat" using `coll`.
|
||||
|
||||
```blocks
|
||||
let coll = (<string[]>[])
|
||||
let coll: string[] = []
|
||||
coll.push("puppy")
|
||||
coll.push("clock")
|
||||
coll.push("cat")
|
||||
@ -37,7 +37,7 @@ coll.push("cat")
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow.
|
||||
## 4. Write the five (5) lines of code that will add the following five words to `coll`: puppy, clock, night, cat, cow.
|
||||
|
||||
```typescript
|
||||
let coll : string[] = [];
|
||||
|
@ -17,12 +17,12 @@ On Logo Up
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to plot image **on logo up**, `on logo up` to run code when the @boardname@ screen is facing up and vertically orientated. We will be learning how to plot an image with the logo up, basic show LEDs, and logo down.
|
||||
Learn how to plot an image using ``||input:on logo up||`` to run code when the @boardname@ screen is facing up and vertically orientated. We will be learning how to plot an image with the logo up, basic show LEDs, and logo down.
|
||||
|
||||
## Documentation
|
||||
```cards
|
||||
input.onLogoUp(() => {})
|
||||
input.onLogoDown(() => {})
|
||||
input.onGesture(Gesture.LogoUp, function () {})
|
||||
input.onGesture(Gesture.LogoDown, function () {})
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
|
@ -8,7 +8,7 @@ Welcome! This tutorial will help you display an arrow pointing toward the logo!
|
||||
|
||||
## ~
|
||||
|
||||
Using the **accelerometer** sensor, the @boardname@ can detect when the **logo** is oriented **up**. We call that the **logo up** event. We will use `on logo up` to register an event handler that will run when the **logo up** event happens.
|
||||
Using the **accelerometer** sensor, the @boardname@ can detect when the **logo** is oriented **up**. We call that the **logo up** event. We will use ``||input:on logo up||`` to register an event handler that will run when the **logo up** event happens.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.LogoUp, () => {
|
||||
@ -16,7 +16,7 @@ input.onGesture(Gesture.LogoUp, () => {
|
||||
})
|
||||
```
|
||||
|
||||
When the @boardname@ goes logo up, the code nested under the `on logo up` function will run. Let's add a line of code to show LEDs in there.
|
||||
When the @boardname@ goes logo up, the code nested under the ``||input:on logo up||`` function will run. Let's add a line of code to show LEDs in there.
|
||||
|
||||
```blocks
|
||||
input.onGesture(Gesture.LogoUp, () => {
|
||||
|
@ -7,7 +7,7 @@ Coding challenges for magic logo.
|
||||
Complete the [magic logo](/lessons/magic-logo/activity) activity and your code will look like this:
|
||||
|
||||
```blocks
|
||||
input.onLogoUp(() => {
|
||||
input.onGesture(Gesture.LogoUp, function () {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
@ -25,7 +25,7 @@ input.onLogoUp(() => {
|
||||
How about when the logo is down? We should display an arrow pointing downward!
|
||||
|
||||
```blocks
|
||||
input.onLogoUp(() => {
|
||||
input.onGesture(Gesture.LogoUp, function () {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
@ -34,7 +34,7 @@ input.onLogoUp(() => {
|
||||
. . # . .
|
||||
`)
|
||||
})
|
||||
input.onLogoDown(() => {
|
||||
input.onGesture(Gesture.LogoDown, function () {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
|
@ -28,7 +28,7 @@ The `logo up` event is raised when...
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
input.onLogoUp(() => {
|
||||
input.onGesture(Gesture.LogoUp, function () {
|
||||
})
|
||||
```
|
||||
|
||||
@ -43,7 +43,7 @@ input.onLogoUp(() => {
|
||||
<br/>
|
||||
|
||||
```blocks
|
||||
input.onLogoDown(() => {
|
||||
input.onGesture(Gesture.LogoDown, function () {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
|
@ -8,7 +8,7 @@ show an image that points up when the logo is up.
|
||||
|
||||
Use the hints from the [magic logo activity](/lessons/magic-logo/activity) to answer this quiz!
|
||||
|
||||
## 1. Define what `input->on logo up` does
|
||||
## 1. Define what ``||input:on logo up||`` does
|
||||
|
||||
<br/>
|
||||
|
||||
|
@ -10,7 +10,7 @@ Use this activity document to guide your work in the [night light tutorial](/les
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what "led->set brightness" does ?
|
||||
## 1. Describe what ``||led:set brightness||`` does ?
|
||||
|
||||
## 2. If the picture below is the @boardname@, write the code that sets all the LEDs to full brightness and turns on all the LEDs
|
||||
|
||||
|
@ -79,7 +79,7 @@ input.onButtonPressed(Button.AB, () => {
|
||||
}
|
||||
basic.showNumber(Math.max(player1Score, player2Score))
|
||||
})
|
||||
input.onGesture(Gesture.LogoDown, () => {
|
||||
input.onGesture(Gesture.LogoDown, function () {
|
||||
player2Score = 0
|
||||
player1Score = 0
|
||||
basic.showString("Reset")
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Plot LEDs
|
||||
|
||||
Display an [Image](/reference/images/image) on the @boardname@'s [LED screen](/device/screen). NOTE: `basic -> plot image` has been replaced by `basic -> show leds`.
|
||||
Display an [Image](/reference/images/image) on the @boardname@'s [LED screen](/device/screen).
|
||||
|
||||
```sig
|
||||
basic.showLeds(`
|
||||
|
Loading…
Reference in New Issue
Block a user