Migrate docs from the other repo
This commit is contained in:
81
docs/reference/js/antenna.md
Normal file
81
docs/reference/js/antenna.md
Normal file
@ -0,0 +1,81 @@
|
||||
# Antenna Library
|
||||
|
||||
The events library #docs
|
||||
|
||||
The functions in the ``antenna`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device.
|
||||
|
||||
### Remote control
|
||||
|
||||
Control the presentation of media content available on a remote device using the `tell remote control to` function
|
||||
|
||||
```
|
||||
export function tellRemoteControlTo(event: string)
|
||||
```
|
||||
|
||||
The remote control specific events include:
|
||||
|
||||
* play
|
||||
* pause
|
||||
* stop
|
||||
* next track
|
||||
* previous track
|
||||
* forward
|
||||
* rewind
|
||||
* volume up
|
||||
* volume down
|
||||
|
||||
### Camera
|
||||
|
||||
Access the photo/video-taking functionality of a remote device using the *camera* function:
|
||||
|
||||
```
|
||||
export function tellCameraTo(event: string)
|
||||
```
|
||||
|
||||
The camera-specific events include:
|
||||
|
||||
* toggle front-rear
|
||||
* launch photo mode
|
||||
* take photo
|
||||
* stop photo mode
|
||||
* launch video mode
|
||||
* start video capture
|
||||
* stop video capture
|
||||
* stop video mode
|
||||
|
||||
### Alert
|
||||
|
||||
Raise an alert on a remote device using the `raise alert to` function
|
||||
|
||||
```
|
||||
export function raiseAlertTo(event: string)
|
||||
```
|
||||
|
||||
The set of alerting-specific events include:
|
||||
|
||||
* display toast
|
||||
* vibrate
|
||||
* play sound
|
||||
* play ringtone
|
||||
* find my phone
|
||||
* alarm 1
|
||||
* alarm 2
|
||||
* alarm 3
|
||||
* alarm 4
|
||||
* alarm 5
|
||||
* alarm 6
|
||||
|
||||
### Microphone
|
||||
|
||||
Access the audio recording capabilities of the device using the `tell microphone to` function
|
||||
|
||||
```
|
||||
export function tellMicrophoneTo(event: string)
|
||||
```
|
||||
|
||||
The set of audio recorder events include:
|
||||
|
||||
* launch
|
||||
* start capture
|
||||
* end capture
|
||||
* stop
|
54
docs/reference/js/assign.md
Normal file
54
docs/reference/js/assign.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Assignment Operator
|
||||
|
||||
Set the value for local and global variables #docs #assignment #language #var #data
|
||||
|
||||
### @parent js/operators
|
||||
|
||||
|
||||
Set or change the value of a variable
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
### Touch Develop
|
||||
|
||||
Use the assignment operator (:=) to set or change the value of a [local variable](/microbit/reference/variables/var) or a [global variable](/microbit/js/data).
|
||||
|
||||
### Declare a variable
|
||||
|
||||
Declare a new *local* variable using the [var](/microbit/reference/variables/var) statement and the assignment operator (`:=`). Like this:
|
||||
|
||||
```blocks
|
||||
let num1 = 7
|
||||
let name = "Joe"
|
||||
```
|
||||
|
||||
The variable's name is on the left of the assignment operator (`:=`) and the variable's value is on the right:
|
||||
|
||||
*variable name* `:=` *value*
|
||||
|
||||
See [global variable](/microbit/js/data) for info on declaring a global variable.
|
||||
|
||||
### Change a variable
|
||||
|
||||
After a global or local variable is defined, use the assignment operator (`:=`) to change the variable's value.
|
||||
|
||||
```
|
||||
g = 42
|
||||
num1 = 42
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
* Don't confuse the assignment operator `:=` with the equality operator `=`, which is used to compare values.
|
||||
* You can use the assignment operator `:=` with variables of each of the supported [types](/microbit/js/types).
|
||||
|
||||
### Lessons
|
||||
|
||||
[counter](/microbit/lessons/counter), [rotation animation](/microbit/lessons/rotation-animation), [digital pet](/microbit/lessons/digital-pet), [offset image](/microbit/lessons/offset-image)
|
||||
|
||||
### See also
|
||||
|
||||
[local variables](/microbit/reference/variables/var), [global variables](/microbit/js/data), [types](/microbit/js/types)
|
||||
|
67
docs/reference/js/bits.md
Normal file
67
docs/reference/js/bits.md
Normal file
@ -0,0 +1,67 @@
|
||||
# Bits Library
|
||||
|
||||
Functions in the Bits library. #docs #bits #32bit #signed #unsigned
|
||||
|
||||
### @parent td/language
|
||||
|
||||
The binary numeral system represents numeric values using values 0 and 1. This is how almost all modern computers store data. Each 0 or 1 digit is called a binary digit, or bit for short.
|
||||
|
||||
The Bits library includes functions for bit-level manipulation of integers. In the [Touch Develop editor](/microbit/js/editor), click `bits` to see the following bit functions:
|
||||
|
||||
## Bitwise and, or, and xor functions
|
||||
|
||||
#### Syntax
|
||||
|
||||
bits `->` *and/or/xor* uint32 (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number)
|
||||
|
||||
#### Parameters
|
||||
|
||||
* x - an unsigned 32 bit integer [Number](/microbit/reference/types/number)
|
||||
* y - another unsigned 32 bit integer [Number](/microbit/reference/types/number)
|
||||
|
||||
### and uint32
|
||||
|
||||
performs bitwise AND; returns `1` at position i if both bits *x[i]* and *y[i]* are `1`, otherwise returns `0`.
|
||||
|
||||
### or uint32
|
||||
|
||||
performs bitwise OR; returns `1` at position *i* if either bit *x[i]* or *y[i]* is `1`, otherwise returns `0`.
|
||||
|
||||
### xor uint32
|
||||
|
||||
performs bitwise exclusive XOR; returns `1` at position *i* if *x[i]=1 and y[i]=0* or *x[i] = 0 and y[i] =1*; returns `0` otherwise
|
||||
|
||||
## Rotate left and rotate right
|
||||
|
||||
Rotate bits to the left or the right, by the specified number of positions.
|
||||
|
||||
#### Syntax
|
||||
|
||||
bits `->` rotate left unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number)
|
||||
|
||||
bits `->` rotate right unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number)
|
||||
|
||||
#### Parameters
|
||||
|
||||
* x - [Number](/microbit/reference/types/number);
|
||||
* bits - [Number](/microbit/reference/types/number);
|
||||
|
||||
## Shift left and shift right
|
||||
|
||||
Shift bits to the left or the right, by the specified number of positions.
|
||||
|
||||
#### Syntax
|
||||
|
||||
bits `->` shift left unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number)
|
||||
|
||||
bits `->` shift right unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number)
|
||||
|
||||
#### Parameters
|
||||
|
||||
* x - [Number](/microbit/reference/types/number);
|
||||
* bits - [Number](/microbit/reference/types/number);
|
||||
|
||||
### See also
|
||||
|
||||
[statements and operators](/microbit/js/statements), [math functions](/microbit/js/math), [Number](/microbit/reference/types/number)
|
||||
|
122
docs/reference/js/boolean.md
Normal file
122
docs/reference/js/boolean.md
Normal file
@ -0,0 +1,122 @@
|
||||
# Boolean
|
||||
|
||||
true or false.
|
||||
|
||||
### @parent js/language
|
||||
|
||||
A Boolean has one of two possible values: `true`; `false`. Boolean (logical) operators (*and*, *or*, *not*) take Boolean inputs and yields a Boolean value. Comparison operators on other types ([numbers](/microbit/reference/types/number), [strings](/microbit/reference/types/string)) yields a Boolean value.
|
||||
|
||||
### Block Editor
|
||||
|
||||
In the Block Editor, the following blocks represent the true and false Boolean values, which can be plugged in anywhere a Boolean value is expected:
|
||||
|
||||

|
||||
|
||||
The next three blocks represent the three Boolean (logic) operators:
|
||||
|
||||

|
||||
|
||||
The next six blocks represent comparison operators that yield a Boolean value. Most comparisons you will do involve [numbers](/microbit/reference/types/number):
|
||||
|
||||

|
||||
|
||||
### Touch Develop
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
let condition = true
|
||||
let condition2 = true
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
Boolean values and operators are often used with an [if](/microbit/reference/logic/if) or [while](/microbit/js/while) statement to determine which code will execute next. For example:
|
||||
|
||||
```
|
||||
if (condition && condition2) {
|
||||
// This code runs if both `condition` and `condition2` are `true`
|
||||
} else {
|
||||
// This code runs if either `condition` or `condition2` is `false`
|
||||
}
|
||||
```
|
||||
|
||||
### Functions that return a Boolean
|
||||
|
||||
Some functions return a Boolean value, which you can store in a Boolean variable. For example, the following code gets the on/off state of `point (1, 2)` and stores this in the Boolean variable named `on`. Then the code clears the screen if `on` is `true`:
|
||||
|
||||
```
|
||||
let on = led.point(1, 2)
|
||||
if (on) {
|
||||
basic.clearScreen()
|
||||
}
|
||||
```
|
||||
|
||||
### Boolean operators
|
||||
|
||||
Boolean operators take Boolean inputs and evaluate to a Boolean output:
|
||||
|
||||
### Conjunction: `A and B`
|
||||
|
||||
`A and B` evaluates to `true` if-and-only-if both A and B are true:
|
||||
|
||||
- `false and false` = `false`
|
||||
|
||||
- `false and true` = `false`
|
||||
|
||||
- `true and false` = `false`
|
||||
|
||||
- `true and true` = `true`
|
||||
|
||||
### Disjunction: `A or B`
|
||||
|
||||
`A or B` evaluates to `true` if-and-only-if either A is true or B is true:
|
||||
|
||||
- `false or false` = `false`
|
||||
|
||||
- `false or true` = `true`
|
||||
|
||||
- `true or false` = `true`
|
||||
|
||||
- `true or true` = `true`
|
||||
|
||||
### Negation: `not A`
|
||||
|
||||
`not A` evaluates to the opposite (negation) of A:
|
||||
|
||||
* `not false` = `true`
|
||||
* `not true` = `false`
|
||||
|
||||
### Example
|
||||
|
||||
This example turns on LED `3 , 3`, if LEDs `1 , 1` and `2 , 2` are both on:
|
||||
|
||||
```
|
||||
if (led.point(1, 1) && led.point(2, 2)) {
|
||||
led.plot(3, 3)
|
||||
}
|
||||
```
|
||||
|
||||
### Comparisons of numbers and strings
|
||||
|
||||
When you compare two Numbers, you get a Boolean value, such as the comparison `x < 5` in the code below:
|
||||
|
||||
```
|
||||
let x = Math.random(10)
|
||||
if (x < 5) {
|
||||
basic.showString("Low", 150)
|
||||
} else {
|
||||
basic.showString("High", 150)
|
||||
}
|
||||
```
|
||||
|
||||
See the documentation on [Numbers](/microbit/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/microbit/reference/types/string-functions) using the `equals` function.
|
||||
|
||||
### Lessons
|
||||
|
||||
[rotation animation](/microbit/lessons/rotation-animation), [digi yoyo](/microbit/lessons/digi-yoyo), [love meter](/microbit/lessons/love-meter), [zoomer](/microbit/lessons/zoomer)
|
||||
|
||||
### See also
|
||||
|
||||
[if](/microbit/reference/logic/if), [while](/microbit/js/while), [number](/microbit/reference/types/number)
|
||||
|
37
docs/reference/js/break.md
Normal file
37
docs/reference/js/break.md
Normal file
@ -0,0 +1,37 @@
|
||||
# Break
|
||||
|
||||
Break statement; exit a for or while loop. #docs #break #language #loop #for #while
|
||||
|
||||
### @parent js/language
|
||||
|
||||
|
||||
Exit a [while](/microbit/js/while) or [for](/microbit/reference/loops/for) loop before the loop is complete.
|
||||
|
||||
### Touch Develop syntax
|
||||
|
||||
**break**
|
||||
|
||||
### Example: count to a random number
|
||||
|
||||
The following example counts from 0 to a random number from 0-9. When the for loop counter equals the random number (`i = x`), the `break` statement exits the loop:
|
||||
|
||||
```
|
||||
let x = Math.random(10)
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (i == x) {
|
||||
break
|
||||
} else {
|
||||
basic.showNumber(i, 0)
|
||||
basic.pause(500)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[jailbreak](/microbit/lessons/jailbreak)
|
||||
|
||||
### See also
|
||||
|
||||
[for](/microbit/reference/loops/for), [while](/microbit/js/while)
|
||||
|
63
docs/reference/js/call.md
Normal file
63
docs/reference/js/call.md
Normal file
@ -0,0 +1,63 @@
|
||||
# Call a Function
|
||||
|
||||
How to call a function in your code. #docs #function #call #language
|
||||
|
||||
### @parent js/language
|
||||
|
||||
|
||||
Type a function name in your code to call an existing [function](/microbit/js/function) in your script.
|
||||
|
||||
### Call a function
|
||||
|
||||
1. In the Touch Develop editor, click a line of code to open the on-screen [Code Keyboard](/microbit/js/editor).
|
||||
|
||||
2. Click `code` to see the functions in your script.
|
||||
|
||||
2. Click the function that you want to call.
|
||||
|
||||
3. Click `store in var` to store the return value in a variable.
|
||||
|
||||
### Example: the square function
|
||||
|
||||
Here's a function called `square`, with a [Number](/microbit/reference/types/number) input parameter:
|
||||
|
||||
```
|
||||
/**
|
||||
* // returns the square of the input parameter x
|
||||
* @param x TODO
|
||||
*/
|
||||
export function square(x: number) : number {
|
||||
let result: number
|
||||
return x * x
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
||||
The following code calls the `square` function, passing it an input parameter (`x`), and storing the return value in the `result` variable:
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
let x1 = 2
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
let result1 = square(x1)
|
||||
```
|
||||
|
||||
Or this code, which displays the result of the `square` function (without first storing the value in a variable):
|
||||
|
||||
```
|
||||
basic.showNumber(square(x1), 150)
|
||||
```
|
||||
|
||||
### See all your functions
|
||||
|
||||
To see a list of the functions in a script, open the script and then click `script` (in the upper-right corner). All of the functions appear under the **code** heading. Click on a function to open it in the editor.
|
||||
|
||||
### See also
|
||||
|
||||
[function parameters](/microbit/js/functionparameters), [create a function](/microbit/js/function), [return statement](/microbit/js/return)
|
||||
|
31
docs/reference/js/code.md
Normal file
31
docs/reference/js/code.md
Normal file
@ -0,0 +1,31 @@
|
||||
# function
|
||||
|
||||
A function with inputs and outputs. #docs #function #language
|
||||
|
||||
### @parent js/language
|
||||
|
||||
|
||||
To add a **functions** to your script, click the `script` button, then click the `+` `add new function` button
|
||||
|
||||
### functions
|
||||
|
||||
A **function** takes [inputs](/microbit/actionparameters), runs code and (optionally) returns an output.
|
||||
|
||||
TouchDevelop functions are similar to `mathematical functions`. Consider the function that computes the square of `x`: `square(x) = x*x`. In code, it would look like this:
|
||||
|
||||
```
|
||||
export function square(x: number) : number {
|
||||
let result: number
|
||||
return x * x
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
||||
### private function
|
||||
|
||||
An function can be marked as **private** in the properties. A private function is not visible outside a library (if the script is a library)
|
||||
|
||||
### documentation
|
||||
|
||||
The comment(s) at the beginning of a function used to provide a description of its purpose. This text will show in the help area when the function is called from the code editor. This is particularly useful for [libraries](/microbit/libraries).
|
||||
|
111
docs/reference/js/collections.md
Normal file
111
docs/reference/js/collections.md
Normal file
@ -0,0 +1,111 @@
|
||||
# The Collections Library
|
||||
|
||||
#docs
|
||||
|
||||
A collection allows you to store an arbitrary number of elements. If you have a collection of numbers, you can add new numbers to the collection; remove numbers; check if a number is in there; iterate over all the numbers in the collection.
|
||||
|
||||
## Creation
|
||||
|
||||
A collection is created as follows. Note that we are providing the *type* of the elements that are meant to go in the collection.
|
||||
|
||||
```
|
||||
let c = (<number[]>[])
|
||||
```
|
||||
|
||||
At the moment, you can create collections of numbers, booleans, strings, and any of the object types that you defined.
|
||||
|
||||
**Important:** if your collection is a global variable, make sure you initialise it at the beginning of your script.
|
||||
|
||||
```
|
||||
c = (<boolean[]>[])
|
||||
```
|
||||
|
||||
Trying to use an uninitialised collection will crash the simulator, and display a sad face on the device.
|
||||
|
||||
## Adding and finding elements; counting
|
||||
|
||||
```
|
||||
c.push(3)
|
||||
```
|
||||
|
||||
The line above just added the number `3` to the collection. One can think of a collection as a list, where `add` appends the element at the end of the list.
|
||||
|
||||
At this stage, our collection has size `1`, meaning that the line below will display `1`.
|
||||
|
||||
```
|
||||
basic.showNumber(c.length, 150)
|
||||
```
|
||||
|
||||
We can add another number as follows.
|
||||
|
||||
```
|
||||
c.push(5)
|
||||
```
|
||||
|
||||
At this stage, the count of elements in the collection is `2`. We mentioned earlier that a collection is like a list: adding elements appends them at the end of the list. This means that, at this point in the program, the first element in the list is 3 (we added it earlier), and the second element in the list is 5 (we just added it).
|
||||
|
||||
```
|
||||
basic.showNumber(c[0], 150)
|
||||
```
|
||||
|
||||
Can you guess what the line above does? Remember that in computing, indexing starts at zero. This function takes the *first element* in the list. This means that the line above displays `3`.
|
||||
|
||||
We can ask questions such as: "what is the index of this element"? The line below displays `1`, meaning that the number `5` is first found at index `1` (it is the *second* element in the list).
|
||||
|
||||
```
|
||||
basic.showNumber(c.indexOf(5, 0), 150)
|
||||
```
|
||||
|
||||
## Iterating over the elements
|
||||
|
||||
A classic pattern consists in iterating over all the elements in the collection. Here's one way to do it:
|
||||
|
||||
```
|
||||
for (let i = 0; i < c.length; i++) {
|
||||
basic.showString("The element at index " + i.toString() + " is " + c[i].toString(), 150)
|
||||
}
|
||||
```
|
||||
|
||||
The code above will first print `The element at index 0 is 3`, then `The element at index 1 is 5`.
|
||||
|
||||
## Modifying and removing elements
|
||||
|
||||
One can modify an existing collection using `set at`, which changes the element *at a given index*.
|
||||
|
||||
```
|
||||
c[0] = 7
|
||||
```
|
||||
|
||||
The line above modifies the collection `c` so that, after the line above, the first element of the collection is now `7`.
|
||||
|
||||
Removing elements can be done in two different ways. We can remove the *first occurrence* of an element.
|
||||
|
||||
```
|
||||
c.remove(5)
|
||||
```
|
||||
|
||||
This removes the first occurrence of `5` in the list. At this point in the program, our list now has just one element (at index 0). If we wish, we can use `remove at` to remove the element at a given index.
|
||||
|
||||
```
|
||||
c.splice(0, 1)
|
||||
```
|
||||
|
||||
Now, the collection is empty.
|
||||
|
||||
## Complete example
|
||||
|
||||
This program will record the current acceleration measured on `x` when you press `A`; when you press `B`, the program will print out all the acceleration values that were measured, then will clear the collection.
|
||||
|
||||
```
|
||||
let accelerations = (<number[]>[])
|
||||
input.onButtonPressed("A", () => {
|
||||
accelerations.push(input.acceleration("x"))
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
for (let i1 = 0; i1 < accelerations.length; i1++) {
|
||||
basic.showString(accelerations[i1].toString(), 150)
|
||||
}
|
||||
accelerations.clear()
|
||||
})
|
||||
```
|
||||
|
79
docs/reference/js/comment.md
Normal file
79
docs/reference/js/comment.md
Normal file
@ -0,0 +1,79 @@
|
||||
# Comment
|
||||
|
||||
A note in code. #docs #comment #language
|
||||
|
||||
### @parent js/statement
|
||||
|
||||
|
||||
A comment is a line of code that contains text, usually an explanation or a note. All comments are ignored during script execution.
|
||||
|
||||
### Block
|
||||
|
||||
Right click on any block and add a comment
|
||||
|
||||
### Touch Develop syntax
|
||||
|
||||
To insert a comment in a Touch Develop script:
|
||||
|
||||
1. Click a line in your script.
|
||||
|
||||
2. Click `+`.
|
||||
|
||||
3. Click `// comment` and then type some text (your comment).
|
||||
|
||||
### ~hint
|
||||
|
||||
To find out how to insert comments using the Blocks editor, see [the Blocks editor](/microbit/blocks/editor).
|
||||
|
||||
### ~
|
||||
|
||||
### Sample function with comments
|
||||
|
||||
This function has comments that describe the purpose of the function:
|
||||
|
||||
```
|
||||
/**
|
||||
* // square function :
|
||||
* // returns the square of the input parameter x
|
||||
* @param x TODO
|
||||
*/
|
||||
export function square(x: number) : number {
|
||||
let result: number
|
||||
return x * x
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
||||
### Formatting
|
||||
|
||||
Use [markdown syntax](/microbit/js/markdown) to format your comments (for example, **bold** and *italic* formatting).
|
||||
|
||||
### Commenting out code
|
||||
|
||||
During the debugging process, you may want to comment out a section of your code so that it doesn't run.
|
||||
|
||||
To comment out a block of code:
|
||||
|
||||
1. Click the first line of code that you want to comment out.
|
||||
|
||||
2. Press and hold the Shift key, and then press the Down arrow key to select a block of code.
|
||||
|
||||
3. In the block editing window, scroll down to **surround with** and click `comment out`. This adds an [if](/microbit/reference/logic/if) statement around your code, like this:
|
||||
|
||||
```
|
||||
if (false) {
|
||||
// the commented code here...
|
||||
}
|
||||
```
|
||||
|
||||
When you want to uncomment your code, click the `if false then` statement in your code, and then click `uncomment`.
|
||||
|
||||
### Library and function comments
|
||||
|
||||
* Use [comments](/microbit/js/comment) at the beginning of a library to describe the library
|
||||
* Use [comments](/microbit/js/comment) at the beginning of a [function](/microbit/js/function) to describe a function. The comment will appear in the help area of the Touch Develop editor when you insert the function
|
||||
|
||||
### See also
|
||||
|
||||
[markdown syntax](/microbit/js/markdown), [Touch Develop editor](/microbit/js/editor), [Block editor](/microbit/blocks/editor)
|
||||
|
30
docs/reference/js/compiler.md
Normal file
30
docs/reference/js/compiler.md
Normal file
@ -0,0 +1,30 @@
|
||||
# In-browser compiler
|
||||
|
||||
The BBC micro:bit pins #docs #gnd #p1 #p2 #p3 #3V
|
||||
|
||||
## We listened to your feedback!
|
||||
|
||||
Following the feedback from teachers, the following improvements were made:
|
||||
|
||||
* compile without signing in
|
||||
* compile offline
|
||||
* save and load code using files
|
||||
|
||||
## A new in-browser compiler
|
||||
|
||||
The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The BBC micro:bit compilation process (see page 10 in the Quick Start book) has been updated below to reflect the new compiler architecture, shown below.
|
||||
|
||||

|
||||
|
||||
The C++ compiler now only is used to compile the micro:bit runtime - this is done offline by the micro:bit team and the precompiled runtime linked with your compiled script in the browser.
|
||||
|
||||
## Save and load code using files
|
||||
|
||||

|
||||
|
||||
The BBC micro:bit automatically saves and synchronizes scripts for signed in users through the cloud. Unfortunately, this scenario would not work always so we decided to also support files. Users are now able to import and export scripts as files. For example, they can simply email it or submit them in their classroom portal.
|
||||
|
||||

|
||||
|
||||
Compiled .hex files can also be imported back into the web site. This make it easy for a teacher to review the source of a script by simply drag and dropping the file into the editor.
|
||||
|
216
docs/reference/js/contents.md
Normal file
216
docs/reference/js/contents.md
Normal file
@ -0,0 +1,216 @@
|
||||
# Touch Develop Documentation
|
||||
|
||||
Touch Develop docs for the micro:bit #docs #contents #apis #functions #language #statements
|
||||
|
||||
### @section full
|
||||
|
||||
### @parent editor-documentation
|
||||
|
||||
### @short Touch Develop
|
||||
|
||||
### ~hint
|
||||
|
||||
**Spotty internet? No problem!** (1) When online, go to https://www.microbit.co.uk/app/ and bookmark this URL; (2) use the bookmark to reload the web app, even without the internet.
|
||||
|
||||
### ~
|
||||
|
||||
Welcome to the Touch Develop home page for the BBC micro:bit. Below you will find resources about the Touch Develop programming language and code editor. Good places to start include:
|
||||
|
||||
* [the Touch Develop Editor](/microbit/js/editor)
|
||||
* [30+ BBC micro:bit lessons](/microbit/lessonss)
|
||||
* [offline support](/microbit/offline)
|
||||
|
||||
### ~column
|
||||
|
||||
## Language {#pconst}
|
||||
|
||||
### Variables
|
||||
|
||||
* [local variables](/microbit/reference/variables/var)
|
||||
* [global variables ](/microbit/js/data)
|
||||
|
||||
### Types
|
||||
|
||||
* [Number](/microbit/reference/types/number)
|
||||
* [Boolean](/microbit/reference/types/boolean)
|
||||
* [String](/microbit/reference/types/string)
|
||||
* [Image](/microbit/reference/image/image)
|
||||
|
||||
### Statements and control structures
|
||||
|
||||
* [assignment operator](/microbit/reference/variables/assign) `:=`
|
||||
* [if](/microbit/reference/logic/if)
|
||||
* [for](/microbit/reference/loops/for)
|
||||
* [while](/microbit/js/while)
|
||||
* [break](/microbit/js/break)
|
||||
* [forever](/microbit/reference/basic/forever)
|
||||
* [in background](/microbit/reference/control/in-background)
|
||||
* [function](/microbit/js/function)
|
||||
* [return](/microbit/js/return)
|
||||
|
||||
### Maths
|
||||
|
||||
* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [Numbers](/microbit/reference/types/number)
|
||||
* comparison operators (such as `>`, `=`) on [Numbers](/microbit/reference/types/number)
|
||||
* the [math](/microbit/js/math) library
|
||||
* the [bits](/microbit/js/bits) library
|
||||
|
||||
### Logical
|
||||
|
||||
* [Boolean](/microbit/reference/types/boolean) values `true` and `false`
|
||||
* Operations (`not`, `or`, `and`) on [Booleans](/microbit/reference/types/boolean)
|
||||
|
||||
### Strings
|
||||
|
||||
* [string functions](/microbit/reference/types/string-functions)
|
||||
|
||||
### Functions
|
||||
|
||||
* [create a function](/microbit/js/function)
|
||||
* [function parameters](/microbit/js/functionparameters)
|
||||
* [call a function](/microbit/js/call)
|
||||
|
||||
### Collections
|
||||
|
||||
* read the [collections tutorial](/microbit/js/collections)
|
||||
|
||||
### Custom object types
|
||||
|
||||
* see the [object types tutorial](/microbit/js/object-types)
|
||||
* read the [object disclaimer](/microbit/js/object-disclaimer) if you're an advanced user
|
||||
|
||||
### Libraries
|
||||
|
||||
* [create and use libraries](/microbit/js/libraries)
|
||||
|
||||
### Documentation
|
||||
|
||||
* [comments](/microbit/js/comment)
|
||||
* [markdown syntax](/microbit/js/markdown)
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
## BBC micro:bit functions
|
||||
|
||||
### Basic
|
||||
|
||||
* [clear screen](/microbit/reference/basic/clear-screen)
|
||||
* [forever](/microbit/reference/basic/forever)
|
||||
* [pause](/microbit/reference/basic/pause)
|
||||
* [show leds](/microbit/reference/basic/show-leds)
|
||||
* [show animation](/microbit/reference/basic/show-animation)
|
||||
* [show number](/microbit/reference/basic/show-number)
|
||||
* [show string](/microbit/reference/basic/show-string)
|
||||
|
||||
### LED
|
||||
|
||||
* [brightness](/microbit/reference/led/brightness)
|
||||
* [fade in](/microbit/reference/led/fade-in)
|
||||
* [fade out](/microbit/reference/led/fade-out)
|
||||
* [plot](/microbit/reference/led/plot)
|
||||
* [plot all](/microbit/reference/led/plot-all)
|
||||
* [point](/microbit/reference/led/point)
|
||||
* [screenshot](/microbit/functions/screenshot)
|
||||
* [set display mode](/microbit/functions/set-display-mode)
|
||||
* [set brightness](/microbit/reference/led/set-brightness)
|
||||
* [stop animation](/microbit/reference/led/stop-animation)
|
||||
* [toggle](/microbit/reference/led/toggle)
|
||||
* [toggle all](/microbit/reference/led/toggle-all)
|
||||
* [unplot](/microbit/reference/led/unplot)
|
||||
|
||||
### Input
|
||||
|
||||
* [acceleration](/microbit/reference/input/acceleration)
|
||||
* [rotation](/microbit/functions/rotation)
|
||||
* [button is pressed](/microbit/reference/input/button-is-pressed)
|
||||
* [compass heading](/microbit/reference/input/compass-heading)
|
||||
* [temperature](/microbit/reference/input/temperature)
|
||||
* [running time](/microbit/reference/input/running-time)
|
||||
* [on shake](/microbit/reference/input/on-gesture)
|
||||
* [on button pressed](/microbit/reference/input/on-button-pressed)
|
||||
* [on logo down](/microbit/functions/on-logo-down)
|
||||
* [on logo up](/microbit/functions/on-logo-up)
|
||||
* [on pin pressed](/microbit/reference/input/on-pin-pressed)
|
||||
* [on screen down](/microbit/functions/on-screen-down)
|
||||
* [on screen up](/microbit/functions/on-screen-up)
|
||||
* [pin is pressed](/microbit/reference/input/pin-is-pressed)
|
||||
|
||||
### Image
|
||||
|
||||
* [create image](/microbit/reference/images/create-image)
|
||||
* [clear](/microbit/reference/basic/clear-screen)
|
||||
* [pixel](/microbit/reference/images/pixel)
|
||||
* [plot frame](/microbit/reference/led/plot-frame)
|
||||
* [plot image](/microbit/reference/led/plot-image)
|
||||
* [scroll image](/microbit/reference/images/scroll-image)
|
||||
* [show frame](/microbit/functions/show-frame)
|
||||
* [set pixel](/microbit/reference/images/set-pixel)
|
||||
* [show image](/microbit/reference/images/show-image)
|
||||
* [width](/microbit/functions/width)
|
||||
|
||||
### Music
|
||||
|
||||
* [play note](/microbit/functions/play-note)
|
||||
* [note](/microbit/functions/note)
|
||||
* [ring](/microbit/reference/music/ring)
|
||||
|
||||
### Pins
|
||||
|
||||
* [digital read pin](/microbit/reference/pins/digital-read-pin)
|
||||
* [digital write pin](/microbit/reference/pins/digital-write-pin)
|
||||
* [analog read pin](/microbit/reference/pins/analog-read-pin)
|
||||
* [analog write pin](/microbit/reference/pins/analog-write-pin)
|
||||
* [analog set period](/microbit/reference/pins/analog-set-period)
|
||||
* [analog pitch](/microbit/reference/pins/analog-pitch)
|
||||
* [analog set pitch pin](/microbit/reference/pins/analog-set-pitch-pin)
|
||||
* [servo write pin](/microbit/reference/pins/servo-write-pin)
|
||||
* [servo set pulse](/microbit/reference/pins/servo-set-pulse)
|
||||
* [map](/microbit/functions/map)
|
||||
|
||||
### Control
|
||||
|
||||
* [in background](/microbit/reference/control/in-background)
|
||||
* [reset](/microbit/functions/reset)
|
||||
|
||||
### Devices
|
||||
|
||||
Functions in this category require to be connected to a remote device.
|
||||
|
||||
* [tell camera to](/microbit/reference/devices/tell-camera-to)
|
||||
* [tell remote control to](/microbit/reference/devices/tell-remote-control-to)
|
||||
* [raise alert to](/microbit/reference/devices/raise-alert-to)
|
||||
* [on notified](/microbit/reference/devices/on-notified)
|
||||
|
||||
### Libraries
|
||||
|
||||
* [game library](/microbit/js/game-library)
|
||||
* [serial library](/microbit/js/serial-library)
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
## Run
|
||||
|
||||
* [scripts in the browser](/microbit/js/simulator)
|
||||
* [scripts on your BBC micro:bit](/microbit/device/usb)
|
||||
|
||||
## Debugging
|
||||
|
||||
* use the [serial library](/microbit/js/serial-library) to print data from your micro:bit on your computer
|
||||
* learn about the [device error codes](/microbit/device/errors) that are displayed when sad faces occur
|
||||
|
||||
## Edit/Publish
|
||||
|
||||
* [the Touch Develop Editor](/microbit/js/editor)
|
||||
* [publish a script](/microbit/js/publishing)
|
||||
|
||||
## Creating Tutorials
|
||||
|
||||
* [create a tutorial](/microbit/js/create-tutorials)
|
||||
* [markdown syntax](/microbit/js/markdown)
|
||||
|
||||
### ~
|
||||
|
112
docs/reference/js/data.md
Normal file
112
docs/reference/js/data.md
Normal file
@ -0,0 +1,112 @@
|
||||
# Global Variables
|
||||
|
||||
How to define and use global variables. #docs #data #language #variables
|
||||
|
||||
### @parent js/language
|
||||
|
||||
A variable is a place where you can store data so that you can use it later in your code. A *global* variable is accessible from every point in your code.
|
||||
|
||||
### Block Editor
|
||||
|
||||
In the Block Editor, all variables are global. See [Block Editor](/microbit/blocks/editor) for info on creating global variables in a Block Editor script. The following block is used to set (assign) global variable's value:
|
||||
|
||||

|
||||
|
||||
The block below retrieves (gets) the current value of a global variable:
|
||||
|
||||

|
||||
|
||||
### Touch Develop
|
||||
|
||||
In Touch Develop variables are either [global](/microbit/js/data) or [local](/microbit/reference/variables/var). Variables have a name, a [type](/microbit/js/types), and value:
|
||||
|
||||
* the *name* is how you'll refer to the variable
|
||||
* the *type* refers to the kind of value a variable can store
|
||||
* the *value* refers to what's stored in the variable
|
||||
|
||||
[Global variables](/microbit/js/data) are variables that are available throughout your script. Unlike [local variables](/microbit/reference/variables/var), global variables are accessible across functions and in nested code blocks.
|
||||
|
||||
### Create a global variable
|
||||
|
||||
To create a new global variable:
|
||||
|
||||
1. In the Touch Develop [editor](/microbit/js/editor), click `script` (to the right of the search box).
|
||||
|
||||
2. Click `+` **add new**.
|
||||
|
||||
3. Click `data->` **data** and then choose a [type](/microbit/js/types).
|
||||
|
||||
4. Enter a name for your global variable and click **OK**.
|
||||
|
||||
### Set and use a global variable
|
||||
|
||||
To use a global variable that you've declared (using steps above):
|
||||
|
||||
1. In the Touch Develop [editor](/microbit/js/editor), click `data-> ` **data** or `data->` + *variable name*.
|
||||
|
||||
2. Click `:=` (assignment).
|
||||
|
||||
2. Click on the right-side of `:=` and type or click what you want to store in the variable.
|
||||
|
||||
Your code should look something like this:
|
||||
|
||||
// global number variable
|
||||
|
||||
```
|
||||
counter = 2
|
||||
```
|
||||
|
||||
// global string variable
|
||||
|
||||
```
|
||||
name2 = "Mike"
|
||||
```
|
||||
|
||||
// global boolean variable
|
||||
|
||||
```
|
||||
bool = true
|
||||
```
|
||||
|
||||
(for info on creating image variables, see [Image](/microbit/reference/image/image))
|
||||
|
||||
Once you've defined a variable and set it's initial value, use the variable's name whenever you need what's stored in the variable. For example, the following code gets the value stored in the global `counter` variable and shows it on the screen:
|
||||
|
||||
```
|
||||
basic.showNumber(counter, 100)
|
||||
```
|
||||
|
||||
To change the contents of a variable use the [assignment operator](/microbit/reference/variables/assign) `:=`. The following code increments `counter` by 10:
|
||||
|
||||
```
|
||||
counter = counter + 10
|
||||
```
|
||||
|
||||
### Promote, demote, and extract
|
||||
|
||||
To **promote** a local variable to a global variable:
|
||||
|
||||
* select the local variable name and click `promote to data`. The [var](/microbit/reference/variables/var) keyword changes to the data symbol `data->`.
|
||||
|
||||
To **demote** a global variable to a local variable:
|
||||
|
||||
* select the global variable name and click `demote to var`
|
||||
|
||||
To **extract** the content of a global variable to a local variable:
|
||||
|
||||
* select the global variable name and click `extract to var`
|
||||
|
||||
### See your global variables
|
||||
|
||||
To see a list of the global variables in your script:
|
||||
|
||||
* click `script` (along the top) and scroll down to the **vars** heading
|
||||
|
||||
### Lessons
|
||||
|
||||
[counter](/microbit/lessons/counter), [rotation animation](/microbit/lessons/rotation-animation), [digital pet](/microbit/lessons/digital-pet), [offset image](/microbit/lessons/offset-image)
|
||||
|
||||
### See also
|
||||
|
||||
[local variables](/microbit/reference/variables/var), [types](/microbit/js/types), [assignment operator](/microbit/reference/variables/assign)
|
||||
|
112
docs/reference/js/editor.md
Normal file
112
docs/reference/js/editor.md
Normal file
@ -0,0 +1,112 @@
|
||||
# Touch Develop Editor
|
||||
|
||||
The Touch Develop editor. #docs #editor #scripts #compile #run #keyboard
|
||||
|
||||
### @parent js/contents
|
||||
|
||||
|
||||
The Touch Develop editor is where you write and test your code. If you're new to Touch Develop, check out the [Touch Develop editor video](/microbit/getting-started/touchdevelop-editor).
|
||||
|
||||
To create a new Touch Develop script:
|
||||
|
||||
1. Go to the micro:bit website and click **Create Code** (along the top).
|
||||
|
||||
2. Under the Touch Develop editor heading, click **New project**.
|
||||
|
||||
3. Type a name for your script and click **create**.
|
||||
|
||||
An empty script with a [function](/microbit/js/function) called `main` is created.
|
||||
|
||||
## The Editor Menu Bar
|
||||
|
||||
The Touch Develop editor has a bar of options above the code area:
|
||||
|
||||

|
||||
|
||||
* `my scripts` takes you back to a list of your scripts (My Scripts). The open script is automatically saved (in the cloud) when you leave the editor.
|
||||
* `run` executes your script, showing you the results on the on-screen micro:bit device. See [run scripts in the browser](/microbit/js/simulator) for more about this.
|
||||
* `compile` sends your script to an ARM compiler, which creates a file that you can run on your micro:bit. See [run scripts on your micro:bit](/microbit/device/usb) for more info.
|
||||
* `undo` undoes changes that you made to your script.
|
||||
* `search code...` search for functions in libraries such as the micro:bit library.
|
||||
* `script` opens script options, where you can do things like publish and preview. See **script options** below.
|
||||
|
||||
Many of the above buttons aren't much use until you've written some code, so let's move on to the Code Keyboard.
|
||||
|
||||
## Code Keyboard
|
||||
|
||||
The Code Keyboard makes it easy to write code on a touch screen device or by using your mouse. You can also type code using your computer keyboard if you know what function or statement you want (see [Touch Develop documentation](/microbit/js/contents) for a complete list).
|
||||
|
||||
To open the Code Keyboard, click on a line of code:
|
||||
|
||||

|
||||
|
||||
An on-screen keyboard appears, with buttons that vary depending on what's selected.
|
||||
|
||||
### Statements
|
||||
|
||||
The first row of the Code Keyboard has Touch Develop [statements](/microbit/js/statements) that you can insert into your code. These buttons are blue and include things like [var](/microbit/reference/variables/var), [if](/microbit/reference/logic/if), [for](/microbit/reference/loops/for) , and [while](/microbit/js/while). Click `more` to see additional statements.
|
||||
|
||||
### The BBC micro:bit, math, and code buttons
|
||||
|
||||
* `micro:bit`: click to see all the [micro:bit functions](/microbit/js/contents); click `more` to scroll left to right. The micro:bit functions are also grouped together behind the following category buttons: `basic`, `control`, `input`, `image`, `led`, and`pins`
|
||||
* `code`: click to access functions you've written (see [call a function](/microbit/js/call) for more info)
|
||||
* `math`: click to see [math functions](/microbit/js/math); such as `abs` and `round`
|
||||
* `bits`: click to see functions for bit-level manipulation of integers
|
||||
|
||||
### Editing code: add, copy, paste, and cut
|
||||
|
||||
In the coding area...
|
||||
|
||||
* **add**: to add a new line, click on a line and then click a **+** to add a new line above or below the current line
|
||||
* **copy, paste, cut**: click on a line then click **copy** or **cut**. Then click on a new line, and click **paste**.
|
||||
|
||||
### Block editing
|
||||
|
||||
To copy, cut, or comment out a block of code (more than one line):
|
||||
|
||||
1. Click on a line of code.
|
||||
|
||||
2. Press and hold the `Shift` key, and then press the `Up arrow` or `Down arrow` key on your keyboard (this selects multiple lines).
|
||||
|
||||
3. Choose a block editing option like copy, cut, or [comment out](/microbit/js/comment).
|
||||
|
||||
### Script options
|
||||
|
||||
Click `script` (in the upper-right corner) to open the script options:
|
||||
|
||||

|
||||
|
||||
Here you'll find options like...
|
||||
|
||||
* `script properties`: the script name, description, and whether or not the script is a library (more info below)
|
||||
* `publish`: share a script with other users by [publishing](/microbit/js/publishing) it
|
||||
* `share`: share a link to a published script (see [publish as script](/microbit/js/publishing) for more info)
|
||||
* `preview`: preview a documentation script
|
||||
* `+` `add new`: add a new [function](/microbit/js/function), [global variable](/microbit/js/data), picture, or library to a script
|
||||
* *code*: the functions in your script; click a function to open it in the editor
|
||||
* *global vars*: the [global variables](/microbit/js/data) in your script; click a variable to go to that variable
|
||||
* *libraries*: the libraries added to your script
|
||||
* *art*: picture and video resources added to your script
|
||||
|
||||
### Script properties
|
||||
|
||||
To edit a script's properties, click `script` (in the upper-right corner), and then click the script name or script properties.
|
||||
|
||||

|
||||
|
||||
* `name`: the script's name (60 character limit)
|
||||
* `description`: a description of what your script does along with #hashtags for search (for example, #game or #maker). Hashtags are especially important if you publish your script (200 character limit).
|
||||
* `this script is a library`: click this check box to turn a script into a library
|
||||
|
||||
### Comments
|
||||
|
||||
Comments are notes within your scripts. To learn how to insert comments into your scripts, see [Comments](/microbit/js/comment). You can format your comments using [markdown syntax](/microbit/js/markdown).
|
||||
|
||||
### Share your scripts
|
||||
|
||||
Share your scripts with other people by publishing them. See [publish a script](/microbit/js/publishing) for more info.
|
||||
|
||||
### See also
|
||||
|
||||
[publish a script](/microbit/js/publishing), [Touch Develop documentation](/microbit/js/contents)
|
||||
|
59
docs/reference/js/event-handler.md
Normal file
59
docs/reference/js/event-handler.md
Normal file
@ -0,0 +1,59 @@
|
||||
# event handler
|
||||
|
||||
Event handlers - how they work. #eventhandler #docs #input #button
|
||||
|
||||
An event handler is code that is associated with a particular event, such as "button A pressed". You create (or register) the association between an event and an event handler by calling a function named "on <event>". After registering an event handler with an event, then whenever that event occurs, the event handler code executes.
|
||||
|
||||
### Registering an event handler
|
||||
|
||||
Functions named "on <event>" create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A:
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
```
|
||||
|
||||
After this code executes, then whenever button A is pressed in the future, the string "hello" will be printed.
|
||||
|
||||
### Event handlers are active for the entire program execution
|
||||
|
||||
Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute:
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
})
|
||||
```
|
||||
|
||||
The above code associated an event handler that does nothing with the event of a press of button A.
|
||||
|
||||
### There is only one event handler per event
|
||||
|
||||
The above example also illustrates that there is only one event handler for each event. What is the result of the following code?
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
```
|
||||
|
||||
The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this:
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("hello", 150)
|
||||
basic.showString("goodbye", 150)
|
||||
})
|
||||
```
|
||||
|
||||
### To learn more
|
||||
|
||||
To learn more about how the BBC micro:bit queues up and schedules event handlers, see [the BBC micro:bit - a reactive system](/microbit/device/reactive)
|
||||
|
||||
### see also
|
||||
|
||||
[on button pressed](/microbit/reference/input/on-button-pressed), [on logo up](/microbit/functions/on-logo-up), [on logo down](/microbit/functions/on-logo-down), [on screen up](/microbit/functions/on-screen-up), [on screen down](/microbit/functions/on-screen-down), [on shake](/microbit/reference/input/on-gesture), [on pin pressed](/microbit/reference/input/on-pin-pressed)
|
||||
|
81
docs/reference/js/events.md
Normal file
81
docs/reference/js/events.md
Normal file
@ -0,0 +1,81 @@
|
||||
# Events Library
|
||||
|
||||
The events library #docs
|
||||
|
||||
The functions in the events namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. The events accessible from Touch Develop are listed below.
|
||||
|
||||
### Remote control
|
||||
|
||||
Control the presentation of media content available on a remote device using the `remote control` function
|
||||
|
||||
```
|
||||
export function remoteControl(event: string)
|
||||
```
|
||||
|
||||
The remote control specific events include:
|
||||
|
||||
* play
|
||||
* pause
|
||||
* stop
|
||||
* next track
|
||||
* previous track
|
||||
* forward
|
||||
* rewind
|
||||
* volume up
|
||||
* volume down
|
||||
|
||||
### Camera
|
||||
|
||||
Access the photo/video-taking functionality of a remote device using the *camera* function:
|
||||
|
||||
```
|
||||
export function camera(event: string)
|
||||
```
|
||||
|
||||
The camera-specific events include:
|
||||
|
||||
* toggle front-rear
|
||||
* launch photo mode
|
||||
* take photo
|
||||
* stop photo mode
|
||||
* launch video mode
|
||||
* start video capture
|
||||
* stop video capture
|
||||
* stop video mode
|
||||
|
||||
### Alert
|
||||
|
||||
Raise an alert on a remote device using the `alert` function
|
||||
|
||||
```
|
||||
export function alert(event: string)
|
||||
```
|
||||
|
||||
The set of alerting-specific events include:
|
||||
|
||||
* display toast
|
||||
* vibrate
|
||||
* play sound
|
||||
* play ringtone
|
||||
* find my phone
|
||||
* alarm 1
|
||||
* alarm 2
|
||||
* alarm 3
|
||||
* alarm 4
|
||||
* alarm 5
|
||||
* alarm 6
|
||||
|
||||
### Audio recorder
|
||||
|
||||
Access the audio recording capabilities of the device using the `audio recording` function
|
||||
|
||||
```
|
||||
export function audioRecorder(event: string)
|
||||
```
|
||||
|
||||
The set of audio recorder events include:
|
||||
|
||||
* launch
|
||||
* start capture
|
||||
* end capture
|
||||
* stop
|
83
docs/reference/js/for.md
Normal file
83
docs/reference/js/for.md
Normal file
@ -0,0 +1,83 @@
|
||||
# For
|
||||
|
||||
Repeat code a preset number of times. #docs #for #endfor #language
|
||||
|
||||
### @parent js/language
|
||||
|
||||
|
||||
Repeat code a fixed number of times.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times:
|
||||
|
||||
```
|
||||
for (let k = 0; k < 4; k++) {
|
||||
}
|
||||
```
|
||||
|
||||
### Touch Develop
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
let upper = 5
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
for (let k1 = 0; k1 < upper; k1++) {
|
||||
// Add code to repeat here, also called the `loop body`
|
||||
}
|
||||
```
|
||||
|
||||
where
|
||||
|
||||
* `0` is initial value of the loop index variable `k`
|
||||
* the value of `k` increases by 1 after each execution of the `loop body`
|
||||
* `upper` is the number of times the loop body will repeat
|
||||
|
||||
In other words, the index variable (`k`) starts at 0 and increases by 1 each time the `loop body` executes, until `k = upper`.
|
||||
|
||||
### Example: count to 5
|
||||
|
||||
The following example displays numbers 1 through 5 on the LED screen:
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
basic.showNumber(i + 1, 100)
|
||||
basic.pause(500)
|
||||
}
|
||||
```
|
||||
|
||||
### Example: draw a box
|
||||
|
||||
The [LED screen](/microbit/device/screen) has a fixed number of rows and columns (5x5), which is ideal for a for loop. This example uses a for loop to turn on the LEDs along the edge of the screen, making a square.
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 5; i1++) {
|
||||
led.plot(0, i1)
|
||||
led.plot(4, i1)
|
||||
led.plot(i1, 0)
|
||||
led.plot(i1, 4)
|
||||
basic.pause(500)
|
||||
}
|
||||
```
|
||||
|
||||
### ~hint
|
||||
|
||||
Want to exit a loop early? The [break](/microbit/js/break) statement exits a loop before the end value is reached.
|
||||
|
||||
### ~
|
||||
|
||||
### Lessons
|
||||
|
||||
[looper](/microbit/lessons/looper), [strobe light](/microbit/lessons/strobe-light)
|
||||
|
||||
### See also
|
||||
|
||||
[while](/microbit/js/while), [break](/microbit/js/break), [if](/microbit/reference/logic/if)
|
||||
|
117
docs/reference/js/function.md
Normal file
117
docs/reference/js/function.md
Normal file
@ -0,0 +1,117 @@
|
||||
# Create a Function
|
||||
|
||||
How to define a function with input and output parameters. #docs #function #language
|
||||
|
||||
### @parent js/language
|
||||
|
||||
|
||||
A function is a unit of code that performs a specific task and returns a result.
|
||||
|
||||
Functions are ideal when you need to perform an action multiple times. Instead of repeating a block of code in your script, you can put the code in a function and simply [call the function](/microbit/js/call) when needed.
|
||||
|
||||
*Why use functions?* Functions makes your code easier to read, debug, and update.
|
||||
|
||||
### Add a function
|
||||
|
||||
To add a function to a Touch Develop script:
|
||||
|
||||
1. Open a script and then click `script` (in the upper-right corner).
|
||||
|
||||
2. Click `+` **add new**.
|
||||
|
||||
3. Click **function()**.
|
||||
|
||||
A new function appears, like this:
|
||||
|
||||
```
|
||||
export function doStuff(p: number) {
|
||||
}
|
||||
```
|
||||
|
||||
Functions begin with the `function` keyword and end with `end function`. The function name appears after the `function` keyword (in this case, `do stuff`).
|
||||
|
||||
### ~hint
|
||||
|
||||
Click the function name to edit the function properties (i.e. change the name or add parameters - see below).
|
||||
|
||||
### ~
|
||||
|
||||
### Function components
|
||||
|
||||
Functions have three parts:
|
||||
|
||||
* [input and output parameters](/microbit/js/functionparameters)
|
||||
* the function *body* (the code that performs a task)
|
||||
|
||||
- one or more [return](/microbit/js/return) statements (the output of the function)
|
||||
|
||||
#### Example function
|
||||
|
||||
```
|
||||
/**
|
||||
* // returns the square of the input parameter x
|
||||
* @param x TODO
|
||||
*/
|
||||
export function square(x: number) : number {
|
||||
let result: number
|
||||
return x * x
|
||||
return result
|
||||
}
|
||||
```
|
||||
|
||||
In the above code...
|
||||
|
||||
* ``x `` is the [input parameter](/microbit/js/functionparameters) ([Number](/microbit/reference/types/number) type)
|
||||
* ``result`` is the [output parameter](/microbit/js/functionparameters) ([Number](/microbit/reference/types/number) type)
|
||||
* `return x * x` is the function body (which returns the value of the expression `x * x`)
|
||||
|
||||
### Add function parameters
|
||||
|
||||
1. Open your function (if needed). To do this, open your script and then click `script` (in the upper-right corner).
|
||||
|
||||
2. Under **code** click your function name.
|
||||
|
||||
3. Click the function name in the code window. This opens the function panel.
|
||||
|
||||
4. Click **add input parameter** or **add output parameter**. The parameter is added to your function.
|
||||
|
||||
Click the parameter name to rename it and click the [type](/microbit/js/types) to change the variable type. For more info, see [function parameters](/microbit/js/functionparameters).
|
||||
|
||||
### ~hide
|
||||
|
||||
### Extract code into a function
|
||||
|
||||
If you've already written some code that you'd like to have in a function, you can extract the code. Here's how:
|
||||
|
||||
1. Click the first line of code that you want to extract.
|
||||
|
||||
2. Press and hold the Shift key, and then press the Down arrow on your keyboard to select multiple lines of code.
|
||||
|
||||
3. In the block editing window, scroll down to **extract selection into function** and click `extract`.
|
||||
|
||||
### ~
|
||||
|
||||
### Function documentation
|
||||
|
||||
Use a [comment](/microbit/js/comment) at the beginning of your functions to describe the function. When you insert a function into your code, the comment text appears in the help area of the Code Keyboard.
|
||||
|
||||
### See all your functions
|
||||
|
||||
To see all the functions in a script, open the script and then click `script` (in the upper-right corner). All of the functions in your script appear under **code**.
|
||||
|
||||
### ~hide
|
||||
|
||||
### Private functions
|
||||
|
||||
If you don't want people to see the code in your function, you can make the function private. To do this, open the function, click the function name, and then mark the **private function** check box. Private functions have a locked icon instead of a play icon.
|
||||
|
||||
### ~
|
||||
|
||||
### Lessons
|
||||
|
||||
[digital pet](/microbit/lessons/digital-pet)
|
||||
|
||||
### See also
|
||||
|
||||
[function parameters](/microbit/js/functionparameters), [call a function](/microbit/js/call), [return from a function](/microbit/js/return)
|
||||
|
66
docs/reference/js/functionparameters.md
Normal file
66
docs/reference/js/functionparameters.md
Normal file
@ -0,0 +1,66 @@
|
||||
# Function Parameters
|
||||
|
||||
How to use parameters to pass info in and out of an function. #docs #input #output #function #functionparameters
|
||||
|
||||
### @parent js/function
|
||||
|
||||
|
||||
A [function](/microbit/js/function) can have multiple input parameters and/or a single output parameter. The parameters must be one of the supported variable [types](/microbit/js/types).
|
||||
|
||||
When you first [create a function](/microbit/js/function), it looks like this:
|
||||
```
|
||||
export function doStuff() {
|
||||
}
|
||||
```
|
||||
|
||||
### Add a function parameter
|
||||
|
||||
1. Open your script (if needed) and then click `script` in the upper-right corner.
|
||||
|
||||
2. Under **code** click your function name.
|
||||
|
||||
3. Click the function name in your code (this opens the function panel).
|
||||
|
||||
4. Click **add input parameter** or **add output parameter**. The parameter is added to your function.
|
||||
|
||||
#### Input parameters
|
||||
|
||||
The default type for an input parameter is [Number](/microbit/reference/types/number):
|
||||
|
||||
```
|
||||
export function oneInput(p: number) {
|
||||
}
|
||||
```
|
||||
|
||||
To change the default type, click the type ([Number](/microbit/reference/types/number) in this case) and change it to [String](/microbit/reference/types/string), [Boolean](/microbit/reference/types/boolean), or [Image](/microbit/reference/image/image). You can add multiple input parameters to a function.
|
||||
|
||||
#### Output parameter
|
||||
|
||||
the default type for an output parameter is [Number](/microbit/reference/types/number):
|
||||
|
||||
```
|
||||
export function output() : number {
|
||||
let r: number
|
||||
return 42
|
||||
return r
|
||||
}
|
||||
```
|
||||
|
||||
To change the default type, click the type ([Number](/microbit/reference/types/number) in this case) and change it to [String](/microbit/reference/types/string), [Boolean](/microbit/reference/types/boolean), or [Image](/microbit/reference/image/image).
|
||||
|
||||
### Inputs and output function
|
||||
|
||||
The following sample function has two inputs and one output parameter (all are the Number type):
|
||||
|
||||
```
|
||||
export function inputsAndOutput(p: number, q: number) : number {
|
||||
let r: number
|
||||
return p + q
|
||||
return r
|
||||
}
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[call a function](/microbit/js/call), [create a function](/microbit/js/function), [return](/microbit/js/return)
|
||||
|
106
docs/reference/js/gallery.md
Normal file
106
docs/reference/js/gallery.md
Normal file
@ -0,0 +1,106 @@
|
||||
# Gallery
|
||||
|
||||
Overview of Touch Develop lessons for the BBC micro:bit. #docs #contents
|
||||
|
||||
### @short Gallery
|
||||
|
||||
### ~column
|
||||
|
||||
|
||||
## Maker
|
||||
|
||||
* [Telegraph](/microbit/pzeagwoudd), play the telegraph game between 2 BBC micro:bits
|
||||
* [Ornament Chain](/microbit/rnvpgo), play the ornament chain game between 2 BBC micro:bits
|
||||
|
||||
### ~hide
|
||||
|
||||
* [The Watch](/microbit/lessons/the-watch), design and create The Watch
|
||||
* [Hack your headphones](/microbit/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones
|
||||
* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits
|
||||
|
||||
### ~
|
||||
|
||||
## Beginner
|
||||
|
||||
* [Night light](/microbit/vltwrzuqto), dim the LEDs with set brightness
|
||||
* [Beautiful image](/microbit/nudwzmphyx), show a beautiful image with show LEDs
|
||||
* [Smiley,](/microbit/zsohipimef) smiley and frowney with show animation
|
||||
* [Lucky 7](/microbit/rqhxxqppqu), show a number on the LED screen with show number
|
||||
* [Answering machine](/microbit/bnkmeqymuh), show a text message with show string
|
||||
* [Snowflake fall](/microbit/zhcfmiejlg), repeat an animation with forever
|
||||
* [Screen wipe](/microbit/hlnitnqjjk), turn off the LEDs with clear screen
|
||||
* [Flashing heart](/microbit/bwmxfwqswx), display images with a pause
|
||||
* [Blink](/microbit/jbbutifslm), turn an LED on and off with plot
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Bounce image](/microbit/lessons/bounce-image), scroll an image across the screen on shake
|
||||
* [Magic logo](/microbit/lessons/magic-logo), show an image on logo up
|
||||
* [Glowing sword](/microbit/lessons/glowing-sword), make a glowing sword with fade in and fade out
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
## Intermediate
|
||||
|
||||
* [Zoomer](/microbit/fwrohhjqql), measure the force with acceleration
|
||||
* [Strobe light](/microbit/jguqlzeayr), develop shapes with a nested for loops
|
||||
* [Digi yoyo](/microbit/lppocrbpys), create a counter with a while loop
|
||||
* [Die roll](/microbit/lzblatmknq), spin with more if statements
|
||||
* [Spinner](/microbit/dzijduruek), spin the arrow with multiple if statements
|
||||
* [Truth or dare](/microbit/filuzbwauo), a game that forces each player to reveal a secret or do something funny with if statement
|
||||
* [Love meter](/microbit/rrmlrvojfa), create a love meter with on pin pressed
|
||||
* [Guess the number](/microbit/ftsenbvqwz), guess a random number with random
|
||||
* [Magic 8](/microbit/fyjinpjuqu), a fortune teller game with the BBC micro:bit
|
||||
* [Counter](/microbit/rerlmjgjut), display a number with a variable
|
||||
* [Glowing pendulum](/microbit/xrnsveuwxj), construct a pendulum that glows using acceleration
|
||||
* [Looper](/microbit/nxcddtbizi), display a series of numbers with a for loop index
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Rotation animation](/microbit/lessons/rotation-animation), control an animation with a boolean variable
|
||||
* [Offset image](/microbit/lessons/offset-image), shift an image horizontally with image offset
|
||||
* [Compass](/microbit/lessons/compass), displays the direction the BBC micro:bit is pointing
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
## Advanced
|
||||
|
||||
* [Rock paper scissors](/microbit/tnmtbvyyma), use image offsets with local variables
|
||||
* [Digital pet](/microbit/vefocoajpb), a display of pet images with sub-functions
|
||||
* [Catch the egg](/microbit/reczlreqob), catch falling eggs in a basket with an acceleration controller
|
||||
* [Headbands](/microbit/bzrusu), create a charades game with a collection of strings that hold the words
|
||||
* [Prank WiFi](/microbit/dceikq), create fake WiFi to trick your friends
|
||||
* [Flipping bird](/microbit/lbhvywjzkv), use modulo with a conditional
|
||||
* [Runaway pac man](/microbit/loafab), construct the game pac man with the BBC micro:bit
|
||||
* [Line of Fire](/microbit/fzcoly), make a game to test hand-eye coordination
|
||||
* [The hat game](/microbit/njynsd), make a game to test your focus on the moving ball
|
||||
* [Pong](/microbit/xcenyy), a light bouncing from left to right
|
||||
* [Meteorite](/microbit/zaidka), a game where meteorites are coming for you one by one
|
||||
* [Minesweeper](/microbit/jaeeve), make a game to test your memory for placing a LED mine then finding the hidden LED mine
|
||||
* [Bop it](/microbit/zlpndm), a game where you have to keep up with the commands
|
||||
* [Letter Up](/microbit/ftlqjo), a guessing game with string operators with string at
|
||||
* [Racing Buttons](/microbit/hcuxid), racing game to determine if player 1 presses Button A faster or if player 2 presses Button B faster
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Transformers](/microbit/lessons/transformers), use functions to return values
|
||||
* [Speed button](/microbit/lessons/speed-button), code a speed game with running time
|
||||
* [Jailbreak](/microbit/lessons/jailbreak), break out of a counting loop by pressing button "A"
|
||||
* [2 player pong](/microbit/bzycll), collaborate with a classmate to develop Pong on multiple BBC micro:bits
|
||||
|
||||
### ~
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Number psych](/microbit/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple BBC micro:bits and a breadboard
|
||||
|
||||
### ~
|
||||
|
||||
### @section full
|
||||
|
||||
The lessons promote computational thinking and computer science literacy[ read more...](/microbit/lessons/teach)
|
||||
|
155
docs/reference/js/game-library.md
Normal file
155
docs/reference/js/game-library.md
Normal file
@ -0,0 +1,155 @@
|
||||
# Game Library
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The player has a number of **lives** and a **score**. The game has a number of **levels** and a **countdown clock**. The general goal of a game will be to achieve a top score before time runs out or the number of lives goes to zero.
|
||||
|
||||
## Touch Develop
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
```
|
||||
|
||||
### [Countdown](/microbit/js/game-library/start-countdown)
|
||||
|
||||
If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time.
|
||||
|
||||
* start a countdown with the maximum duration of the game in milliseconds.
|
||||
|
||||
```
|
||||
export function startCountdown(ms: number)
|
||||
```
|
||||
|
||||
### [Game over](/microbit/js/game-library/game-over)
|
||||
|
||||
If the `life` reaches zero or the time expires (see countdown), the game enters the **game over** mode. When the game is over, `game->is running` returns false
|
||||
|
||||
* check if the game still running.
|
||||
|
||||
```
|
||||
export function isRunning() : boolean
|
||||
```
|
||||
|
||||
Indicates if the game is display the game over sequence.
|
||||
|
||||
```
|
||||
export function isGameOver() : boolean
|
||||
```
|
||||
|
||||
You can also end the game by calling the `game -> game over` function:
|
||||
|
||||
```
|
||||
export function gameOver()
|
||||
```
|
||||
|
||||
### Score
|
||||
|
||||
When a player achieves a goal, you can increase the game score
|
||||
|
||||
[Add Point to Score](/microbit/js/game-library/add-point-to-score)
|
||||
|
||||
* add score points to the current score
|
||||
|
||||
```
|
||||
export function addScore(points: number)
|
||||
```
|
||||
|
||||
[Score](/microbit/js/game-library/score)
|
||||
|
||||
* set the current score to a particular value.
|
||||
|
||||
```
|
||||
export function setScore(value: number)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### Life
|
||||
|
||||
Manage the player lives. When the life count reaches 0 or less, the game is over.
|
||||
|
||||
* remove one or more lives
|
||||
|
||||
```
|
||||
export function removeLife(life: number)
|
||||
```
|
||||
|
||||
* add lives
|
||||
|
||||
```
|
||||
export function addLife(lives: number)
|
||||
```
|
||||
|
||||
* set the life to a particular value
|
||||
|
||||
```
|
||||
export function setLife(value: number)
|
||||
```
|
||||
|
||||
* get the current life value
|
||||
|
||||
```
|
||||
export function life() : number
|
||||
```
|
||||
|
||||
### Levels
|
||||
|
||||
When the game increases in difficulty, you can increase the level and use that value in your game logic.
|
||||
|
||||
* increase the level by 1
|
||||
|
||||
```
|
||||
export function levelUp()
|
||||
```
|
||||
|
||||
* get the current level
|
||||
|
||||
```
|
||||
export function level() : number
|
||||
```
|
||||
|
||||
### Time
|
||||
|
||||
The game immediately starts tracking the time from the moment the device started.
|
||||
|
||||
* get the current time
|
||||
|
||||
```
|
||||
export function currentTime() : number
|
||||
```
|
||||
|
||||
You can start the time again by using `game->start stopwatch`.
|
||||
|
||||
* start the game timer
|
||||
|
||||
```
|
||||
game.startStopwatch()
|
||||
```
|
||||
|
||||
### Blink
|
||||
|
||||
Reports the blink duration of a `sprite` .
|
||||
|
||||
```
|
||||
export function blink(_this: micro_bitSprites.LedSprite) : number
|
||||
```
|
||||
|
||||
Sets the blink duration interval in milliseconds .
|
||||
|
||||
```
|
||||
export function setBlink(sprite: micro_bitSprites.LedSprite, ms: number)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
43
docs/reference/js/game-library/add-point-to-score.md
Normal file
43
docs/reference/js/game-library/add-point-to-score.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Add Points to Score
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The player will ** add points to score**.
|
||||
|
||||
## Block Editor
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen.
|
||||
|
||||

|
||||
|
||||
## Touch Develop
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
```
|
||||
|
||||
### Score
|
||||
|
||||
When a player achieves a goal, you can increase the game score
|
||||
|
||||
* add score points to the current score
|
||||
|
||||
```
|
||||
export function addScore(points: number)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
43
docs/reference/js/game-library/change-score-by.md
Normal file
43
docs/reference/js/game-library/change-score-by.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Change Score By
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The player will ** add points to score**.
|
||||
|
||||
## Block Editor
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen.
|
||||
|
||||

|
||||
|
||||
## Touch Develop
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
```
|
||||
|
||||
### Score
|
||||
|
||||
When a player achieves a goal, you can increase the game score
|
||||
|
||||
* add score points to the current score
|
||||
|
||||
```
|
||||
export function addScore(points: number)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
24
docs/reference/js/game-library/game-over.md
Normal file
24
docs/reference/js/game-library/game-over.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Game Over
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The game can end the game by calling the `game over` function
|
||||
|
||||
## Block Editor
|
||||
|
||||
You can end the game by calling the `game over ` function. In this example, if BBC micro:bit's answer to the question is GAME OVER, GAME OVER will be displayed to end the game.
|
||||
|
||||

|
||||
|
||||
## Touch Develop
|
||||
|
||||
You can end the game by calling the `game -> game over` function:
|
||||
|
||||
```
|
||||
game.gameOver()
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[game of chance](/microbit/lessons/game-of-chance)
|
||||
|
59
docs/reference/js/game-library/score.md
Normal file
59
docs/reference/js/game-library/score.md
Normal file
@ -0,0 +1,59 @@
|
||||
# Score
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player games. The player has a **score**.
|
||||
|
||||
## Block Editor
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` and adds 1 point to score that will be displayed on the BBC micro:bit screen
|
||||
|
||||

|
||||
|
||||
## Touch Develop
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
```
|
||||
|
||||
### Score
|
||||
|
||||
When a player achieves a goal, you can increase the game score
|
||||
|
||||
* add score points to the current score
|
||||
|
||||
```
|
||||
export function addScore(points: number)
|
||||
```
|
||||
|
||||
* set the current score to a particular value.
|
||||
|
||||
```
|
||||
export function setScore(value: number)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### Countdown
|
||||
|
||||
If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time.
|
||||
|
||||
* start a countdown with the maximum duration of the game in milliseconds.
|
||||
|
||||
```
|
||||
export function startCountdown(ms: number)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
57
docs/reference/js/game-library/start-countdown.md
Normal file
57
docs/reference/js/game-library/start-countdown.md
Normal file
@ -0,0 +1,57 @@
|
||||
# Start Countdown
|
||||
|
||||
The game library #docs
|
||||
|
||||
The game library supports simple single-player time-based games. The general goal of a game will be to achieve a top score before time runs out of time.
|
||||
|
||||
## Block Editor
|
||||
|
||||

|
||||
|
||||
## Touch Develop
|
||||
|
||||
The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
game.addScore(1)
|
||||
})
|
||||
game.startCountdown(10000)
|
||||
```
|
||||
|
||||
### Score
|
||||
|
||||
When a player achieves a goal, you can increase the game score
|
||||
|
||||
* add score points to the current score
|
||||
|
||||
```
|
||||
export function addScore(points: number)
|
||||
```
|
||||
|
||||
* set the current score to a particular value.
|
||||
|
||||
```
|
||||
export function setScore(value: number)
|
||||
```
|
||||
|
||||
* get the current score value
|
||||
|
||||
```
|
||||
export function score() : number
|
||||
```
|
||||
|
||||
### Countdown
|
||||
|
||||
If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time.
|
||||
|
||||
* start a countdown with the maximum duration of the game in milliseconds.
|
||||
|
||||
```
|
||||
export function startCountdown(ms: number)
|
||||
```
|
||||
|
||||
### Lessons
|
||||
|
||||
[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter)
|
||||
|
11
docs/reference/js/game.md
Normal file
11
docs/reference/js/game.md
Normal file
@ -0,0 +1,11 @@
|
||||
# game
|
||||
|
||||
A #microbit game library.
|
||||
|
||||
Gets the current score
|
||||
|
||||
```
|
||||
init()
|
||||
return _score
|
||||
```
|
||||
|
89
docs/reference/js/games.md
Normal file
89
docs/reference/js/games.md
Normal file
@ -0,0 +1,89 @@
|
||||
# Game Tutorials
|
||||
|
||||
Overview of Games for the BBC micro:bit. #docs #contents
|
||||
|
||||
### @short Games
|
||||
|
||||
### ~column
|
||||
|
||||
## Beginner Games
|
||||
|
||||
* [The Watch](/microbit/lessons/the-watch/activity), design and create The Watch
|
||||
* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Smiley,](/microbit/lessons/smiley) smiley and frowney with show animation
|
||||
* [Lucky 7](/microbit/lessons/lucky-7), show a number on the LED screen with show number
|
||||
* [Snowflake fall](/microbit/lessons/snowflake-fall), repeat an animation with forever
|
||||
* [Answering machine](/microbit/lessons/answering-machine), show a text message with show string
|
||||
* [Bounce image](/microbit/lessons/bounce-image), scroll an image across the screen on shake
|
||||
* [Magic logo](/microbit/lessons/magic-logo), show an image on logo up
|
||||
* [Screen wipe](/microbit/lessons/screen-wipe), turn off the LEDs with clear screen
|
||||
* [Blink](/microbit/lessons/blink), turn an LED on and off with plot
|
||||
* [Flashing heart](/microbit/lessons/flashing-heart/tutorial), display images with a pause
|
||||
|
||||
### ~
|
||||
|
||||
* [Night light](/microbit/lessons/night-light/tutorial), dim the LEDs with set brightness
|
||||
* [Glowing sword](/microbit/lessons/glowing-sword/tutorial), make a glowing sword with fade in and fade out
|
||||
* [Guess the number](/microbit/lessons/guess-the-number/tutorial), guess a random number with random
|
||||
* [Rock paper scissors](/microbit/lessons/rock-paper-scissors/tutorial), use image offsets with local variables
|
||||
* [Counter](/microbit/lessons/counter/tutorial), display a number with a variable
|
||||
* [Love meter](/microbit/lessons/love-meter/tutorial), create a love meter with on pin pressed
|
||||
|
||||
### ~column
|
||||
|
||||
## Intermediate Games
|
||||
|
||||
* [Truth or dare](/microbit/lessons/truth-or-dare/tutorial), a game that forces each player to reveal a secret or do something funny with if statement
|
||||
* [Spinner](/microbit/lessons/spinner/tutorial), spin the arrow with multiple if statements
|
||||
* [Die roll](/microbit/lessons/die-roll/tutorial), spin with more if statements
|
||||
* [Looper](/microbit/lessons/looper/tutorial), display a series of numbers with a for loop index
|
||||
* [Strobe light](/microbit/lessons/strobe-light/tutorial), develop shapes with a nested for loops
|
||||
* [Digi yoyo](/microbit/lessons/digi-yoyo/tutorial), create a counter with a while loop
|
||||
* [Magic 8](/microbit/lessons/magic-8/tutorial), a fortune teller game with the BBC micro:bit
|
||||
* [Compass](/microbit/lessons/compass/tutorial), displays the direction the BBC micro:bit is pointing
|
||||
* [Speed button](/microbit/lessons/speed-button/tutorial), code a speed game with running time
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Zoomer](/microbit/lessons/zoomer/tutorial), measure the force with acceleration
|
||||
* [Rotation animation](/microbit/lessons/rotation-animation/tutorial), control an animation with a boolean variable
|
||||
* [Offset image](/microbit/lessons/offset-image/tutorial), shift an image horizontally with image offset
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
## Advanced Games
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Digital pet](/microbit/lessons/digital-pet/tutorial), a display of pet images with sub-functions
|
||||
* [Jailbreak](/microbit/lessons/jailbreak/tutorial), break out of a counting loop by pressing button "A"
|
||||
* [Transformers](/microbit/lessons/transformers/tutorial), use functions to return values
|
||||
* [Flipping bird](/microbit/lessons/flipping-bird/tutorial), use modulo with a conditional
|
||||
|
||||
### ~
|
||||
|
||||
* [Catch the egg](/microbit/lessons/catch-the-egg-game/tutorial), catch falling eggs in a basket with an acceleration controller
|
||||
* [Headbands](/microbit/lessons/headbands/tutorial), create a charades game with a collection of strings that hold the words
|
||||
* [Pong](/microbit/lessons/pong/tutorial), a light bouncing from left to right
|
||||
* [Meteorite](/microbit/lessons/meteorite/tutorial), a game where meteorites are coming for you one by one
|
||||
* [Minesweeper](/microbit/lessons/minesweeper/tutorial), make a game to test your memory for placing a LED mine then finding the hidden LED mine
|
||||
* [Bop it](/microbit/lessons/bop-it/tutorial), a game where you have to keep up with the commands
|
||||
* [Letter Up](/microbit/lessons/letter-up/tutorial), a guessing game with string operators with string at
|
||||
* [Prank WiFi](/microbit/lessons/prank-wifi/tutorial), create fake WiFi to trick your friends
|
||||
* [Runaway pac man](/microbit/lessons/runaway-pacman/tutorial), construct the game pac man with the BBC micro:bit
|
||||
* [The hat game](/microbit/lessons/the-hat-game/tutorial), make a game to test your focus on the moving ball
|
||||
* [2 player pong](/microbit/lessons/2-player-pong/tutorial), collaborate with a classmate to develop Pong on multiple BBC micro:bits
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Glowing pendulum](/microbit/lessons/glowing-pendulum/tutorial), construct a pendulum that glows using acceleration
|
||||
* [Line of Fire](/microbit/lessons/line-of-fire/tutorial), make a game to test hand-eye coordination
|
||||
* [Number psych](/microbit/lessons/number-psych/tutorial), collaborate with multiple classmates to develop a game on multiple BBC micro:bits and a breadboard
|
||||
|
||||
### ~
|
||||
|
86
docs/reference/js/guides/basic-led-show.md
Normal file
86
docs/reference/js/guides/basic-led-show.md
Normal file
@ -0,0 +1,86 @@
|
||||
# basic LED show
|
||||
|
||||
#tutorial #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
You have successfully following the [guided tutorial] (https://live.microbit.co.uk/td/tutorials/blink). If not, we should make sure the micro:bit script displays a blinking script on screen. We want to plot the x and y coordinates to 2, 2. Additionally, you will pause by 100 milliseconds then you will clear the screen of the micro:bit. Let's give it a go!
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led.plot(2, 2)
|
||||
basic.pause(200)
|
||||
basic.clearScreen()
|
||||
basic.pause(200)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Use `basic->show string` to display text after the blink. You will be writing a series of letters to display a series of letters. Try to unravel this secret code word: HELP. This line of code is within the while scope
|
||||
|
||||
Make sure to add this line of code within the `while` scope!
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led1.plot(2, 2)
|
||||
basic1.pause(200)
|
||||
basic1.clearScreen()
|
||||
basic1.pause(200)
|
||||
basic1.showString("HELP", 150) // ***
|
||||
}
|
||||
```
|
||||
|
||||
* run the code and see that it works as expected
|
||||
|
||||
### Challenge 2
|
||||
|
||||
You can also display a number on screen using `basic‐>show number`. Add code under `basic‐>show string` to display the emergency number to call in the United Kingdom. (NOTE: 999 is the historic emergency number for the United Kingdom. All calls are answered by 999 operators. Calls are always free.)
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led2.plot(2, 2)
|
||||
basic2.pause(200)
|
||||
basic2.clearScreen()
|
||||
basic2.pause(200)
|
||||
basic2.showString("HELP", 150)
|
||||
basic2.showNumber(999, 150) // ***
|
||||
}
|
||||
```
|
||||
|
||||
Awesome! You have designed your message and a number to call in case of an emergency.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
* tap the `run` button to view the updated script on the simulator
|
||||
|
||||
Add an associated animation after the emergency number . You can also create a cool animation on screen using `basic->show animation`. Add code under `basic->show number` to display an animation.
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led3.plot(2, 2)
|
||||
basic3.pause(200)
|
||||
basic3.clearScreen()
|
||||
basic3.pause(200)
|
||||
basic3.showString("HELP", 150)
|
||||
basic3.showNumber(999, 150)
|
||||
basic3.showAnimation(`
|
||||
# # . # #
|
||||
. # . # .
|
||||
. . # . .
|
||||
# . . . #
|
||||
# # # # #
|
||||
`, 400) // ***
|
||||
}
|
||||
```
|
||||
|
||||
Awesome! We have implemented a string, number, and animation
|
||||
|
||||
* run the code and see that it works as expected.
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Use the same logic `basic->string`, `basic->number`, or `basic->animation` to turn on the LEDs and display information!!!
|
||||
|
||||
* run the code and see that it works as expected
|
111
docs/reference/js/guides/blink-symbols.md
Normal file
111
docs/reference/js/guides/blink-symbols.md
Normal file
@ -0,0 +1,111 @@
|
||||
# blink symbols
|
||||
|
||||
#tutorial #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
You have successfully following the [blink tutorial](/microbit/hcwxud). If not, then let's start the tutorial now. Your micro:bit script should start by displaying a blinking script on screen. We want to plot the x and y coordinates to 2, 2. Additionally, you will pause by 100 milliseconds then clear the screen of the micro:bit.
|
||||
|
||||
Let's give it a go!
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led.plot(2, 2)
|
||||
basic.pause(200)
|
||||
basic.clearScreen()
|
||||
basic.pause(200)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Make a `>` greater than symbol. Start in the upper left corner of the simulator when you plot coordinates. Make sure to add the line of code `led->plot (0,0)` under the last line of code
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led1.plot(2, 2)
|
||||
basic1.pause(200)
|
||||
basic1.clearScreen()
|
||||
basic1.pause(200)
|
||||
led1.plot(0, 0) // ***
|
||||
}
|
||||
```
|
||||
|
||||
Design the top half of the `>` symbol by connecting a LED to the original center coordinate `2,2` and the upper left coordinate `0,0` Make sure to add the line of code `led->plot (1,1)` under the last line of code
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led2.plot(2, 2)
|
||||
basic2.pause(200)
|
||||
basic2.clearScreen()
|
||||
basic2.pause(200)
|
||||
led2.plot(0, 0)
|
||||
led2.plot(1, 1) // ***
|
||||
}
|
||||
```
|
||||
|
||||
Awesome! You have designed half of the `>` symbol. Now we should finish the lower half of the `>` symbol
|
||||
|
||||
* tap the `run` button to view the updated script on the simulator
|
||||
|
||||
Add the bottom half of the `>` symbol by plotting the most bottom - left LED first. Make sure to add the line of code `led->plot (0,5)`
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led3.plot(2, 2)
|
||||
basic3.pause(200)
|
||||
basic3.clearScreen()
|
||||
basic3.pause(200)
|
||||
led3.plot(0, 0)
|
||||
led3.plot(1, 1)
|
||||
led3.plot(0, 4) // ***
|
||||
}
|
||||
```
|
||||
|
||||
Awesome! Now we must connect a LED to the original center coordinate `2,2` and the lower left coordinate `0,5` Make sure to add the line of code `led->plot (1,4)`
|
||||
|
||||
Your `main` function should look like this:
|
||||
|
||||
```
|
||||
while (true) {
|
||||
led4.plot(2, 2)
|
||||
basic4.pause(200)
|
||||
basic4.clearScreen()
|
||||
basic4.pause(200)
|
||||
led4.plot(0, 0)
|
||||
led4.plot(1, 1)
|
||||
led4.plot(0, 4)
|
||||
led4.plot(1, 3) // ***
|
||||
}
|
||||
```
|
||||
|
||||
* `run` the script and see that the program works as expected
|
||||
|
||||
Congratulations! You made a `>` symbol.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Use `led->plot` to create a exclamation design `!` Your `main` function should look like this. (notice the notation of `...` represents previous code in **Challenge 0** and **Challenge 1**
|
||||
|
||||
Make sure to add these lines of code within the `while` loop
|
||||
|
||||
Your `main` function should look like this:
|
||||
|
||||
```
|
||||
while (true) {
|
||||
// ...
|
||||
led5.plot(4, 0) // ***
|
||||
led5.plot(4, 1) // ***
|
||||
led5.plot(4, 2) // ***
|
||||
led5.plot(4, 4) // ***
|
||||
}
|
||||
```
|
||||
|
||||
* run the code and see that it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Use the same logic `led->plot` to turn on all the LED lights!!!
|
||||
|
||||
* run the code and see that it works as expected
|
43
docs/reference/js/guides/light-column-cascade-activity.md
Normal file
43
docs/reference/js/guides/light-column-cascade-activity.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Light Column Cascade Worksheet
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Great Job! You have completed the Light Column Cascade tutorial having a nested for loop that plots each individual LED by column adding a delay between lighting each LED.
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
basic.pause(200)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Make the board light up faster by making the pause less time.
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 5; i1++) {
|
||||
for (let j1 = 0; j1 < 5; j1++) {
|
||||
led1.plot(i1, j1)
|
||||
basic1.pause(100) // ***
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Make the board light up by rows instead of by columns by changing the i to the y position and j to the x position.
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 5; i2++) {
|
||||
for (let j2 = 0; j2 < 5; j2++) {
|
||||
led2.plot(j2, i2) // ***
|
||||
basic2.pause(100)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
43
docs/reference/js/guides/light-column-cascade.md
Normal file
43
docs/reference/js/guides/light-column-cascade.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Light Column Cascade Activity
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Great Job! You have completed the Light Column Cascade tutorial having a nested for loop that plots each individual LED by column adding a delay between lighting each LED.
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
basic.pause(200)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Make the board light up faster by making the pause less time.
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 5; i1++) {
|
||||
for (let j1 = 0; j1 < 5; j1++) {
|
||||
led1.plot(i1, j1)
|
||||
basic1.pause(100) // ***
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Make the board light up by rows instead of by columns by changing the i to the y position and j to the x position.
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 5; i2++) {
|
||||
for (let j2 = 0; j2 < 5; j2++) {
|
||||
led2.plot(j2, i2) // ***
|
||||
basic2.pause(100)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
22
docs/reference/js/guides/scroll-image-docs.md
Normal file
22
docs/reference/js/guides/scroll-image-docs.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Scroll Image Docs
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
This [guided tutorial](/microbit/xuhkviyyxa) introduces how to make an image look like it's scrolling across the micro:bit!
|
||||
|
||||
We can use an animation to make an image look like its moving!
|
||||
|
||||
```
|
||||
basic.forever()
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Now, let's reverse the animation so it looks like the bar is bouncing off the right edge of the display.
|
||||
|
||||
```
|
||||
basic1.forever()
|
||||
```
|
||||
|
140
docs/reference/js/guides/touchdevelop-lessons.md
Normal file
140
docs/reference/js/guides/touchdevelop-lessons.md
Normal file
@ -0,0 +1,140 @@
|
||||
# TouchDevelop Lessons
|
||||
|
||||
Overview of TouchDevelop lessons for the micro:bit. #docs #contents
|
||||
|
||||
### @section full
|
||||
|
||||
### ~column
|
||||
|
||||
### LED screen
|
||||
|
||||
* [plot guided](/microbit/hcwxud) `guided tutorial ` `video available`
|
||||
* [plots an LED](/microbit/njuzbvocit) [guided tutorial]
|
||||
* [blink symbols](/microbit/rfchtfjmag) `docs`
|
||||
* [clear screen](/microbit/jwqywu)
|
||||
* [point](/microbit/reference/led/point)
|
||||
* [set brightness](/microbit/tfrmcgdtxk)
|
||||
|
||||
## micro:bit
|
||||
|
||||
## functions
|
||||
|
||||
### Basic
|
||||
|
||||
* [show number](/microbit/doxhko)
|
||||
* [show string](/microbit/hgsfxg)
|
||||
* [forever - show image](/microbit/bniyze) `guided tutorial`
|
||||
* [forever - show animation - two frames 1a](/microbit/rwsjmubtaa)
|
||||
* [forever - show animation - two frames 1c](/microbit/fomtaxxdkk)
|
||||
* [forever - show animation - two frames 1 d](/microbit/huguhgjmmn)
|
||||
* [forever - show animation - multliple frames](/microbit/tweyhx)
|
||||
|
||||
## Language {#pconst}
|
||||
|
||||
### Variables
|
||||
|
||||
* [global variables ](/microbit/nkecii) `guided tutorial`
|
||||
* [local variable - create image, show image](/microbit/dcvnwv)
|
||||
* data types: [number](/microbit/reference/types/number), [boolean](/microbit/reference/types/boolean), [string](/microbit/reference/types/string), [image](/microbit/reference/image/image)
|
||||
|
||||
### Statements and control structures
|
||||
|
||||
* [if](/microbit/reference/logic/if)
|
||||
* [for](/microbit/reference/loops/for)
|
||||
* [for loop nested - plot](/microbit/vpvhdnaqfm) **script**
|
||||
* [while](/microbit/js/while)
|
||||
* [while - show string, show number, show animation](/microbit/bidtzqdips) `docs`
|
||||
* [while - create image ](/microbit/bnqbom)
|
||||
* [return](/microbit/js/return)
|
||||
* [break](/microbit/js/break)
|
||||
* [function](/microbit/js/function)
|
||||
* [assignment operation](/microbit/reference/variables/assign) `:=`
|
||||
|
||||
### Maths
|
||||
|
||||
* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [numbers](/microbit/reference/types/number)
|
||||
* comparison operators (such as `>`, `=`) on [numbers](/microbit/reference/types/number)
|
||||
* the [math](/microbit/js/math) library
|
||||
* the [bits](/microbit/js/bits) library
|
||||
|
||||
### Logical
|
||||
|
||||
* boolean operators (`not`, `or`, `and`) on [booleans](/microbit/reference/types/boolean)
|
||||
|
||||
### Strings
|
||||
|
||||
* concat operator combines [strings](/microbit/reference/types/string)
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
### Input
|
||||
|
||||
* [button is pressed](/microbit/reference/input/button-is-pressed)
|
||||
* [on button pressed](/microbit/reference/input/on-button-pressed)
|
||||
* [acceleration](/microbit/reference/input/acceleration)
|
||||
* [compass heading](/microbit/reference/input/compass-heading)
|
||||
* [calibrate](/microbit/functions/calibrate)
|
||||
* [running time](/microbit/reference/input/running-time)
|
||||
* [on shake](/microbit/reference/input/on-gesture)
|
||||
* [on screen up](/microbit/functions/on-screen-up)
|
||||
* [on screen down](/microbit/functions/on-screen-down)
|
||||
* [on logo up](/microbit/functions/on-logo-up)
|
||||
* [on logo down](/microbit/functions/on-logo-down)
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
### Authoring & Other Bits
|
||||
|
||||
* [TouchDevelop editor](/microbit/js/editor)
|
||||
* [markdown](/microbit/js/markdown)
|
||||
* [creating interactive tutorials](/microbit/js/creatinginteractivetutorials)
|
||||
* [run scripts in a web browser](/microbit/js/simulator)
|
||||
* [run scripts on your micro:bit](/microbit/usb)
|
||||
* [libraries](/microbit/js/libraries)
|
||||
|
||||
### Functions and libraries
|
||||
|
||||
* [creating functions](/microbit/js/function)
|
||||
* [function parameters](/microbit/js/functionparameters)
|
||||
* [calling functions](/microbit/js/call)
|
||||
* [libraries](/microbit/js/libraries)
|
||||
|
||||
### Images
|
||||
|
||||
* [create image](/microbit/reference/images/create-image)
|
||||
* [clear](/microbit/reference/basic/clear-screen)
|
||||
* [set pixel](/microbit/reference/images/set-pixel)
|
||||
* [pixel](/microbit/reference/images/pixel)
|
||||
* [show image](/microbit/reference/images/show-image)
|
||||
* [scroll image](/microbit/reference/images/scroll-image)
|
||||
* [width](/microbit/functions/width)
|
||||
* [show animation](/microbit/reference/basic/show-animation)
|
||||
|
||||
### Pins
|
||||
|
||||
* [analog read pin](/microbit/reference/pins/analog-read-pin)
|
||||
* [analog write pin](/microbit/reference/pins/analog-write-pin)
|
||||
* [digital read pin](/microbit/reference/pins/digital-read-pin)
|
||||
* [digital write pin](/microbit/reference/pins/digital-write-pin)
|
||||
|
||||
### Accessories
|
||||
|
||||
* [forever](/microbit/reference/basic/forever)
|
||||
* [in background](/microbit/reference/control/in-background)
|
||||
|
||||
## Tutorials
|
||||
|
||||
* [Blink](/script:hcwxud)
|
||||
* [Button](/script:rxqgzy)
|
||||
* [Compass](/script:fhhhwl)
|
||||
* [Counter](/script:bqrria)
|
||||
* [Digital pet](/script:lsqwsk)
|
||||
* [Flashing heart](/script:bniyze)
|
||||
* [Glowing image](/script:hydyrp)
|
||||
|
||||
### ~
|
||||
|
60
docs/reference/js/hourofcode.md
Normal file
60
docs/reference/js/hourofcode.md
Normal file
@ -0,0 +1,60 @@
|
||||
# Hour of Code
|
||||
|
||||
learn how to run an Hour Of Code with the BBC micro:bit. #docs
|
||||
|
||||
The BBC micro:bit can be used to run an Hour Of Code™ events for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school.
|
||||
|
||||
## preparing the room
|
||||
|
||||
1) Computers
|
||||
|
||||
* Ensure that each participant will have **a computer connected to a BBC micro:bit board via a micro-USB cable**.
|
||||
|
||||
2) Internet
|
||||
|
||||
* Ensure that each computer has access to **internet**.
|
||||
|
||||
3) Website Access
|
||||
|
||||
* [https://www.microbit.co.uk](https://www.microbit.co.uk)
|
||||
|
||||
4) Raffle tickets and prizes (optional)
|
||||
|
||||
* Reward students with raffle tickets to keep them engaged. Finishing an activity or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice).
|
||||
|
||||
5) Music (optional)
|
||||
|
||||
* We recommend playing the latest hits (loudly) while the students are coding. It creates a playful atmosphere and makes the entire experience more enjoyable. Many web sites offer streaming music, but be sure to try it in advance as certain sites may be blocked on your network.
|
||||
|
||||
## preparing the student handouts
|
||||
|
||||
Print the following **activities** (1 handout per student):
|
||||
|
||||
* [answering machine](/microbit/lessons/answering-machine/activity)
|
||||
* [happy birthday](/microbit/lessons/happy-birthday/activity)
|
||||
* [love meter](/microbit/lessons/love-meter/activity)
|
||||
|
||||
Print the following **challenges** (1 handout per student):
|
||||
|
||||
* [answering machine](/microbit/lessons/answering-machine/challenges)
|
||||
* [happy birthday](/microbit/lessons/happy-birthday/challenges)
|
||||
* [love meter](/microbit/lessons/love-meter/challenges)
|
||||
|
||||
## Timeline
|
||||
|
||||
* ``00:00`` students enter the website address (see step 3)
|
||||
* ``10:00`` [answering machine](/microbit/lessons/answering-machine/activity)
|
||||
* ``25:00`` [happy birthday](/microbit/lessons/happy-birthday/activity)
|
||||
* ``35:00`` [love meter](/microbit/lessons/love-meter/activity)
|
||||
* ``55:00`` raffle
|
||||
* ``60:00`` that's it!
|
||||
|
||||
## Follow up
|
||||
|
||||
After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start:
|
||||
|
||||
* [more challenges](/microbit/js/games) are available with BBC micro:bit Tutorials
|
||||
* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within BBC micro:bit
|
||||
|
||||
The 'Hour of Code™' is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming.
|
||||
|
48
docs/reference/js/hourofcode/notes.md
Normal file
48
docs/reference/js/hourofcode/notes.md
Normal file
@ -0,0 +1,48 @@
|
||||
# Hour of Code notes
|
||||
|
||||
learn how to run an Hour Of Code with the BBC micro:bit. #docs
|
||||
|
||||
The BBC micro:bit can be used to run an Hour Of Code™ event for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school.
|
||||
|
||||
## Preparation
|
||||
|
||||
1) Computers
|
||||
|
||||
Each participant has **a computer connected to a BBC micro:bit via micro-USB**.
|
||||
|
||||
2) Internet
|
||||
|
||||
Ensure that each computer has access to **internet**.
|
||||
|
||||
3) Accounts
|
||||
|
||||
Create a classroom in https://www.microbit.co.uk and pre-populate the classroom with student accounts. **Print the student passwords** and cut out each password.
|
||||
|
||||
4) Print the activity challenges (1 copy per participant):
|
||||
|
||||
* [hour of code](/microbit/js/hourofcode/challenges)
|
||||
|
||||
4) (optional) Raffle tickets and prizes
|
||||
|
||||
Reward students with raffle tickets to keep them engaged. Finishing a tutorial or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice).
|
||||
|
||||
5) (optional) Music
|
||||
|
||||
Bring more energy in the room by playing music.
|
||||
|
||||
## Timeline
|
||||
|
||||
* ``00:00`` student sign in using **printed passwords** (see step 3)
|
||||
* ``10:00`` [hour of code tutorial](/microbit/js/hourofcode)
|
||||
* ``40:00`` raffle and demoes
|
||||
* ``50:00`` that's it!
|
||||
|
||||
## Follow up
|
||||
|
||||
After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start:
|
||||
|
||||
* [more challenges](/microbit/lessonss) are available for BBC micro:bit
|
||||
* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within BBC micro:bit
|
||||
|
||||
_The Hour of Code™ is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming._
|
||||
|
101
docs/reference/js/if.md
Normal file
101
docs/reference/js/if.md
Normal file
@ -0,0 +1,101 @@
|
||||
# If
|
||||
|
||||
Run code based on a condition. #docs #if #then #else #endif #language #elseif
|
||||
|
||||
### @parent js/language
|
||||
|
||||
|
||||
Conditionally run code depending on whether a [Boolean](/microbit/reference/types/boolean) condition is true or false.
|
||||
|
||||
### Block Editor
|
||||
|
||||

|
||||
|
||||
In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block.
|
||||
|
||||
### Touch Develop
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
let condition = true
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
if (condition) {
|
||||
// this code runs if `condition` is `true`
|
||||
} else {
|
||||
// this code runs if `condition` is `false`
|
||||
}
|
||||
```
|
||||
|
||||
### Example: adjusting screen brightness
|
||||
|
||||
If the screen [brightness](/microbit/reference/led/brightness) is `< 100`, this code sets the brightness to `255`:
|
||||
|
||||
```
|
||||
if (led.brightness() < 100) {
|
||||
led.setBrightness(255)
|
||||
}
|
||||
```
|
||||
|
||||
You can leave the `then` or `else` blocks empty if they aren't needed.
|
||||
|
||||
### Else if: multiple if statements
|
||||
|
||||
You can chain together if statements by using `else if`. Like this:
|
||||
|
||||
### ~hide
|
||||
|
||||
```
|
||||
let otherCondition = true
|
||||
```
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
if (condition) {
|
||||
// this code runs if `condition` is `true`
|
||||
} else if (otherCondition) {
|
||||
// this code runs if `other condition` is `true`
|
||||
}
|
||||
else {
|
||||
// this code runs if neither `condition` or `other condition` are `true`
|
||||
}
|
||||
```
|
||||
|
||||
### Example: compass heading
|
||||
|
||||
The following example gets the [compass heading](/microbit/reference/input/compass-heading) and then uses ``if-then-else`` statements to display a letter on the screen (N for north, E for East, S for South, and W for West).
|
||||
|
||||
```
|
||||
while (true) {
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 45) {
|
||||
basic.showString("N", 100)
|
||||
} else if (degrees < 135) {
|
||||
basic.showString("E", 100)
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S", 100)
|
||||
}
|
||||
else {
|
||||
basic.showString("W", 100)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Drag and drop
|
||||
|
||||
You can move an entire ``if`` block by clicking the ``if`` keyword and dragging and dropping.
|
||||
|
||||
### Lessons
|
||||
|
||||
[love meter](/microbit/lessons/love-meter), [zoomer](/microbit/lessons/zoomer), [offset image](/microbit/lessons/offset-image)
|
||||
|
||||
### See also
|
||||
|
||||
[while loop](/microbit/js/while), [for](/microbit/reference/loops/for), [boolean](/microbit/reference/types/boolean)
|
||||
|
71
docs/reference/js/image.md
Normal file
71
docs/reference/js/image.md
Normal file
@ -0,0 +1,71 @@
|
||||
# Image
|
||||
|
||||
An image for the micro:bit screen. #docs #image #screen #LED
|
||||
|
||||
### @parent js/language
|
||||
|
||||
An *Image* is a matrix of pixels to show on the [LED screen](/microbit/device/screen)
|
||||
|
||||
### Touch Develop editor: plot an image
|
||||
|
||||
To display an image using the [Touch Develop editor](/microbit/js/editor):
|
||||
|
||||
* click `image` , `plot image`, and then `edit`
|
||||
* click the rectangles to create an image
|
||||
* when you're done, click **ok** to return to your code
|
||||
|
||||

|
||||
|
||||
You should see code similar to this:
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
```
|
||||
|
||||
### Creating an image
|
||||
|
||||
To create an image that you can later modify, see the [create image](/microbit/reference/images/create-image) function.
|
||||
|
||||
### Block editor: create and show images
|
||||
|
||||
To create images using the [Block editor](/microbit/blocks/editor):
|
||||
|
||||
1. Click the **Images** category on the left.
|
||||
|
||||
2. Drag and drop the **show image** block into your code.
|
||||
|
||||
3. Drag and drop the **create image** or **create big image** block onto the **show image** block so that they connect.
|
||||
|
||||
4. Make an image on the **create image** block by clicking on the squares.
|
||||
|
||||
### Global image variables
|
||||
|
||||
Images that you create in the [Touch Develop editor](/microbit/js/editor) are [local variables](/microbit/reference/variables/var). To promote a local image variable to a global variable, select the local image variable and click `promote to data`. The *var* keyword changes to the [data](/microbit/js/data) symbol `data->`.
|
||||
|
||||
### Image functions
|
||||
|
||||
* [create image](/microbit/reference/images/create-image): create an image from a series of on/off LED states
|
||||
* [clear](/microbit/reference/basic/clear-screen): turn off all the pixels in an image
|
||||
* [set pixel](/microbit/reference/images/set-pixel): set the state of a pixel in an image
|
||||
* [pixel](/microbit/reference/images/pixel): get the state of a pixel in an image
|
||||
* [plot-image](/microbit/reference/led/plot-image): show a single-frame image on the LED screen
|
||||
* [show animation](/microbit/reference/basic/show-animation): show a series of image frames
|
||||
* [show image](/microbit/reference/images/show-image): show an image on the screen
|
||||
* [scroll image](/microbit/reference/images/scroll-image): scroll an image on the screen
|
||||
* [width](/microbit/functions/width): get the width of an image
|
||||
|
||||
### Lessons
|
||||
|
||||
* [bounce image ](/microbit/lessons/bounce-image)
|
||||
* [offset image](/microbit/lessons/offset-image)
|
||||
|
||||
### See also
|
||||
|
||||
[plot image](/microbit/reference/led/plot-image), [create image](/microbit/reference/images/create-image), [show image](/microbit/reference/images/show-image), [LED screen](/microbit/device/screen)
|
||||
|
97
docs/reference/js/lessons.md
Normal file
97
docs/reference/js/lessons.md
Normal file
@ -0,0 +1,97 @@
|
||||
# Touch Develop Lessons
|
||||
|
||||
Overview of Touch Develop lessons for the BBC micro:bit. #docs #contents
|
||||
|
||||
### @short Lessons
|
||||
|
||||
### ~column
|
||||
|
||||
## Maker
|
||||
|
||||
* [The Watch](/microbit/lessons/the-watch), design and create The Watch
|
||||
* [Hack your Headphones](/microbit/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones
|
||||
* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits
|
||||
* [Telegraph](/microbit/lessons/telegraph), play the telegraph game between 2 BBC micro:bits
|
||||
* [Ornament Chain](/microbit/lessons/ornament-chain), play the ornament chain game between 2 BBC micro:bits
|
||||
|
||||
## Beginner
|
||||
|
||||
* [Beautiful Image](/microbit/lessons/beautiful-image), show a beautiful image with show LEDs
|
||||
* [Smiley,](/microbit/lessons/smiley) smiley and frowney with show animation
|
||||
* [Lucky 7](/microbit/lessons/lucky-7), show a number on the LED screen with show number
|
||||
* [Answering Machine](/microbit/lessons/answering-machine), show a text message with show string
|
||||
* [Snowflake Fall](/microbit/lessons/snowflake-fall), repeat an animation with forever
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Bounce Image](/microbit/lessons/bounce-image), scroll an image across the screen on shake
|
||||
|
||||
### ~
|
||||
|
||||
* [Magic Logo](/microbit/lessons/magic-logo), show an image on logo up
|
||||
* [Screen Wipe](/microbit/lessons/screen-wipe), turn off the LEDs with clear screen
|
||||
* [Flashing Heart](/microbit/lessons/flashing-heart), display images with a pause
|
||||
* [Blink](/microbit/lessons/blink), turn an LED on and off with plot
|
||||
* [Night Light](/microbit/lessons/night-light), dim the LEDs with set brightness
|
||||
* [Glowing Sword](/microbit/lessons/glowing-sword), make a glowing sword with fade in and fade out
|
||||
|
||||
### ~column
|
||||
|
||||
## Intermediate
|
||||
|
||||
* [Magic 8](/microbit/lessons/magic-8), a fortune teller game with the BBC micro:bit
|
||||
* [Guess the Number](/microbit/lessons/guess-the-number), guess a random number with random
|
||||
* [Rock Paper Scissors](/microbit/lessons/rock-paper-scissors), use image offsets with local variables
|
||||
* [Counter](/microbit/lessons/counter), display a number with a variable
|
||||
* [Love meter](/microbit/lessons/love-meter), create a love meter with on pin pressed
|
||||
* [Zoomer](/microbit/lessons/zoomer), measure the force with acceleration
|
||||
* [Glowing Pendulum](/microbit/lessons/glowing-pendulum), construct a pendulum that glows using acceleration
|
||||
* [Truth or Dare](/microbit/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
|
||||
* [Spinner](/microbit/lessons/spinner), spin the arrow with multiple if statements
|
||||
* [Die Roll](/microbit/lessons/die-roll), spin with more if statements
|
||||
* [Looper](/microbit/lessons/looper), display a series of numbers with a for loop index
|
||||
* [Strobe Light](/microbit/lessons/strobe-light), develop shapes with a nested for loops
|
||||
* [Digi Yoyo](/microbit/lessons/digi-yoyo), create a counter with a while loop
|
||||
* [Rotation Animation](/microbit/lessons/rotation-animation), control an animation with a boolean variable
|
||||
* [Offset Image](/microbit/lessons/offset-image), shift an image horizontally with image offset
|
||||
* [Compass](/microbit/lessons/compass), displays the direction the BBC micro:bit is pointing
|
||||
|
||||
### ~
|
||||
|
||||
### ~column
|
||||
|
||||
## Advanced
|
||||
|
||||
* [Digital Pet](/microbit/lessons/digital-pet), a display of pet images with sub-functions
|
||||
* [Transformers](/microbit/lessons/transformers), use functions to return values
|
||||
* [Speed Button](/microbit/lessons/speed-button), code a speed game with running time
|
||||
* [Catch the Egg](/microbit/lessons/catch-the-egg-game), catch falling eggs in a basket with an acceleration controller
|
||||
* [Headbands](/microbit/lessons/headbands), create a charades game with a collection of strings that hold the words
|
||||
* [Prank WiFi](/microbit/lessons/prank-wifi), create fake WiFi to trick your friends
|
||||
* [Jailbreak](/microbit/lessons/jailbreak), break out of a counting loop by pressing button "A"
|
||||
* [Flipping Bird](/microbit/lessons/flipping-bird), use modulo with a conditional
|
||||
* [Runaway Pac Man](/microbit/lessons/runaway-pacman), construct the game pac man with the BBC micro:bit
|
||||
* [Line of Fire](/microbit/lessons/line-of-fire), make a game to test hand-eye coordination
|
||||
* [The Hat Game](/microbit/lessons/the-hat-game), make a game to test your focus on the moving ball
|
||||
* [2 Player Pong](/microbit/lessons/2-player-pong), collaborate with a classmate to develop Pong on multiple BBC micro:bits
|
||||
|
||||
### Games
|
||||
|
||||
* [Pong](/microbit/lessons/pong), a light bouncing from left to right
|
||||
* [Meteorite](/microbit/lessons/meteorite), a game where meteorites are coming for you one by one
|
||||
* [Minesweeper](/microbit/lessons/minesweeper), make a game to test your memory for placing a LED mine then finding the hidden LED mine
|
||||
* [Bop it](/microbit/lessons/bop-it), a game where you have to keep up with the commands
|
||||
* [Letter up](/microbit/lessons/letter-up), a guessing game with string operators with string at
|
||||
|
||||
### ~
|
||||
|
||||
### ~hide
|
||||
|
||||
* [Number Psych](/microbit/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple BBC micro:bits and a breadboard
|
||||
|
||||
### ~
|
||||
|
||||
### @section full
|
||||
|
||||
The lessons promote computational thinking and computer science literacy[ read more...](/microbit/lessons/teach)
|
||||
|
103
docs/reference/js/lessons/2-player-pong.md
Normal file
103
docs/reference/js/lessons/2-player-pong.md
Normal file
@ -0,0 +1,103 @@
|
||||
# 2 player pong lesson
|
||||
|
||||
make a game to test your focus on the moving ball #function #on-button-pressed #if #show-animation #mod #random #Boolean #docs
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/microbit/lessons/2-player-pong/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` as a unit of code that performs a specific task and returns a result. We will be learning how to create the hat game app using functions, global variables, input on button pressed, if (conditionals), mod, random, Boolean, as well as simple commands such as show animation.
|
||||
|
||||
## What the teacher needs to know/QuickStart Computing Glossary
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep 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.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Repetition: Executing a section of computer code a number of times as part of the program.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **functions** : [read more...](/microbit/js/function)
|
||||
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
|
||||
* **for** : [read more...](/microbit/reference/loops/for)
|
||||
* **if** : [read more...](/microbit/reference/logic/if)
|
||||
* **show animation** : [read more...](/microbit/reference/basic/show-animation)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/2-player-pong/tutorial)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to learn how to conditionally run code depending on whether a condition is true or no
|
||||
* learn how to show a series of image frames on the LED screen
|
||||
* learn how to run code when an input button is pressed
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/2-player-pong/tutorial)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
91
docs/reference/js/lessons/2-player-pong/quiz-answers.md
Normal file
91
docs/reference/js/lessons/2-player-pong/quiz-answers.md
Normal file
@ -0,0 +1,91 @@
|
||||
# 2 player pong quiz answers
|
||||
|
||||
a two-player game of Pong using TWO BBC micro:bits! #LED #number #math #acceleration #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [2 player pong tutorial](/microbit/lessons/2-player-pong/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the two global variables that record if the player has the ball and if the game is running, and assign these variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
hasBall = false
|
||||
gameRunning = false
|
||||
```
|
||||
|
||||
## 2. Write the global variable that keeps track of the game state in which whoever presses button A first will get to start the ball. Assign this variable to its initial value.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
claimBall = true
|
||||
```
|
||||
|
||||
## 3. Write the code that creates a condition to know when Button A is pressed. Then write the 'If statement' to ensure that 'claim ball' is true. If the claim ball is true, then write the code that sets P0 to 1 to signal to the other device that the player has claimed the ball.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
if (claimBall) {
|
||||
pins.digitalWritePin("P0", 1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the code to move the paddle right when button B is pressed. Be sure to check if the game is running and if the paddle is not already on the rightmost edge.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (gameRunning) {
|
||||
if (paddleX != 0) {
|
||||
led.unplot(paddleX, 4)
|
||||
paddleX = paddleX - 1
|
||||
led.plot(paddleX, 4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 5. What are the three pieces of information that we send to the other device when transferring the ball? (Hint: look in your "transfer ball" function, and look for any places that contain "transfer byte").
|
||||
|
||||
<br/>
|
||||
|
||||
The device first transfers a bit of 1 to indicate that the device is going to transfer the data of the ball. After that, the device transfers the x-coordinate of the ball, and then the x-velocity of the ball.
|
||||
|
||||
## 6. Using the function "read velocity", write the code that reads the x-coordinate and the x-velocity of the ball. (Hint: look at the function "read ball".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
ballX = micro_bitTransfer.readByte()
|
||||
ballXVelocity = readVelocity()
|
||||
```
|
||||
|
||||
## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (ballX == 0 || ballX == 4) {
|
||||
ballXVelocity = ballXVelocity * (-1)
|
||||
}
|
||||
```
|
||||
|
||||
## 8. Write the code to move the ball. To move the ball, unplot the ball's original position, update its position variables, and then plot the ball's new position.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.unplot(ballX, 0)
|
||||
ballX = ballX + ballXVelocity
|
||||
ballY = ballY + ballYVelocity
|
||||
led.plot(ballX, ballY)
|
||||
```
|
||||
|
70
docs/reference/js/lessons/2-player-pong/quiz.md
Normal file
70
docs/reference/js/lessons/2-player-pong/quiz.md
Normal file
@ -0,0 +1,70 @@
|
||||
# 2 player pong quiz
|
||||
|
||||
a two-player game of Pong using TWO BBC micro:bits! #LED #number #math #acceleration #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [2 player pong tutorial](/microbit/lessons/2-player-pong/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the two global variables that record if the player has the ball and if the game is running, and assign these variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the global variable that keeps track of the game state in which whoever presses button A first will get to start the ball. Assign this variable to its initial value.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that creates a condition to know when Button A is pressed. Then write the 'If statement' to ensure that 'claim ball' is true. If the 'claim ball' is true, then write the code that sets P0 to 1 to signal to the other device that the player has claimed the ball.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code to move the paddle right when button B is pressed. Be sure to check if the game is running and if the paddle is not already on the rightmost edge.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. What are the three pieces of information that we send to the other device when transferring the ball? (Hint: look in your "transfer ball" function, and look for any places that contain "transfer byte").
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Using the function "read velocity", write the code that reads the x-coordinate and the x-velocity of the ball. (Hint: look at the function "read ball".)
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.)
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 8. Write the code to move the ball. To move the ball, unplot the ball's original position, update its position variables, and then plot the ball's new position.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
59
docs/reference/js/lessons/accelerometer/challenges.md
Normal file
59
docs/reference/js/lessons/accelerometer/challenges.md
Normal file
@ -0,0 +1,59 @@
|
||||
# zoomer challenges
|
||||
|
||||
The acceleration function. #acceleration #docs #input
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Great job! You have successfully completed the [zoomer tutorial](https://test.microbit.co.uk/td/lessons/zoomer/challenges) . You have created a script that measures the acceleration on the micro:bit in the "z" direction of a 3D world.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let millig = input.acceleration("z")
|
||||
basic.showNumber(millig, 150)
|
||||
basic.pause(100)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Create a new variable called milliX that holds the acceleration in the "x" direction or the horizontal direction.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let millig1 = input.acceleration("z")
|
||||
basic.showNumber(millig1, 150)
|
||||
basic.pause(100)
|
||||
let milliX = input.acceleration("x") // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
If Button `A` is pressed, we want to show the acceleration in the "x" direction by adding an if statement that checks to see if Button `A` is pressed and then calling the show number method passing in milliX as the number.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let millig2 = input.acceleration("z")
|
||||
basic.showNumber(millig2, 150)
|
||||
basic.pause(100)
|
||||
let milliX1 = input.acceleration("x")
|
||||
if (input.buttonIsPressed("A")) {
|
||||
basic.showNumber(milliX1, 150) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
If Button `B` is pressed, program the micro:bit to display the acceleration in the "y" direction.
|
||||
|
||||
You can do this by storing the acceleration in a variable: `var milliY := input->acceleration("y")`.
|
||||
|
||||
Then add an `if` statement that checks if Button `B` is pressed: `if input-> button is pressed ("B") then`.
|
||||
|
||||
Inside of the `if` statement, add `basic->show number(milliY, 150)`, which will display the acceleration in the "y" direction.
|
||||
|
81
docs/reference/js/lessons/answering-machine.md
Normal file
81
docs/reference/js/lessons/answering-machine.md
Normal file
@ -0,0 +1,81 @@
|
||||
# answering machine lesson
|
||||
|
||||
create an answering machine on the BBC micro:bit #docs
|
||||
|
||||
### @video td/videos/answering-machine-0
|
||||
|
||||
## Topic
|
||||
|
||||
Show String
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/microbit/lessons/answering-machine/activity)
|
||||
* [quiz](/microbit/lessons/answering-machine/quiz)
|
||||
* [quiz answers](/microbit/lessons/answering-machine/quiz-answers)
|
||||
* [challenges](/microbit/lessons/answering-machine/challenges)
|
||||
* [tutorial](/microbit/lessons/answering-machine/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a message with a **string**, `basic->show string` to write your message. We will be learning how to create a message using simple commands, such as show string and on button pressed.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **show string** : [read more...](/microbit/reference/basic/show-string)
|
||||
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to show a string on the LED screen one character at a time
|
||||
* learn how to use to register an event handler that will execute whenever an input button is pressed
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
* Evaluates the appropriatness of digital devices, internet services and application software to achieve given goals (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [activity](/microbit/lessons/answering-machine/activity)
|
||||
* [quiz](/microbit/lessons/answering-machine/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/answering-machine/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/answering-machine/challenges)
|
||||
|
25
docs/reference/js/lessons/banana-keyboard.md
Normal file
25
docs/reference/js/lessons/banana-keyboard.md
Normal file
@ -0,0 +1,25 @@
|
||||
# banana keyboard blocks lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit #var #pause #docs
|
||||
|
||||
## Topic
|
||||
|
||||
Music
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/microbit/lessons/banana-keyboard/activity)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, earphones (or speakers), as well as crocodile clips (or spring clips). The connect fruit using pins P1 and GND.
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to setup the BBC micro:bit with earphones to play music
|
||||
* learn how to setup the BBC micro:bit with fruit be the musical instrument
|
||||
|
76
docs/reference/js/lessons/beautiful-image.md
Normal file
76
docs/reference/js/lessons/beautiful-image.md
Normal file
@ -0,0 +1,76 @@
|
||||
# beautiful image lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit #var #pause #docs
|
||||
|
||||
### @video td/videos/beautiful-image-0
|
||||
|
||||
## Topic
|
||||
|
||||
Show LEDs
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/microbit/lessons/beautiful-image/activity)
|
||||
* [quiz](/microbit/lessons/beautiful-image/quiz)
|
||||
* [quiz answers](/microbit/lessons/beautiful-image/quiz-answers)
|
||||
* [challenges](/microbit/lessons/beautiful-image/challenges)
|
||||
* [tutorial](/microbit/lessons/beautiful-image/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to **show LEDs**, to show an image on the BBC micro:bit's LED screen. We will be learning how to Show LEDs using simple commands such as Show LEDs and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **show LEDs** : [read more...](/microbit/reference/basic/show-leds)
|
||||
* **pause** : [read more...](/microbit/reference/basic/pause)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to display an image on the micro:bit's LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/beautiful-image/tutorial)
|
||||
* [quiz](/microbit/lessons/beautiful-image/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/beautiful-image/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/beautiful-image/challenges)
|
||||
|
97
docs/reference/js/lessons/blink.md
Normal file
97
docs/reference/js/lessons/blink.md
Normal file
@ -0,0 +1,97 @@
|
||||
# blink lesson
|
||||
|
||||
Learn how to create a blinking LED. #LED #screen #plot #docs #lesson
|
||||
|
||||
### @video td/videos/blink-0
|
||||
|
||||
## Topic
|
||||
|
||||
Plot
|
||||
|
||||
## Quick links
|
||||
|
||||
* [activity](/microbit/lessons/blink/activity)
|
||||
* [quiz](/microbit/lessons/blink/quiz)
|
||||
* [quiz answers](/microbit/lessons/blink/quiz-answers)
|
||||
* [challenges](/microbit/lessons/blink/challenges)
|
||||
* [tutorial](/microbit/lessons/blink/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, unplot and pause.
|
||||
|
||||
## What the teacher needs to know / QuickStart Computing Glossary
|
||||
|
||||
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
|
||||
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem
|
||||
|
||||
**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. The forever loop repeats code in the background forever.
|
||||
|
||||
**Command:** An instruction for the computer to execute, written in a particular programming language.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **plot**: [read more...](/microbit/reference/led/plot)
|
||||
* **unplot**: [read more...](/microbit/reference/led/unplot)
|
||||
* **pause**: [read more...](/microbit/reference/basic/pause)
|
||||
* **forever**: [read more...](/microbit/reference/basic/forever)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/blink/tutorial)
|
||||
* Activity: [quiz](/microbit/lessons/blink/quiz)
|
||||
* Extended Activity: [challenges](/microbit/lessons/blink/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to turn on LED lights on the LED screen
|
||||
* learn how to turn off LED lights on the LED screen
|
||||
* learn how to pause program execution for the specified number of milliseconds
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/blink/tutorial)
|
||||
* [quiz](/microbit/lessons/blink/quiz)
|
||||
* [quiz answers](/microbit/lessons/blink/quiz-answers)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/blink/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/blink/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
55
docs/reference/js/lessons/blink/activity.md
Normal file
55
docs/reference/js/lessons/blink/activity.md
Normal file
@ -0,0 +1,55 @@
|
||||
# blink activity
|
||||
|
||||
Turn an LED on and off with forever
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/blink-0
|
||||
|
||||
Let's learn how to blink an LED.
|
||||
|
||||
### ~
|
||||
|
||||
Have you ever tried to blink a flashlight at night? The concept is fairly simply: turn on the light, wait for a little, turn off the light, wait again, and repeat. That's exactly what we need to code to get a blinking LED.
|
||||
|
||||
Let's start by adding a line of code that turns on the LED at position ``2, 2``.
|
||||
|
||||
```
|
||||
led.plot(2, 2)
|
||||
```
|
||||
|
||||
Run your script to make sure it's correct. Then, let's add code to **pause** `500` milliseconds and turn off the LED.
|
||||
|
||||
```
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
```
|
||||
|
||||
We've got the LED blinking once. Let's add another pause and turn on the LED again.
|
||||
|
||||
```
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(500)
|
||||
led.plot(2, 2)
|
||||
```
|
||||
|
||||
The current code works but it only blinks once! We are going to use a `basic->forever` loop and move the code inside it to repeat it forever. We've dropped the second `led-plot` line since we don't need it in the loop.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
basic.pause(500)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/blink/challenges)!
|
||||
|
||||
### ~
|
||||
|
85
docs/reference/js/lessons/blink/challenges.md
Normal file
85
docs/reference/js/lessons/blink/challenges.md
Normal file
@ -0,0 +1,85 @@
|
||||
# blink challenges
|
||||
|
||||
Coding challenges for the blink tutorial #docs #challenges
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [blink](/microbit/lessons/blink/activity) activity and your code will look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
basic.pause(200)
|
||||
led.unplot(2, 2)
|
||||
basic.pause(200)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/blink-1
|
||||
|
||||
Let's display a "smiley face" on the screen! We'll start by plotting the eyes.
|
||||
|
||||
Add `led->plot (1,1)` and `led->plot(3,1)` under `led->plot(2,2)` ; then add `led->unplot(1,1)` and `led->unplot(3,1)` after pause. When you're ready, don't forget to run your code to try it out!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
led.plot(1, 1)
|
||||
led.plot(3, 1)
|
||||
basic.pause(200)
|
||||
led.unplot(2, 2)
|
||||
led.unplot(1, 1)
|
||||
led.unplot(3, 1)
|
||||
basic.pause(200)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/blink-2
|
||||
|
||||
Let's add the code to plot the mouth by plotting and unplotting `(1,4)`, `(2,4)` and `(3,4)`.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
led.plot(2, 2)
|
||||
led.plot(1, 1)
|
||||
led.plot(3, 1)
|
||||
led.plot(1, 4)
|
||||
led.plot(2, 4)
|
||||
led.plot(3, 4)
|
||||
basic.pause(200)
|
||||
led.unplot(2, 2)
|
||||
led.unplot(1, 1)
|
||||
led.unplot(3, 1)
|
||||
led.unplot(1, 4)
|
||||
led.unplot(2, 4)
|
||||
led.unplot(3, 4)
|
||||
basic.pause(200)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/blink-3
|
||||
|
||||
Let's keep using `led->plot` to convert the mouth into a smiley face.
|
||||
|
||||
```` bitmatrix
|
||||
0 0 0 0 0
|
||||
0 1 0 1 0
|
||||
0 0 1 0 0
|
||||
1 0 0 0 1
|
||||
0 1 1 1 0
|
||||
````
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Let's make it blink a bit faster. To do so, we need to reduce the amount of time used in ``basic->pause`` to ``100`` milliseconds.
|
||||
|
||||
### Challenge 5
|
||||
|
||||
Create your own image by changing the coordinates in `led->plot`!
|
||||
|
101
docs/reference/js/lessons/blink/lesson-plan.md
Normal file
101
docs/reference/js/lessons/blink/lesson-plan.md
Normal file
@ -0,0 +1,101 @@
|
||||
# blink lesson plan
|
||||
|
||||
Learn how to create a blinking LED script.
|
||||
|
||||
### @video vimeo/133778417
|
||||
|
||||
## Topic
|
||||
|
||||
Plot - Blinking LED
|
||||
|
||||
## Quick links
|
||||
|
||||
* [tutorial](/microbit/lessons/blink/tutorial)
|
||||
* [quiz](/microbit/js/blink/quiz)
|
||||
* [quiz answers](/microbit/lessons/blink/quiz-answers)
|
||||
* [challenges](/microbit/lessons/blink/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, pause, and clear screen.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.**
|
||||
|
||||
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem**
|
||||
|
||||
**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever.
|
||||
|
||||
**Command:** An instruction for the computer to execute, written in a particular programming language.**
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **plot**: [read more...](/microbit/reference/led/plot)
|
||||
* **pause**: [read more...](/microbit/reference/basic/pause)
|
||||
* **clear screen**: [read more...](/microbit/reference/basic/clear-screen)
|
||||
* **forever**: [read more...](/microbit/reference/basic/forever)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/blink/tutorial)
|
||||
* Activity: [quiz](/microbit/lessons/blink/quiz)
|
||||
* Extended Activity: [challenges](/microbit/lessons/blink/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to blink a light
|
||||
* learn how to turn the light on and off
|
||||
* learn how to repeat turning on and off the light
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/blink/tutorial)
|
||||
* [quiz](/microbit/lessons/blink/quiz)
|
||||
* assessment opportunities: forever, plot, pause, clear screen
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/blink/challenges)
|
||||
* assessment opportunities: loops, plot, pause, clear screen
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/blink/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
46
docs/reference/js/lessons/blink/quiz-answers.md
Normal file
46
docs/reference/js/lessons/blink/quiz-answers.md
Normal file
@ -0,0 +1,46 @@
|
||||
# blink quiz answers
|
||||
|
||||
Learn how to create a blinking LED script.
|
||||
|
||||
This is the answer key for the [blink quiz](/microbit/lessons/blink/quiz).
|
||||
|
||||
## 1. Describe what `led->plot` does?
|
||||
|
||||
Answers will vary. In general, plot refers to the code that turns on a specific LED. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Draw which LED is ON after running this code
|
||||
|
||||
```
|
||||
led.plot(2, 2)
|
||||
```
|
||||
|
||||

|
||||
|
||||
By default, the position of an LED on *Blink Tutorial* is set to the centre of the screen. This code turns on the centre LED
|
||||
|
||||
## 3. Draw which LED is ON after running this code
|
||||
|
||||
```
|
||||
led.plot(0, 0)
|
||||
```
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
* ``x`` - the x coordinate or horizontal position (0)
|
||||
* ``y`` - the y coordinate or vertical position (0)
|
||||
|
||||
## 4. Draw which LED is ON after running this code
|
||||
|
||||
```
|
||||
led.plot(4, 4)
|
||||
```
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using ``x``, ``y`` coordinates.
|
||||
|
||||
* ``x`` - the x coordinate or horizontal position (4)
|
||||
* ``y`` - the y coordinate or vertical position (4)
|
||||
|
40
docs/reference/js/lessons/blink/quiz.md
Normal file
40
docs/reference/js/lessons/blink/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# blink quiz
|
||||
|
||||
Learn how to create a blinking LED script.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [blink tutorial](/microbit/lessons/blink/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what `led->plot` does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Draw which LED is ON after running this code
|
||||
|
||||
```
|
||||
led.plot(2, 2)
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 3. Draw which LED is ON after running this code
|
||||
|
||||
```
|
||||
led.plot(0, 0)
|
||||
```
|
||||
|
||||

|
||||
|
||||
## 4. Draw which LED is ON after running this code
|
||||
|
||||
```
|
||||
led.plot(4, 4)
|
||||
```
|
||||
|
||||

|
||||
|
79
docs/reference/js/lessons/blinks-rectangle/challenges.md
Normal file
79
docs/reference/js/lessons/blinks-rectangle/challenges.md
Normal file
@ -0,0 +1,79 @@
|
||||
# rectangle explosion challenges
|
||||
|
||||
These challenges will allow you to make an exploding rectangle. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
This [guided tutorial](https://test.microbit.co.uk/td/lessons/blinks-rectangle/tutorial) will help you show an animation forever!
|
||||
|
||||
First, let's make a small rectangle blink forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
. # # # . . . . . .
|
||||
. # # # . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Let's begin creating our explosion effect by adding another rectangle animation that displays a slightly larger rectangle after the first one.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
. # # # . . . . . .
|
||||
. # # # . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
To finalize our explosion effect, let's add a rectangle that is bigger than the last two we have created.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
. # # # . . . . . .
|
||||
. # # # . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
If you notice, the rectangle explodes fairly slow. Let's make it explode faster by decreasing the intervals of the animation from 400 to 200.
|
||||
|
91
docs/reference/js/lessons/boolean-fun/challenges.md
Normal file
91
docs/reference/js/lessons/boolean-fun/challenges.md
Normal file
@ -0,0 +1,91 @@
|
||||
# speed button challenges
|
||||
|
||||
This challenging script will create a game in which the user needs to press button A fast enough. You will get practice with using booleans in "if" statements. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/speed-button/tutorial) will help you begin creating this game!
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
We need to know when the user has hit button `A` 15 times. The user wins when he/she is able to accomplish this in less than 3500 milliseconds (3.5 seconds). We can check for both conditions by using an `and` operator. When using an `and` operator, both conditions need to be true in order for the condition to be true.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Next, if the user has won, let's set our boolean to true. This indicates that he or she has won.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
fastPress = true // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
We want to set `fastPress` to false if the user was too slow. To do so, we need another condition to see if the user took more than 3500 milliseconds (3.5 seconds). In the `if` statement, set `fastPress` to false.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
fastPress = true
|
||||
}
|
||||
if (counter == 15 && input.runningTime() > 3499) {
|
||||
fastPress = false // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's display if the user won or lost. To do so, we need to check the status of `fastPress` when the game is finished, and then show the correct message.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
fastPress = true
|
||||
}
|
||||
if (counter == 15 && input.runningTime() > 3499) {
|
||||
fastPress = false
|
||||
}
|
||||
if (counter == 15 && fastPress) {
|
||||
basic.showString("YOU WIN!", 150) // ***
|
||||
}
|
||||
if (counter == 15 && ! fastPress) {
|
||||
basic.showString("TOO SLOW!", 150) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Click the `run` button to see if the code runs properly.
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Modify the code to change the difficulty level. Increasing the time will make it easier, while decreasing the time will make it harder. For example, changing the 3500 milliseconds to 4500 milliseconds will make the difficulty easier.
|
||||
|
97
docs/reference/js/lessons/bop-it.md
Normal file
97
docs/reference/js/lessons/bop-it.md
Normal file
@ -0,0 +1,97 @@
|
||||
# bop it lesson
|
||||
|
||||
a game where you have to keep up with the commands #var #data #if #random #min #max #mod #plot #unplot #pause #accceleration #docs
|
||||
|
||||
## Topic
|
||||
|
||||
Game Library
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/microbit/lessons/bop-it/tutorial)
|
||||
* [quiz](/microbit/lessons/bop-it/quiz)
|
||||
* [quiz answers](/microbit/lessons/bop-it/quiz-answers)
|
||||
* [challenges](/microbit/lessons/bop-it/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a minesweeper game with **if**, `if condition do` , **global variables** to keep track of the action that the player is asked to perform. We will be learning how to create a bop it game using functions, global variables, if (conditionals), input on button pressed, math random, logo down, add score, as well as simple commands such as show string.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **game library** : [read more...](/microbit/js/game-library)
|
||||
* **global variables** : [read more...](/microbit/js/data)
|
||||
* **assignment operator** : [read more...](/microbit/reference/variables/assignment)
|
||||
* **functions** : [read more...](/microbit/js/function)
|
||||
* **call** : [read more...](/microbit/js/call)
|
||||
* **math random number** : [read more...](/microbit/js/math)
|
||||
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
|
||||
* **on logo down** : [read more...](/microbit/functions/on-logo-down)
|
||||
* **on shake** : [read more...](/microbit/reference/input/on-gesture)
|
||||
* **if** : [read more...](/microbit/reference/logic/if)
|
||||
* **show number** : [read more...](/microbit/reference/basic/show-number)
|
||||
* **show string** : [read more...](/microbit/reference/basic/show-string)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how the game library supports single-player, time-based games: a game library supports setting a number of lives, score, countdown clock, and levels.
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how the assignment operator is used to declare a new variable or update the value of a variable
|
||||
* learn how to create a function as a unit of code that performs a specific task and returns a result to make the code easier to read, debug, and update
|
||||
* learn how to call an existing function in the script
|
||||
* learn how to return a random number
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to run code when the BBC micro:bit is oriented perpendicularly to the floor with the logo down
|
||||
* learn how to run code when the BBC micro:bit is shaken; when running code in the web browser, moving the mouse quickly simulates shaking
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to show a string of the LED screen one character at a time (scrolling left to right)
|
||||
* learn how to show a number on the LED screen one digit at a time (scrolling left to right)
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/bop-it/tutorial)
|
||||
* [quiz](/microbit/lessons/bop-it/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/bop-it/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/bop-it/challenges)
|
||||
|
87
docs/reference/js/lessons/bop-it/challenges.md
Normal file
87
docs/reference/js/lessons/bop-it/challenges.md
Normal file
@ -0,0 +1,87 @@
|
||||
# bop it challenges
|
||||
|
||||
a game similar to "Simon Says" with the BBC micro:bit. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/bop-it/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
newAction() // ***
|
||||
input.onButtonPressed("A", () => {
|
||||
if (action == 0) {
|
||||
game.addScore(1) // ***
|
||||
newAction() // ***
|
||||
}
|
||||
}) // ***
|
||||
input.onLogoDown(() => {
|
||||
if (action == 1) {
|
||||
game.addScore(1) // ***
|
||||
newAction() // ***
|
||||
}
|
||||
}) // ***
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
if (action == 2) {
|
||||
game.addScore(1) // ***
|
||||
newAction() // ***
|
||||
}
|
||||
}) // ***
|
||||
input.onButtonPressed("B", () => {
|
||||
basic.showNumber(game.score(), 150) // ***
|
||||
basic.pause(2000) // ***
|
||||
newAction() // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
```
|
||||
/**
|
||||
* {highlight}
|
||||
*/
|
||||
export function newAction_() {
|
||||
action = Math.random(4) // ***
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150) // ***
|
||||
}
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150) // ***
|
||||
}
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150) // ***
|
||||
}
|
||||
if (action == 3) {
|
||||
basic.showString("PRESS PIN 0", 150) // ***
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 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`.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed("B", () => {
|
||||
basic.showNumber(game.score(), 150) // ***
|
||||
basic.pause(2000) // ***
|
||||
newAction() // ***
|
||||
}) // ***
|
||||
input.onPinPressed("P0", () => {
|
||||
if (action == 3) {
|
||||
game.addScore(1) // ***
|
||||
newAction() // ***
|
||||
}
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add `POINT ME NORTH` to the list of possible commands.
|
||||
|
86
docs/reference/js/lessons/bop-it/quiz-answers.md
Normal file
86
docs/reference/js/lessons/bop-it/quiz-answers.md
Normal file
@ -0,0 +1,86 @@
|
||||
# bop it quiz answers
|
||||
|
||||
a game where you have to keep up with the commands #math #random #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [bop it tutorial](/microbit/lessons/bop-it/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
action = Math.random(3)
|
||||
```
|
||||
|
||||
## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (action == 0) {
|
||||
basic.showString("PUSH A", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
if (action == 0) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (action == 1) {
|
||||
basic.showString("LOGO DOWN", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
input.onLogoDown(() => {
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (action == 2) {
|
||||
basic.showString("SHAKE", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onLogoDown(() => {
|
||||
if (action == 1) {
|
||||
game.addScore(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
40
docs/reference/js/lessons/bop-it/quiz.md
Normal file
40
docs/reference/js/lessons/bop-it/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# bop it quiz
|
||||
|
||||
a game where you have to keep up with the commands #math #random #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [bop it tutorial](/microbit/lessons/bop-it/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1
|
||||
|
||||
<br />
|
||||
|
||||
<br />
|
||||
|
||||
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
|
||||
|
||||
<br />
|
||||
|
||||
## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2
|
||||
|
108
docs/reference/js/lessons/bounce-image.md
Normal file
108
docs/reference/js/lessons/bounce-image.md
Normal file
@ -0,0 +1,108 @@
|
||||
# bounce image lesson
|
||||
|
||||
scroll an image across the screen #animation #docs
|
||||
|
||||
### @video td/videos/bounce-image-0
|
||||
|
||||
## Topic
|
||||
|
||||
Basic- Show Animation
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/microbit/lessons/bounce-image/tutorial)
|
||||
* [quiz](/microbit/lessons/bounce-image/quiz)
|
||||
* [quiz answers](/microbit/lessons/bounce-image/quiz-answers)
|
||||
* [challenges](/microbit/lessons/bounce-image/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to creating an **animation**, `basic->show animation` to display a series of images. We will be learning how to create a counter app using a forever loop, the input on shake, and show animation.
|
||||
|
||||
## What the teacher needs to know / QuickStart Computing Glossary
|
||||
|
||||
* 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.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Loop: A block of code repeated automatically under the program’s control.
|
||||
* 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.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **forever** : [read more...](/microbit/reference/basic/forever)
|
||||
* **show animation** : [read more...](/microbit/reference/basic/show-animation)
|
||||
* **on shake** : [read more...](/microbit/reference/input/on-gesture)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/bounce-image/tutorial)
|
||||
* Activity: [quiz](/microbit/lessons/bounce-image/quiz)
|
||||
* Extended Activity: [challenges](/microbit/lessons/bounce-image/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to show a series of image frames on the LED screen, pausing the specified time after each frame
|
||||
* learn how to run code when the micro:bit is shaken; when running code in the web browser, moving the mouse quickly simulates shaking
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Understands that iteration is the repetition of a process such as a loop (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Selects the appropriate data types(AL) (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/bounce-image/tutorial)
|
||||
* [quiz](/microbit/lessons/bounce-image/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/bounce-image/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/bounce-image/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
90
docs/reference/js/lessons/bounce-image/challenges.md
Normal file
90
docs/reference/js/lessons/bounce-image/challenges.md
Normal file
@ -0,0 +1,90 @@
|
||||
# bounce image challenges
|
||||
|
||||
Coding challenges for the bounce image tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/bounce-image/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
`, 200)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/bounce-image-1
|
||||
|
||||
Now, let's add frames to reverse the animation so it looks like the bar is bouncing off the right edge of the display.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
`, 200) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's add a condition for on shake!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
`, 200)
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
### @video td/videos/bounce-image-2-3
|
||||
|
||||
When the BBC micro:bit is shaken we want to show a new animation. Here is an example, but you can create your own. Be creative!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
`, 200)
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # # # # # . . . . . . . . . .
|
||||
. . . . . . # # # . # # # # # . # # # . . . . . .
|
||||
. . # . . . # # # . # # # # # . # # # . . . # . .
|
||||
. . . . . . # # # . # # # # # . # # # . . . . . .
|
||||
. . . . . . . . . . # # # # # . . . . . . . . . .
|
||||
`, 200) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
60
docs/reference/js/lessons/bounce-image/quiz-answers.md
Normal file
60
docs/reference/js/lessons/bounce-image/quiz-answers.md
Normal file
@ -0,0 +1,60 @@
|
||||
# bounce image quiz answers
|
||||
|
||||
scroll an image on the BBC micro:bit #LED #screen #animation #docs
|
||||
|
||||
This is the answer key for the [bounce image quiz](/microbit/lessons/bounce-image/quiz).
|
||||
|
||||
## 1. What does it mean to 'add frames' ?
|
||||
|
||||
Adding frames modifies the animation by including more still images in each animation.
|
||||
|
||||
## 2. Write the code that will display this animation.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# . . . .
|
||||
# . . . .
|
||||
# . . . .
|
||||
# . . . .
|
||||
# . . . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 3. Write the code that will display this animation with two frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 4. Write the code that will display this animation with three frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
40
docs/reference/js/lessons/bounce-image/quiz.md
Normal file
40
docs/reference/js/lessons/bounce-image/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# bounce image quiz
|
||||
|
||||
scroll an image on the BBC micro:bit #LED #screen #animation #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this document to guide your work in the [bounce image tutorial](/microbit/lessons/bounce-image/tutorial) !
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What does it mean to 'add frames' ?
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that will display this animation.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that will display this animation with two frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that will display this animation with three frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
85
docs/reference/js/lessons/boxer-mania/challenges.md
Normal file
85
docs/reference/js/lessons/boxer-mania/challenges.md
Normal file
@ -0,0 +1,85 @@
|
||||
# boxer mania challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
This [guided tutorial](/microbit/lessons/boxer-mania/tutorial) will help you create an animation!
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Let's create and show a series of frames on the LED screen; this is an animation!
|
||||
|
||||
We will use multiple frames to make it look like a square is rotating on the micro:bit screen!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . .
|
||||
# . . . .
|
||||
. # . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Let's create the next frame to make it look like the square is spinning clock-wise!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . .
|
||||
# . . . .
|
||||
. # . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Add the next two frames to show a complete rotation for the square!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . .
|
||||
# . . . .
|
||||
. # . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. # . . . # # # # #
|
||||
# . # . . # . . . #
|
||||
. . . # . # . . . #
|
||||
. . . . # # . . . #
|
||||
. . . # . # # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Do you want to show the same animation with fewer lines of codes? We can do this by combining all the frames into one show animation function call!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . . # # # # # . # . . . # # # # #
|
||||
# . . . . # . . . # # . # . . # . . . #
|
||||
. # . . . # . . . # . . . # . # . . . #
|
||||
. . # . # # . . . # . . . . # # . . . #
|
||||
. . . # . # # # # # . . . # . # # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
86
docs/reference/js/lessons/break/challenges.md
Normal file
86
docs/reference/js/lessons/break/challenges.md
Normal file
@ -0,0 +1,86 @@
|
||||
# break challenges
|
||||
|
||||
This guide will show you how to use a break statement within a while loop. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/microbit/lessons/break/tutorial) will assist you with this activity.
|
||||
|
||||
```
|
||||
count = 0
|
||||
shouldBreak = false
|
||||
input.onButtonPressed("A", () => {
|
||||
shouldBreak = true
|
||||
})
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
images.createImage(`
|
||||
# . . . #
|
||||
# . . . #
|
||||
. . # . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`).showImage(0)
|
||||
break
|
||||
}
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
basic.pause(1000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Try to remove the `break` in the `if` loop. What problem does this create?
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now let's resume the timer again once button `B` is pressed! To do so, begin by creating a condition to know when button `B` is pressed.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
break
|
||||
}
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
basic.pause(1000)
|
||||
}
|
||||
input.onButtonPressed("B", () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
Next, set `shouldBreak` back to false to indicate we want to run the `while` loop again.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed("B", () => {
|
||||
shouldBreak = false // ***
|
||||
})
|
||||
```
|
||||
|
||||
And now copy the code from the previous while loop into the condition of `input->on button pressed("B")`. This will resume the counter.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed("B", () => {
|
||||
shouldBreak = false
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150) // ***
|
||||
break // ***
|
||||
}
|
||||
count = count + 1 // ***
|
||||
basic.showNumber(count, 150) // ***
|
||||
basic.pause(1000) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Notice that the two `while` loops are identical. Clean up this redundancy in your code by creating another method and then placing the `while` loop in the method.
|
||||
|
52
docs/reference/js/lessons/button/challenges.md
Normal file
52
docs/reference/js/lessons/button/challenges.md
Normal file
@ -0,0 +1,52 @@
|
||||
# button challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Howdy! This [guided tutorial](/microbit/rxqgzy) will help you complete this activity!
|
||||
|
||||
In this guide, you will learn how to use buttons and show text on the screen. Let's start by adding to respond **when the left button is pressed**.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
})
|
||||
```
|
||||
|
||||
All the code inside `input->on button pressed` runs when the button is pressed. Let's add the code to show some text.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add an event handler for Button `B`.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Display `bye` when the `B` button is pressed.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
basic.showString("bye", 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Change the strings so that they display some other text. In order to do so, you will need to edit what is inside the quotation marks in `basic->show string`.
|
||||
|
128
docs/reference/js/lessons/cascade/quiz.md
Normal file
128
docs/reference/js/lessons/cascade/quiz.md
Normal file
@ -0,0 +1,128 @@
|
||||
# strobe lightquiz
|
||||
|
||||
Learn how to create a blinking LED script with a for loop. #LED #screen #plot #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [light column cascade tutorial](/microbit/js/light-column-cascade/tutorial).
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs!
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 3; i1++) {
|
||||
for (let j1 = 0; j1 < 3; j1++) {
|
||||
led.plot(i1, j1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 2; i2++) {
|
||||
for (let j2 = 0; j2 < 2; j2++) {
|
||||
led.plot(i2, j2)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
******************************
|
||||
|
||||
## ANSWER KEY
|
||||
|
||||
## Directions
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial.
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i3 = 0; i3 < 5; i3++) {
|
||||
for (let j3 = 0; j3 < 5; j3++) {
|
||||
led.plot(i3, j3)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2,3,4)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2,3,4)
|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 3; i4++) {
|
||||
for (let j4 = 0; j4 < 3; j4++) {
|
||||
led.plot(i4, j4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2)
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i5 = 0; i5 < 2; i5++) {
|
||||
for (let j5 = 0; j5 < 2; j5++) {
|
||||
led.plot(i5, j5)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1)
|
||||
|
||||
y - the y coordinate or vertical position (0,1)
|
||||
|
91
docs/reference/js/lessons/catch-the-egg-game.md
Normal file
91
docs/reference/js/lessons/catch-the-egg-game.md
Normal file
@ -0,0 +1,91 @@
|
||||
# catch the egg game lesson
|
||||
|
||||
a game to catch eggs in a basket #var #data #if #random #min #max #mod #plot #unplot #pause #accceleration #docs
|
||||
|
||||
### @video td/videos/catch-the-egg-game-0
|
||||
|
||||
## Topic
|
||||
|
||||
Variables
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
||||
* [quiz](/microbit/lessons/catch-the-egg-game/quiz)
|
||||
* [quiz answers](/microbit/lessons/catch-the-egg-game/quiz-answers)
|
||||
* [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## 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.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **variables** : [read more...](/microbit/reference/variables/var)
|
||||
* **forever** : [read more...](/microbit/reference/basic/forever)
|
||||
* **unplot** : [read more...](/microbit/reference/led/unplot)
|
||||
* **plot** : [read more...](/microbit/reference/led/plot)
|
||||
* **if** : [read more...](/microbit/reference/logic/if)
|
||||
* **acceleration** : [read more...](/microbit/reference/input/acceleration)
|
||||
* **math minimum number** : [read more...](/microbit/js/math)
|
||||
* **math maximum number** : [read more...](/microbit/js/math)
|
||||
* **math random number** : [read more...](/microbit/js/math)
|
||||
* **math modulus** : [read more...](/microbit/js/math)
|
||||
* **show number** : [read more...](/microbit/reference/basic/show-number)
|
||||
* **pause** : [read more...](/microbit/reference/basic/pause)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to turn off a LED light on the LED screen
|
||||
* learn how to turn on a LED light on the LED screen
|
||||
* learn how to learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to learn how to get the acceleration value (g-force), in one of three specified dimensions
|
||||
* learn how to return the smaller of two numbers
|
||||
* learn how to return the larger of two numbers
|
||||
* learn how to return a random number
|
||||
* learn how to return the modulus
|
||||
* learn how to show a number of the BBC micro:bit screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
||||
* [quiz](/microbit/lessons/catch-the-egg-game/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/catch-the-egg-game/challenges)
|
||||
|
163
docs/reference/js/lessons/catch-the-egg-game/challenges.md
Normal file
163
docs/reference/js/lessons/catch-the-egg-game/challenges.md
Normal file
@ -0,0 +1,163 @@
|
||||
# catch the egg game challenges
|
||||
|
||||
Coding challenges for catch the egg game.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
let basketX = 2
|
||||
let eggX = 2
|
||||
let eggY = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX, 4)
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
basic.pause(300)
|
||||
let accX = input.acceleration("x")
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
led.plot(basketX, 4)
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar impressed
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's start by adding the **game** library.
|
||||
|
||||
### ~
|
||||
|
||||
### ~avatar avatar improvised
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's use an **IF** statement to detect if the egg and the basket are lined up.
|
||||
|
||||
Now that we know when an egg is caught, we can keep track of the score! We need to use the `add score` function built into the game library to add `1` point for every egg that is caught. However, let's not forget to `remove life` if an egg falls off the display before it's caught!
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
let basketX1 = 2
|
||||
let eggX1 = 2
|
||||
let eggY1 = 0
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX1, 4)
|
||||
led.unplot(eggX1, eggY1)
|
||||
eggY1 = eggY1 + 1
|
||||
led.plot(eggX1, eggY1)
|
||||
basic.pause(300)
|
||||
let accX1 = input.acceleration("x")
|
||||
basketX1 = 2 + Math.min(2, Math.max(-2, accX1 / 200))
|
||||
led.plot(basketX1, 4)
|
||||
if (eggY1 > 4) {
|
||||
eggY1 = -1
|
||||
eggX1 = Math.random(5)
|
||||
}
|
||||
if (eggY1 == 4) {
|
||||
if (basketX1 == eggX1) {
|
||||
game.addScore(1) // ***
|
||||
} else {
|
||||
game.removeLife(1) // ***
|
||||
}
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
* Press the `run` button to test out your game.
|
||||
|
||||
### ~avatar avatar encourage
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Catching eggs gets easier with practice so let's make the eggs fall faster every 5 catches. We can do this by tracking how long the egg pauses in each position while falling with a global variable called **falling pause**. Let's create this variable and set it to `300` initially. Don't forget to also create a condition that will be true every 5 catches.
|
||||
|
||||
### ~
|
||||
|
||||
```
|
||||
let basketX2 = 2
|
||||
let eggX2 = 2
|
||||
let eggY2 = 0
|
||||
let fallingPause = 300 // ***
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX2, 4)
|
||||
led.unplot(eggX2, eggY2)
|
||||
eggY2 = eggY2 + 1
|
||||
led.plot(eggX2, eggY2)
|
||||
basic.pause(300)
|
||||
let accX2 = input.acceleration("x")
|
||||
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
|
||||
led.plot(basketX2, 4)
|
||||
if (eggY2 > 4) {
|
||||
eggY2 = -1
|
||||
eggX2 = Math.random(5)
|
||||
}
|
||||
if (eggY2 == 4) {
|
||||
if (basketX2 == eggX2) {
|
||||
game.addScore(1)
|
||||
if (math.mod(game.score(), 5) == 0) {
|
||||
}
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(300)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar surprised
|
||||
|
||||
### Challenge 4
|
||||
|
||||
### @video td/videos/catch-the-egg-game-4
|
||||
|
||||
Let's make the egg fall faster by decreasing the amount of time it pauses in each position by decreasing **falling pause** by `25` every 5 catches. Now, instead of pausing for 300 milliseconds we can pause for the value of **falling pause**.
|
||||
|
||||
```
|
||||
let basketX3 = 2
|
||||
let eggX3 = 2
|
||||
let eggY3 = 0
|
||||
let fallingPause1 = 300
|
||||
basic.forever(() => {
|
||||
led.unplot(basketX3, 4)
|
||||
led.unplot(eggX3, eggY3)
|
||||
eggY3 = eggY3 + 1
|
||||
led.plot(eggX3, eggY3)
|
||||
basic.pause(300)
|
||||
let accX3 = input.acceleration("x")
|
||||
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
|
||||
led.plot(basketX3, 4)
|
||||
if (eggY3 > 4) {
|
||||
eggY3 = -1
|
||||
eggX3 = Math.random(5)
|
||||
}
|
||||
if (eggY3 == 4) {
|
||||
if (basketX3 == eggX3) {
|
||||
game.addScore(1)
|
||||
if (math.mod(game.score(), 5) == 0) {
|
||||
fallingPause1 = fallingPause1 - 25 // ***
|
||||
}
|
||||
} else {
|
||||
game.removeLife(1)
|
||||
}
|
||||
}
|
||||
basic.pause(fallingPause1) // ***
|
||||
})
|
||||
```
|
||||
|
||||
Fantastic! Your game is now ready to show off.
|
||||
|
||||
* Press the `run` button to see your finished game!
|
61
docs/reference/js/lessons/catch-the-egg-game/quiz-answers.md
Normal file
61
docs/reference/js/lessons/catch-the-egg-game/quiz-answers.md
Normal file
@ -0,0 +1,61 @@
|
||||
# catch the egg game quiz answers
|
||||
|
||||
Programming a game of catch the egg using the accelerometer
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the data type for the global variables 'basket' and 'egg'.
|
||||
|
||||
<br/>
|
||||
|
||||
'Basket' and 'egg' are stored as **Number**.
|
||||
|
||||
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plot(eggX, eggY)
|
||||
led.plot(basketX, 4)
|
||||
```
|
||||
|
||||
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.unplot(eggX, eggY)
|
||||
eggY = eggY + 1
|
||||
led.plot(eggX, eggY)
|
||||
```
|
||||
|
||||
## 4. Write the code that calculates 'basket x' given the variable 'acc x'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let accX = input.acceleration("x")
|
||||
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
|
||||
```
|
||||
|
||||
Note: the first line of code in this answer is optional.
|
||||
|
||||
## 5. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (eggY > 4) {
|
||||
eggY = -1
|
||||
eggX = Math.random(5)
|
||||
}
|
||||
```
|
||||
|
34
docs/reference/js/lessons/catch-the-egg-game/quiz.md
Normal file
34
docs/reference/js/lessons/catch-the-egg-game/quiz.md
Normal file
@ -0,0 +1,34 @@
|
||||
# catch the egg game quiz
|
||||
|
||||
Programming a game of catch the egg using the accelerometer.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [catch the egg tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the data type for the global variables 'basket' and 'egg'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that calculates 'basket x' given the variable 'acc x'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
8
docs/reference/js/lessons/catch-the-egg.md
Normal file
8
docs/reference/js/lessons/catch-the-egg.md
Normal file
@ -0,0 +1,8 @@
|
||||
# catch the egg
|
||||
|
||||
Programming a game of 'catch the egg' using the accelerometer in Touch Develop #docs #functions #var
|
||||
|
||||
Programming a game of 'catch the egg' using the accelerometer
|
||||
|
||||
* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial)
|
||||
* [challenges](/microbit/lessons/catch-the-egg/challenges)
|
77
docs/reference/js/lessons/clear-screen/challenges.md
Normal file
77
docs/reference/js/lessons/clear-screen/challenges.md
Normal file
@ -0,0 +1,77 @@
|
||||
# clear screen challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/microbit/hzckbb) will help you create the script to clear the screen!
|
||||
|
||||
Your goal is to clear the screen after displaying an animation. Begin by showing and displaying an animation. Remember that the `show animation` is in the `basic` namespace. We then need to detect when the "A" button is pressed. Finally, clear the screen by typing in `basic->clear screen`.
|
||||
|
||||
Your main function should look like this:
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
```
|
||||
|
||||
* tap the `run` button to view the script on the monitor.
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Create an event handler for Button "B".
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`.
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed("A", () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Show an animation that scrolls back up when you press button "B".
|
||||
|
||||
* tap the `run` button to view your final product!
|
128
docs/reference/js/lessons/column/quiz.md
Normal file
128
docs/reference/js/lessons/column/quiz.md
Normal file
@ -0,0 +1,128 @@
|
||||
# cascade quiz
|
||||
|
||||
Learn how to create a blinking LED script with a for loop. #LED #screen #plot #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [light column cascade tutorial](/microbit/js/light-column-cascade/tutorial).
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs!
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 3; i1++) {
|
||||
for (let j1 = 0; j1 < 3; j1++) {
|
||||
led.plot(i1, j1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 2; i2++) {
|
||||
for (let j2 = 0; j2 < 2; j2++) {
|
||||
led.plot(i2, j2)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
******************************
|
||||
|
||||
## KEY
|
||||
|
||||
## Directions
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial.
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i3 = 0; i3 < 5; i3++) {
|
||||
for (let j3 = 0; j3 < 5; j3++) {
|
||||
led.plot(i3, j3)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2,3,4)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2,3,4)
|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 3; i4++) {
|
||||
for (let j4 = 0; j4 < 3; j4++) {
|
||||
led.plot(i4, j4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2)
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i5 = 0; i5 < 1; i5++) {
|
||||
for (let j5 = 0; j5 < 1; j5++) {
|
||||
led.plot(i5, j5)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1)
|
||||
|
||||
y - the y coordinate or vertical position (0,1)
|
||||
|
79
docs/reference/js/lessons/compare-machine/challenges.md
Normal file
79
docs/reference/js/lessons/compare-machine/challenges.md
Normal file
@ -0,0 +1,79 @@
|
||||
# compare machine challenges
|
||||
|
||||
These challenges allow you to set the value of a counter to 1 when button B is pressed. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/microbit/lessons/comparison/tutorial) will assist you with using the comparison operator.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
basic.showNumber(counter, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now let's do something special when the micro:bit reaches the number `5`. Instead of just showing the number `5`, let's show the string `HALF WAY!`. Begin by setting an if statement to know when `counter = 5`.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
if (counter == 5) {
|
||||
}
|
||||
basic.showNumber(counter, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's continue our plan of displaying `HALF WAY!` when `counter = 5`. To do so, add the following line of code inside the if statement.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
if (counter == 5) {
|
||||
basic.showString("HALF WAY!", 150) // ***
|
||||
}
|
||||
basic.showNumber(counter, 150)
|
||||
})
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
You may notice a problem right now. When `counter = 5`, the micro:bit will show both the message `HALF WAY!` and the number `5`. In order to fix this problem, let's take advantage of the `else` at the end of the if statement.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
if (counter == 5) {
|
||||
basic.showString("HALF WAY!", 150)
|
||||
} else {
|
||||
basic.showNumber(counter, 150) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
When `counter = 8`, display the message `ALMOST THERE!` on the micro:bit. You will need to add an `else if` after the if statement of `counter = 5`.
|
||||
|
8
docs/reference/js/lessons/compass.md
Normal file
8
docs/reference/js/lessons/compass.md
Normal file
@ -0,0 +1,8 @@
|
||||
# compass lesson
|
||||
|
||||
build a compass app that applies the BBC micro:bit magnetic sensor (magnetometer) #functions #var #docs
|
||||
|
||||
build a compass app that applies the BBC micro:bit magnetic sensor (magnetometer)
|
||||
|
||||
* [tutorial](/microbit/lessons/compass/tutorial)
|
||||
* [challenges](/microbit/lessons/compass/challenges)
|
88
docs/reference/js/lessons/compass/challenges.md
Normal file
88
docs/reference/js/lessons/compass/challenges.md
Normal file
@ -0,0 +1,88 @@
|
||||
# compass challenges
|
||||
|
||||
Display the direction that the BBC micro:bit is facing using the compass
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/compass/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.calibrate()
|
||||
basic.forever(() => {
|
||||
let degrees = input.compassHeading()
|
||||
if (degrees < 45) {
|
||||
basic.showString("N", 100)
|
||||
} else if (degrees < 135) {
|
||||
basic.showString("E", 100)
|
||||
}
|
||||
else if (degrees < 225) {
|
||||
basic.showString("S", 100)
|
||||
}
|
||||
else {
|
||||
basic.showString("W", 100)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Instead of displaying `N` when the BBC micro:bit is pointing North, display a star to indicate the north star.
|
||||
|
||||
```
|
||||
input.calibrate()
|
||||
basic.forever(() => {
|
||||
let degrees1 = input.compassHeading()
|
||||
if (degrees1 < 45) {
|
||||
basic.plotImage(`
|
||||
# . # . #
|
||||
. # # # .
|
||||
# # # # #
|
||||
. # # # .
|
||||
# . # . #
|
||||
`) // ***
|
||||
} else if (degrees1 < 135) {
|
||||
basic.showString("E", 100)
|
||||
}
|
||||
else if (degrees1 < 225) {
|
||||
basic.showString("S", 100)
|
||||
}
|
||||
else {
|
||||
basic.showString("W", 100)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Instead of displaying just `N`, `W`, `S`, or `E`, display the full word.
|
||||
|
||||
```
|
||||
input.calibrate()
|
||||
basic.forever(() => {
|
||||
let degrees2 = input.compassHeading()
|
||||
if (degrees2 < 45) {
|
||||
basic.showString("NORTH", 100) // ***
|
||||
} else if (degrees2 < 135) {
|
||||
basic.showString("EAST", 100) // ***
|
||||
}
|
||||
else if (degrees2 < 225) {
|
||||
basic.showString("SOUTH", 100) // ***
|
||||
}
|
||||
else {
|
||||
basic.showString("WEST", 100) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Display your own unique message for each direction.
|
||||
|
56
docs/reference/js/lessons/compass/quiz-answers.md
Normal file
56
docs/reference/js/lessons/compass/quiz-answers.md
Normal file
@ -0,0 +1,56 @@
|
||||
# compass quiz answers
|
||||
|
||||
Create an actual compass to show your direction: North, South, East, or West
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [compass tutorial](/microbit/lessons/compass/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the purpose of the 'compass heading' block?
|
||||
|
||||
Gets the compass heading of the BBC micro:bit in degrees
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let degrees = input.compassHeading()
|
||||
```
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the BBC micro:bit
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (degrees < 45) {
|
||||
basic.showString("N", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the BBC micro:bit
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (degrees < 135) {
|
||||
basic.showString("E", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the BBC micro:bit
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (degrees < 225) {
|
||||
basic.showString("S", 150)
|
||||
}
|
||||
```
|
||||
|
32
docs/reference/js/lessons/compass/quiz.md
Normal file
32
docs/reference/js/lessons/compass/quiz.md
Normal file
@ -0,0 +1,32 @@
|
||||
# compass quiz
|
||||
|
||||
Create an actual compass to show your direction: North, South, East, or West
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [compass tutorial](/microbit/lessons/compass/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the purpose of the 'compass heading' block?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the BBC micro:bit
|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the BBC micro:bit
|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the BBC micro:bit
|
||||
|
||||
<br />
|
||||
|
80
docs/reference/js/lessons/counter.md
Normal file
80
docs/reference/js/lessons/counter.md
Normal file
@ -0,0 +1,80 @@
|
||||
# counter lesson
|
||||
|
||||
Learn how to create a counter with with on button pressed. #show #number #screen #number #math #docs
|
||||
|
||||
### @video td/videos/counter-0
|
||||
|
||||
## Topic
|
||||
|
||||
Variables
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/microbit/lessons/counter/activity)
|
||||
* [challenges](/microbit/lessons/counter/challenges)
|
||||
* [quiz](/microbit/lessons/counter/quiz)
|
||||
* [quiz answers](/microbit/lessons/counter/quiz-answers)
|
||||
* [tutorial](/microbit/lessons/counter/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using a variable as well as simple commands, such as on button pressed, and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **variable**: [read more...](/microbit/reference/variables/var)
|
||||
* **arithmetic operators**: [read more...](/microbit/reference/types/number)
|
||||
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
|
||||
* **show number** : [read more...](/microbit/reference/basic/show-number)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across all functions, and in nested code blocks
|
||||
* learn how arithmetic operators operate on numbers and return a number
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
* Represents solutions using a structured notation. (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
* Declares and assigns variables.(AB)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [activity](/microbit/lessons/counter/activity)
|
||||
* [tutorial](/microbit/lessons/counter/tutorial)
|
||||
* [quiz](/microbit/lessons/counter/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/counter/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/counter/challenges)
|
||||
|
45
docs/reference/js/lessons/counter/activity.md
Normal file
45
docs/reference/js/lessons/counter/activity.md
Normal file
@ -0,0 +1,45 @@
|
||||
# counter activity
|
||||
|
||||
Display a number with a variable.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/counter-0
|
||||
|
||||
Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. 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**.
|
||||
|
||||
Let's start by creating a **local variable** `count` to keep track of the current count.
|
||||
|
||||
```
|
||||
let count = 0
|
||||
```
|
||||
|
||||
The code under ``on button pressed("A")`` will run each time the user presses A. Let's add a line of code that increments `count` by `1`.
|
||||
|
||||
```
|
||||
let count_ = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count = count + 1
|
||||
})
|
||||
```
|
||||
|
||||
Since the count has changed, it's time to refresh the screen display. Let's add a line of code to display the count on screen.
|
||||
|
||||
```
|
||||
let count_1 = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/counter/challenges)!
|
||||
|
||||
### ~
|
||||
|
38
docs/reference/js/lessons/counter/challenges.md
Normal file
38
docs/reference/js/lessons/counter/challenges.md
Normal file
@ -0,0 +1,38 @@
|
||||
# counter challenges
|
||||
|
||||
Coding challenges for the counter tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/microbit/lessons/counter/activity) At the end of the tutorial, your code should look like this:
|
||||
|
||||
```
|
||||
let count = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/counter-1-2
|
||||
|
||||
Let's add the code to `count` when `B` is pressed. Add an event handler with `input->on button pressed(B)` then add the code to `count`.
|
||||
|
||||
```
|
||||
let count1 = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count1 = count1 + 1
|
||||
basic.showNumber(count1, 150)
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
count1 = count1 - 1 // ***
|
||||
basic.showNumber(count1, 150) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's try to reset the counter when the BBC micro:bit is shaken. You will need to register an event handler with `input->on shake`.
|
||||
|
91
docs/reference/js/lessons/counter/lesson-plan.md
Normal file
91
docs/reference/js/lessons/counter/lesson-plan.md
Normal file
@ -0,0 +1,91 @@
|
||||
# counter lesson plan
|
||||
|
||||
Learn how to create a counter with with on button pressed.
|
||||
|
||||
### @video vimeo/134118661
|
||||
|
||||
## Topic
|
||||
|
||||
Variable - Counter
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using global variables as well as simple commands, such as on button pressed, and show number.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.**
|
||||
|
||||
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem**
|
||||
|
||||
**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever.
|
||||
|
||||
**Command:** An instruction for the computer to execute, written in a particular programming language.**
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **variables**: [read more...](/microbit/reference/variables/var)
|
||||
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
|
||||
* **show number** : [read more...](/microbit/reference/basic/show-number)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/counter/tutorial)
|
||||
* Activity: [quiz](/microbit/lessons/counter/quiz)
|
||||
* Extended Activity: [challenges](/microbit/lessons/counter/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a variable
|
||||
* learn how to blink a light
|
||||
* learn how to repeat turning on and off the light
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
* Represents solutions using a structured notation. (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
* Declares and assigns variables.(AB)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/counter/tutorial)
|
||||
* [quiz](/microbit/lessons/counter/quiz)
|
||||
* assessment opportunities: forever, plot, pause, clear screen
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/counter/challenges)
|
||||
* assessment opportunities: loops, plot, pause, clear screen
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/counter/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
54
docs/reference/js/lessons/counter/quiz-answers.md
Normal file
54
docs/reference/js/lessons/counter/quiz-answers.md
Normal file
@ -0,0 +1,54 @@
|
||||
# counter quiz answers
|
||||
|
||||
Learn how to create a counter with the BBC micro:bit button.
|
||||
|
||||
This is the answer key for the [counter quiz](/microbit/lessons/counter/quiz).
|
||||
|
||||
## 1. What is a variable?
|
||||
|
||||
Answers may vary but a variable is a place where you can store and retrieve data
|
||||
|
||||
## 2. Draw the stored value for the variable called count
|
||||
|
||||
```
|
||||
let count = 0
|
||||
```
|
||||
|
||||

|
||||
|
||||
We create a **variable**, `count` to keep track of the current count. The number 0 is stored into memory of the variable.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||
|
||||
```
|
||||
let count_ = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count_ = count_ + 1
|
||||
basic.showNumber(count, 150)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
We are only pressing on button pressed once. So the number to display on the micro:bit is also one.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||
|
||||
```
|
||||
count_ = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count_ = count_ + 1
|
||||
basic.showNumber(count_, 100)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
We included the code ``on button pressed("A")`` that runs each time the user presses A. The code increments `count` by `1`. We increase `count` by 1 whenever the user presses the button. So the third time the A button is pressed on the BBC micro:bit, the number 3 is displayed
|
||||
|
||||
<br/>
|
||||
|
54
docs/reference/js/lessons/counter/quiz.md
Normal file
54
docs/reference/js/lessons/counter/quiz.md
Normal file
@ -0,0 +1,54 @@
|
||||
# counter quiz
|
||||
|
||||
Learn how to create a counter with the BBC micro:bit button.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [counter tutorial](/microbit/lessons/counter/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a variable?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Draw the stored value for the variable called count
|
||||
|
||||
```
|
||||
let count = 0
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||
|
||||
```
|
||||
let count_ = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count_ = count_ + 1
|
||||
basic.showNumber(count_, 100)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||
|
||||
```
|
||||
count_ = 0
|
||||
input.onButtonPressed("A", () => {
|
||||
count_ = count_ + 1
|
||||
basic.showNumber(count_, 100)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
91
docs/reference/js/lessons/die-roll.md
Normal file
91
docs/reference/js/lessons/die-roll.md
Normal file
@ -0,0 +1,91 @@
|
||||
# die roll lesson
|
||||
|
||||
create a die on the BBC micro:bit #button #pressed #math #random #var #string #if #docs
|
||||
|
||||
## Topic
|
||||
|
||||
If (Conditionals)
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/microbit/lessons/die-roll/activity)
|
||||
* [challenges](/microbit/lessons/die-roll/challenges)
|
||||
* [quiz](/microbit/lessons/die-roll/quiz)
|
||||
* [quiz answers](/microbit/lessons/die-roll/quiz-answers)
|
||||
* [tutorial](/microbit/lessons/die-roll/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a die with If statements, On Shake, Variables, Assignment Operator, Pick Random and Show LEDs
|
||||
|
||||
## Documentation
|
||||
|
||||
* **Variables** : [read more...](/microbit/reference/variables/var)
|
||||
* **If** : [read more...](/microbit/reference/logic/if)
|
||||
* **On Shake** : [read more...](/microbit/reference/input/on-gesture)
|
||||
* **Assignment Operator** : [read more...](/microbit/reference/variables/assign)
|
||||
* **Math Random** : [read more...](/microbit/js/math)
|
||||
* **Show LEDs** : [read more...](/microbit/reference/basic/show-leds)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to run code when the BBC micro:bit is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
|
||||
* learn how to create a local variable as a place where you can store and retrieve data
|
||||
* learn how the assignment operator is used to declare a new local variable
|
||||
* learn how to declare a new local variable or update the value of a variable
|
||||
* learn how to return a random number
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to show an image on the LED screen
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Uses filters or can perform single criteria searches for information.(AL)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [activity](/microbit/lessons/die-roll/activity)
|
||||
* [tutorial](/microbit/lessons/die-roll/tutorial)
|
||||
* [quiz](/microbit/lessons/die-roll/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/die-roll/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/die-roll/challenges)
|
||||
|
130
docs/reference/js/lessons/die-roll/activity.md
Normal file
130
docs/reference/js/lessons/die-roll/activity.md
Normal file
@ -0,0 +1,130 @@
|
||||
# die roll activity
|
||||
|
||||
Create a die on the BBC micro:bit
|
||||
|
||||
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **KindScript**.
|
||||
|
||||
Let's create a condition for when the BBC micro:bit is shaken.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
})
|
||||
```
|
||||
|
||||
We need to show a random value from 1 to 6 on our die. So let's make a local variable called **roll**.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6)
|
||||
})
|
||||
```
|
||||
|
||||
We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `Show LEDs` to display the side of a die that shows 6.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll1 = Math.random(6)
|
||||
if (roll1 == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the die.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll2 = Math.random(6)
|
||||
if (roll2 == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`, 400)
|
||||
} else if (roll2 == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the die. Let's also repeat these steps to show the 3, 2, and 1 on the die. We are almost done with our die!
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll3 = Math.random(6)
|
||||
if (roll3 == 5) {
|
||||
basic.showLeds(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`, 400)
|
||||
} else if (roll3 == 4) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
else if (roll3 == 3) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
else if (roll3 == 2) {
|
||||
basic.showLeds(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`, 400)
|
||||
}
|
||||
else if (roll3 == 1) {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
else {
|
||||
basic.showLeds(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/die-roll/challenges)!
|
||||
|
||||
### ~
|
||||
|
201
docs/reference/js/lessons/die-roll/challenges.md
Normal file
201
docs/reference/js/lessons/die-roll/challenges.md
Normal file
@ -0,0 +1,201 @@
|
||||
# die roll challenges
|
||||
|
||||
Create a die on the BBC micro:bit.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/die-roll/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll = Math.random(6) // ***
|
||||
if (roll == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
else if (roll == 1) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Modify the line of code with `math->random` so that only number 1-4 can appear on the die.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll1 = Math.random(4) // ***
|
||||
if (roll1 == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll1 == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll1 == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll1 == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
else if (roll1 == 1) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's make a trick die! Modify the line of code with `math->random` so that only numbers 3-6 can appear on the die. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let roll2 = Math.random(4) + 2 // ***
|
||||
if (roll2 == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll2 == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 1) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . . .
|
||||
. . . . .
|
||||
. . . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
else if (roll2 == 0) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add a couple more conditions so that the BBC micro:bit randomly chooses a number between 1 and 8.
|
||||
|
116
docs/reference/js/lessons/die-roll/quiz-answers.md
Normal file
116
docs/reference/js/lessons/die-roll/quiz-answers.md
Normal file
@ -0,0 +1,116 @@
|
||||
# die roll quiz answers
|
||||
|
||||
Create a die when the BBC micro:bit is shaken
|
||||
|
||||
These are the answers to the [die roll quiz](/microbit/lessons/die-roll/quiz).
|
||||
|
||||
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let roll = Math.random(6)
|
||||
```
|
||||
|
||||
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (roll == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (roll == 5) {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
`)
|
||||
} else if (roll == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
||||
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (roll == 4) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
} else if (roll == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
||||
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (roll == 3) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
. # . # .
|
||||
. . . . .
|
||||
`)
|
||||
} else if (roll == 2) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
||||
|
42
docs/reference/js/lessons/die-roll/quiz.md
Normal file
42
docs/reference/js/lessons/die-roll/quiz.md
Normal file
@ -0,0 +1,42 @@
|
||||
# die roll quiz
|
||||
|
||||
Create a die when the BBC micro:bit is shaken
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [die roll tutorial](/microbit/lessons/die-roll/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
91
docs/reference/js/lessons/digi-yoyo.md
Normal file
91
docs/reference/js/lessons/digi-yoyo.md
Normal file
@ -0,0 +1,91 @@
|
||||
# digi yoyo lesson
|
||||
|
||||
create a counter with a while loop #while #loop #counter #docs
|
||||
|
||||
### @video td/videos/digi-yoyo-0
|
||||
|
||||
## Topic
|
||||
|
||||
While Loop
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/microbit/lessons/digi-yoyo/tutorial)
|
||||
* [quiz](/microbit/lessons/digi-yoyo/quiz)
|
||||
* [quiz answers](/microbit/lessons/digi-yoyo/quiz-answers)
|
||||
* [challenges](/microbit/lessons/digi-yoyo/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to creating a **while loop**, `while condition do` to repeat code while a condition is true. We will be learning how to create a digi yoyo app using a while loop, a variable, as well as basic commands, such as pause and show number.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **local variables** : [read more...](/microbit/reference/variables/var)
|
||||
* **assignment operator** : [read more...](/microbit/reference/variables/assign)
|
||||
* **while loop** : [read more...](/microbit/js/while)
|
||||
* **relational operator ** : [read more...](/microbit/reference/types/number)
|
||||
* **pause** : [read more...](/microbit/reference/basic/pause)
|
||||
* **show number** : [read more...](/microbit/reference/basic/show-number)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a local variables to store data and use it in your code
|
||||
* learn how to set or change the value of a local variable
|
||||
* learn how to repeat code while a condition is true
|
||||
* learn how a relational comparison (<) of numbers will yield a Boolean
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
* learn how to show a number on the LED screen
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL)
|
||||
* Recognises that different algorithms exist for the same problem (AL) (GE)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Uses filters or can perform single criteria searches for information.(AL)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/digi-yoyo/tutorial)
|
||||
* [quiz](/microbit/lessons/digi-yoyo/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/digi-yoyo/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/digi-yoyo/challenges)
|
||||
|
65
docs/reference/js/lessons/digi-yoyo/challenges.md
Normal file
65
docs/reference/js/lessons/digi-yoyo/challenges.md
Normal file
@ -0,0 +1,65 @@
|
||||
# digi yoyo challenges
|
||||
|
||||
Coding challenges for the digi yoyo.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/digi-yoyo/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
let count = 0
|
||||
while (count < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count, 150)
|
||||
count = count + 1
|
||||
}
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
```
|
||||
let count1 = 0
|
||||
while (count1 < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count1, 150)
|
||||
count1 = count1 + 1
|
||||
}
|
||||
while (count1 > 0) {
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/digi-yoyo-1-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`!
|
||||
|
||||
```
|
||||
let count2 = 0
|
||||
while (count2 < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count2, 150)
|
||||
count2 = count2 + 1
|
||||
}
|
||||
while (count2 > 0) {
|
||||
basic.pause(1000) // ***
|
||||
basic.showNumber(count2, 150) // ***
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now, we need `count` to decrease by one after the BBC micro:bit has displayed the value of `count`.
|
||||
|
||||
We can do this by adding this line:
|
||||
|
||||
`count := count - 1`
|
||||
|
34
docs/reference/js/lessons/digi-yoyo/quiz-answers.md
Normal file
34
docs/reference/js/lessons/digi-yoyo/quiz-answers.md
Normal file
@ -0,0 +1,34 @@
|
||||
# digi yoyo quiz answers
|
||||
|
||||
Answers for digi yoyo quiz.
|
||||
|
||||
This is the answer key for the [digi yoyo quiz](/microbit/lessons/digi-yoyo/quiz).
|
||||
|
||||
## 1. Describe what a "while loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
A loop that repeats code while a condition is true.
|
||||
|
||||
## 2. Write the code that will create a **variable** called `count` and set the variable to 0.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let count = 0
|
||||
```
|
||||
|
||||
## 3. Create a `while loop` that will loop until the **variable** `count` equals 4.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
while (count < 5) {
|
||||
count = count + 1
|
||||
}
|
||||
```
|
||||
|
28
docs/reference/js/lessons/digi-yoyo/quiz.md
Normal file
28
docs/reference/js/lessons/digi-yoyo/quiz.md
Normal file
@ -0,0 +1,28 @@
|
||||
# digi yoyo quiz
|
||||
|
||||
Create a counter with a while loop
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digi yoyo tutorial](/microbit/lessons/digi-yoyo/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what a "while loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that will create a variable called count and set the variable to 0.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code for a while loop that will loop until the variable count equals 4.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
133
docs/reference/js/lessons/digital-pet.md
Normal file
133
docs/reference/js/lessons/digital-pet.md
Normal file
@ -0,0 +1,133 @@
|
||||
# digital pet lesson
|
||||
|
||||
a display of pet images for the BBC micro:bit #functions #number #forever #button #string #pause #data #shake #docs
|
||||
|
||||
### @video td/videos/digital-pet-0
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/microbit/lessons/digital-pet/tutorial)
|
||||
* [quiz](/microbit/lessons/digital-pet/quiz)
|
||||
* [quiz answers](/microbit/lessons/digital-pet/quiz-answers)
|
||||
* [challenges](/microbit/lessons/digital-pet/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a digital pet app using functions, global variables, forever loop, input button in pressed, input on shake as well as simple commands, such as show string, show number, and pause.
|
||||
|
||||
## 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.
|
||||
* 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.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* 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.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **function** : [read more...](/microbit/js/function)
|
||||
* **call** : [read more...](/microbit/js/call)
|
||||
* **global variable** : [read more...](/microbit/js/data)
|
||||
* **assignment operator** : [read more...](/microbit/reference/variables/assign)
|
||||
* **forever** : [read more...](/microbit/reference/basic/forever)
|
||||
* **button is pressed** : [read more...](/microbit/reference/input/button-is-pressed)
|
||||
* **show string** : [read more...](/microbit/reference/basic/show-string)
|
||||
* **show number** : [read more...](/microbit/reference/basic/show-number)
|
||||
* **create image** : [read more...](/microbit/reference/images/create-image)
|
||||
* **show image** : [read more...](/microbit/reference/images/show-image)
|
||||
* **pause** : [read more...](/microbit/reference/basic/pause)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/digital-pet/tutorial)
|
||||
* Activity: [quiz](/microbit/lessons/digital-pet/quiz)
|
||||
* Extended Activity: [challenges](/microbit/lessons/digital-pet/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a function as a unit of code that performs a specific task and returns a result
|
||||
* learn how to call an existing function in your script
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to set or change the value of a global variable
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to get the state of an input button
|
||||
* learn how to show a number on the micro:bit's LED screen
|
||||
* learn how to show a string on the micro:bit's LED screen
|
||||
* learn how to create an image to show on the micro:bit's LED screen
|
||||
* learn how to show an image on the micro:bit's LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/digital-pet/tutorial)
|
||||
* [quiz](/microbit/lessons/digital-pet/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/digital-pet/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/digital-pet/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
129
docs/reference/js/lessons/digital-pet/challenges.md
Normal file
129
docs/reference/js/lessons/digital-pet/challenges.md
Normal file
@ -0,0 +1,129 @@
|
||||
# digital pet challenges
|
||||
|
||||
Coding challenges for the digital pet tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/digital-pet/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now let's feed the pet! Add an **ELSE IF** statement that checks if button `B` is pressed. Click on the **ELSE** and type **IF** next to it to get the **ELSE IF**.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/digital-pet-2
|
||||
|
||||
Now we want to show your eating pet! Let's create a function called `set eat` that will do create an image. Store that image in a variable and then show it.
|
||||
|
||||
```
|
||||
export function setEat() {
|
||||
let img = images.createImage(`
|
||||
. # . # .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
}
|
||||
```
|
||||
|
||||
Once you create the function `set eat`, call it in the **ELSE IF** statement that checks if button `B` is pressed.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
setEat()
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/digital-pet-3
|
||||
|
||||
Have your pet tell you when it is going to sleep! Do this inside of the **IF** statement that checks if button `A` is pressed before you call the function `set sleep`.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
basic.showString("I am going to sleep.", 150) // ***
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
setEat()
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
### @video td/videos/digital-pet-4
|
||||
|
||||
Now, how about we keep track of how many times our pet eats? Add a global variable called `feed` that keeps track of how many times you feed your pet. If button `B` is pressed, increment `feed` by one. Add a condition `on shake` to check your total.
|
||||
|
||||
```
|
||||
feed = 0 // ***
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
basic.showString("I am going to sleep.", 150)
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
feed = feed + 1 // ***
|
||||
setEat()
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showNumber(feed, 150) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Challenge 5
|
||||
|
||||
Program your pet to say that it is hungry after 60 seconds.
|
||||
|
||||
**Hint**: use `input->running time`
|
||||
|
60
docs/reference/js/lessons/digital-pet/quiz-answers.md
Normal file
60
docs/reference/js/lessons/digital-pet/quiz-answers.md
Normal file
@ -0,0 +1,60 @@
|
||||
# digital pet quiz answers
|
||||
|
||||
A display of pet images for the BBC micro:bit
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digital pet tutorial](/microbit/lessons/digital-pet/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
<br/>
|
||||
|
||||
A function is a unit of code that performs a specific task and may return a result.
|
||||
|
||||
## 2. Write the steps to create the function called set awake()
|
||||
|
||||
<br/>
|
||||
|
||||
Click on "+ add new" and then "function". Click on the function name (by default it is "set awake"), and rename it to "set awake()".
|
||||
|
||||
## 3. Write the code inside the function "set awake()" that shows an image of the pet awake
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let img = images.createImage(`
|
||||
. # . # .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
```
|
||||
|
||||
## 4. Write the steps to create the function called set sleep, function set sleep()
|
||||
|
||||
<br/>
|
||||
|
||||
Click on "+ add new" and then "function". Click on the function name (by default it is "set sleep"), and rename it to "set sleep()".
|
||||
|
||||
## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
img = images.createImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
```
|
||||
|
32
docs/reference/js/lessons/digital-pet/quiz.md
Normal file
32
docs/reference/js/lessons/digital-pet/quiz.md
Normal file
@ -0,0 +1,32 @@
|
||||
# digital pet quiz
|
||||
|
||||
A display of pet images for the BBC micro:bit
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digital pet tutorial](/microbit/lessons/digital-pet/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the steps to create the function called set awake()
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code inside the function "set awake()" that shows an image of the pet awake
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the steps to create the function called set sleep, function set sleep()
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep
|
||||
|
||||
<br/>
|
||||
|
93
docs/reference/js/lessons/flashing-heart.md
Normal file
93
docs/reference/js/lessons/flashing-heart.md
Normal file
@ -0,0 +1,93 @@
|
||||
# flashing heart lesson
|
||||
|
||||
Learn how to create LED images with a global variable. #LED #screen #plot #docs
|
||||
|
||||
### @video td/videos/flashing-heart-0
|
||||
|
||||
## Topic
|
||||
|
||||
Pause
|
||||
|
||||
## Quick links
|
||||
|
||||
* [activity](/microbit/lessons/flashing-heart/activity)
|
||||
* [quiz](/microbit/lessons/flashing-heart/quiz)
|
||||
* [quiz answers](/microbit/lessons/flashing-heart/quiz-answers)
|
||||
* [challenges](/microbit/lessons/flashing-heart/challenges)
|
||||
* [tutorial](/microbit/lessons/flashing-heart/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to **plot image** by turning on a series of LED lights on the LED screen. We will be learning how to create a blinking app using a forever loop as well as simple commands, such as plot image, pause, and clear screen.
|
||||
|
||||
## What the teacher needs to know / QuickStart Computing Glossary
|
||||
|
||||
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.**
|
||||
|
||||
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem**
|
||||
|
||||
**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever.
|
||||
|
||||
**Command:** An instruction for the computer to execute, written in a particular programming language.**
|
||||
|
||||
## Documentation
|
||||
|
||||
* **forever**: [read more...](/microbit/reference/basic/forever)
|
||||
* **plot image** : [read more...](/microbit/reference/led/plot-image)
|
||||
* **pause**: [read more...](/microbit/reference/basic/pause)
|
||||
* **clear screen**: [read more...](/microbit/reference/basic/clear-screen)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to turn on a series of LED lights on the LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
* learn how to turn off all the LED lights on the LED screen
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
* Represents solutions using a structured notation. (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
* Declares and assigns variables.(AB)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Exercise
|
||||
|
||||
* time: 20 min.
|
||||
* [activity](/microbit/lessons/flashing-heart/activity) or [tutorial](/microbit/lessons/flashing-heart/tutorial)
|
||||
* [quiz](/microbit/lessons/flashing-heart/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/flashing-heart/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
63
docs/reference/js/lessons/flashing-heart/activity.md
Normal file
63
docs/reference/js/lessons/flashing-heart/activity.md
Normal file
@ -0,0 +1,63 @@
|
||||
# flashing heart activity
|
||||
|
||||
Ccontrol images with variables.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/flashing-heart-0
|
||||
|
||||
In this activity, you will learn how to blink an image on the LED screen.
|
||||
|
||||
### ~
|
||||
|
||||
To create a new script, go to the [Create Code](https://www.microbit.co.uk/create-code) page and tap `New Project` under **KindScript**.
|
||||
|
||||
Let's start by adding code that plots a heart image on the screen using `basic->plot image`. Once you are done coding, don't forget to run your code in the simulator or the BBC micro:bit.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`) // ***
|
||||
```
|
||||
|
||||
We want to leave the image on the screen for 0.5 seconds (500 milliseconds), then clear the screen. We can use `basic->pause` to wait and `basic->clear screen` to turn off the LEDs.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500) // ***
|
||||
basic.clearScreen() // ***
|
||||
```
|
||||
|
||||
Finally, we can surround this code with a `basic->forever` loop to repeat it and add a pause after `basic->clear screen` to keep the screen off for a little while. Modify your code so that your code looks like this.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/flashing-heart/challenges)!
|
||||
|
||||
### ~
|
||||
|
93
docs/reference/js/lessons/flashing-heart/challenges.md
Normal file
93
docs/reference/js/lessons/flashing-heart/challenges.md
Normal file
@ -0,0 +1,93 @@
|
||||
# flashing heart challenges
|
||||
|
||||
Coding challenges for flashing heart.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [flashing heart](/microbit/lessons/flashing-heart/activity) activity and your code will look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/flashing-heart-1
|
||||
|
||||
Let's plot a different image. Let's display a broken heart!
|
||||
|
||||
To do this, you need to **add a line** between the last line and the end loop. Plot the image of the broken heart and then add a pause of 500 milliseconds.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.plotImage(`
|
||||
# # . # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`) // ***
|
||||
basic.pause(500) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* click `run main` to see if the code works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/flashing-heart-2
|
||||
|
||||
Now let's alternate flashing the heart and the broken heart. To do this, we need to clear the screen and then add a pause of 500 milliseconds under the new code we added in Challenge 1.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.plotImage(`
|
||||
# # . # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen()
|
||||
basic.pause(500)
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
# . # # #
|
||||
# . . # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
basic.pause(500)
|
||||
basic.clearScreen() // ***
|
||||
basic.pause(500) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* click `run main` to see if the code works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
You now have a heart and broken heart flashing! Now plot a new image to alternate in with the heart and broken heart.
|
||||
|
102
docs/reference/js/lessons/flashing-heart/lesson-plan.md
Normal file
102
docs/reference/js/lessons/flashing-heart/lesson-plan.md
Normal file
@ -0,0 +1,102 @@
|
||||
# flashing heart lesson plan
|
||||
|
||||
Learn how to create LED images with a variable.
|
||||
|
||||
### @video vimeo/134118661
|
||||
|
||||
## Topic
|
||||
|
||||
Global Variable - Blinking Images
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to control a blinking LED image. We will be learning how to create a blinking app using global variables, forever as well as simple commands, such as create image, show image, pause, and clear screen.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.**
|
||||
|
||||
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem**
|
||||
|
||||
**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever.
|
||||
|
||||
**Command:** An instruction for the computer to execute, written in a particular programming language.**
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **global variables**: [read more...](/microbit/js/data)
|
||||
* **create image** : [read more...](/microbit/reference/images/create-image)
|
||||
* **show image** : [read more...](/microbit/reference/images/show-image)
|
||||
* **pause**: [read more...](/microbit/reference/basic/pause)
|
||||
* **clear screen**: [read more...](/microbit/reference/basic/clear-screen)
|
||||
* **forever**: [read more...](/microbit/reference/basic/forever)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/microbit/lessons/flashing-heart/tutorial)
|
||||
* Activity: [quiz](/microbit/lessons/flashing-heart/quiz)
|
||||
* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a global variable
|
||||
* learn how to blink a light
|
||||
* learn how to repeat turning on and off the light
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Assessment
|
||||
|
||||
### Progression Pathways
|
||||
|
||||
### Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
* Represents solutions using a structured notation. (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
* Declares and assigns variables.(AB)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/microbit/lessons/flashing-heart/tutorial)
|
||||
* [quiz](/microbit/lessons/flashing-heart/quiz)
|
||||
* assessment opportunities: forever, plot, pause, clear screen
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/microbit/lessons/flashing-heart/challenges)
|
||||
* assessment opportunities: loops, plot, pause, clear screen
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user