removing olddocs folder

This commit is contained in:
Peli de Halleux 2017-03-16 07:58:13 -07:00
parent 00e9217e73
commit 32de33241e
139 changed files with 0 additions and 10568 deletions

View File

@ -1,67 +0,0 @@
# Bits Library
Functions in the Bits library.
### @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](/javascript/editor), click `bits` to see the following bit functions:
## Bitwise and, or, and xor functions
#### Syntax
bits `->` *and/or/xor* uint32 (x : [Number](/types/number), y : [Number](/types/number)) *returns* [Number](/types/number)
#### Parameters
* x - an unsigned 32 bit integer [Number](/types/number)
* y - another unsigned 32 bit integer [Number](/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](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number)
bits `->` rotate right unint32 (x : [Number](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number)
#### Parameters
* x - [Number](/types/number);
* bits - [Number](/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](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number)
bits `->` shift right unint32 (x : [Number](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number)
#### Parameters
* x - [Number](/types/number);
* bits - [Number](/types/number);
### See also
[statements and operators](/javascript/statements), [math functions](/javascript/math), [Number](/types/number)

View File

@ -1,33 +0,0 @@
# Break
Break statement; exit a for or while loop.
### @parent javascript/language
Exit a [while](/javascript/while) or [for](/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)
}
}
```
### See also
[for](/reference/loops/for), [while](/javascript/while)

View File

@ -1,63 +0,0 @@
# Call a Function
How to call a function in your code.
### @parent javascript/language
Type a function name in your code to call an existing [function](/javascript/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](/javascript/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](/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](/javascript/functionparameters), [create a function](/javascript/function), [return statement](/javascript/return)

View File

@ -1,31 +0,0 @@
# function
A function with inputs and outputs.
### @parent javascript/language
To add a **functions** to your script, click the `script` button, then click the `+` `add new function` button
### functions
A **function** takes [inputs](/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](/libraries).

View File

@ -1,111 +0,0 @@
# 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(Button.A, () => {
accelerations.push(input.acceleration("x"))
})
input.onButtonPressed(Button.B, () => {
for (let i1 = 0; i1 < accelerations.length; i1++) {
basic.showString(accelerations[i1].toString(), 150)
}
accelerations.clear()
})
```

View File

@ -1,68 +0,0 @@
# Comment
A note in code.
### @parent javascript/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).
### 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 {
return x * x
}
```
### 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](/blocks/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](/javascript/comment) at the beginning of a library to describe the library
* Use [comments](/javascript/comment) at the beginning of a [function](/javascript/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](/javascript/markdown), [Touch Develop editor](/javascript/editor)

View File

@ -1,30 +0,0 @@
# In-browser compiler
The @boardname@ pins.
## 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 @boardname@ compilation process (see page 10 in the Quick Start book) has been updated below to reflect the new compiler architecture, shown below.
![](/static/mb/offline-2.png)
The C++ compiler now only is used to compile the @boardname@ runtime - this is done offline by the @boardname@ team and the precompiled runtime linked with your compiled script in the browser.
## Save and load code using files
![](/static/mb/offline-0.png)
The @boardname@ 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.
![](/static/mb/offline-1.png)
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.

View File

@ -1,211 +0,0 @@
# @boardname@/JavaScript Documentation
JavaScript docs for the @boardname@
### @section full
### @parent reference
### @short JavaScript
### ~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 @boardname@. Below you will find resources about the Touch Develop programming language and code editor. Good places to start include:
* [the Touch Develop Editor](/js/editor)
* [30+ @boardname@ lessons](/lessonss)
* [offline support](/offline)
### ~column
## Language {#pconst}
### Variables
* [local variables](/reference/variables/var)
* [global variables ](/js/data)
### Types
* [Number](/types/number)
* [Boolean](/types/boolean)
* [String](/types/string)
* [Image](/reference/images/image)
### Statements and control structures
* [assignment operator](/reference/variables/assign) `:=`
* [if](/reference/logic/if)
* [for](/reference/loops/for)
* [while](/js/while)
* [break](/js/break)
* [forever](/reference/basic/forever)
* [in background](/reference/control/in-background)
* [function](/js/function)
* [return](/js/return)
### Maths
* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [Numbers](/types/number)
* comparison operators (such as `>`, `=`) on [Numbers](/types/number)
* the [math](/js/math) library
* the [bits](/js/bits) library
### Logical
* [Boolean](/types/boolean) values `true` and `false`
* Operations (`not`, `or`, `and`) on [Booleans](/types/boolean)
### Strings
* [string functions](/types/string-functions)
### Functions
* [create a function](/js/function)
* [function parameters](/js/functionparameters)
* [call a function](/js/call)
### Collections
* read the [collections tutorial](/js/collections)
### Custom object types
* see the [object types tutorial](/js/object-types)
* read the [object disclaimer](/js/object-disclaimer) if you're an advanced user
### Libraries
* [create and use libraries](/js/libraries)
### Documentation
* [comments](/js/comment)
* [markdown syntax](/js/markdown)
### ~
### ~column
## @boardname@ functions
### Basic
* [clear screen](/reference/basic/clear-screen)
* [forever](/reference/basic/forever)
* [pause](/reference/basic/pause)
* [show leds](/reference/basic/show-leds)
* [show animation](/reference/basic/show-animation)
* [show number](/reference/basic/show-number)
* [show string](/reference/basic/show-string)
### LED
* [brightness](/reference/led/brightness)
* [fade in](/reference/led/fade-in)
* [fade out](/reference/led/fade-out)
* [plot](/reference/led/plot)
* [plot all](/reference/led/plot-all)
* [point](/reference/led/point)
* [screenshot](/functions/screenshot)
* [set display mode](/functions/set-display-mode)
* [set brightness](/reference/led/set-brightness)
* [stop animation](/reference/led/stop-animation)
* [toggle](/reference/led/toggle)
* [toggle all](/reference/led/toggle-all)
* [unplot](/reference/led/unplot)
### Input
* [acceleration](/reference/input/acceleration)
* [rotation](/functions/rotation)
* [button is pressed](/reference/input/button-is-pressed)
* [compass heading](/reference/input/compass-heading)
* [temperature](/reference/input/temperature)
* [running time](/reference/input/running-time)
* [on shake](/reference/input/on-gesture)
* [on button pressed](/reference/input/on-button-pressed)
* [on pin pressed](/reference/input/on-pin-pressed)
* [pin is pressed](/reference/input/pin-is-pressed)
### Image
* [create image](/reference/images/create-image)
* [clear](/reference/basic/clear-screen)
* [pixel](/reference/images/pixel)
* [plot frame](/reference/led/plot-frame)
* [plot image](/reference/led/plot-image)
* [scroll image](/reference/images/scroll-image)
* [show frame](/functions/show-frame)
* [set pixel](/reference/images/set-pixel)
* [show image](/reference/images/show-image)
* [width](/functions/width)
### Music
* [play note](/functions/play-note)
* [note](/functions/note)
* [ring](/reference/music/ring)
### Pins
* [digital read pin](/reference/pins/digital-read-pin)
* [digital write pin](/reference/pins/digital-write-pin)
* [analog read pin](/reference/pins/analog-read-pin)
* [analog write pin](/reference/pins/analog-write-pin)
* [analog set period](/reference/pins/analog-set-period)
* [analog pitch](/reference/pins/analog-pitch)
* [analog set pitch pin](/reference/pins/analog-set-pitch-pin)
* [servo write pin](/reference/pins/servo-write-pin)
* [servo set pulse](/reference/pins/servo-set-pulse)
* [map](/functions/map)
### Control
* [in background](/reference/control/in-background)
* [reset](/functions/reset)
### Devices
Functions in this category require to be connected to a remote device.
* [tell camera to](/reference/devices/tell-camera-to)
* [tell remote control to](/reference/devices/tell-remote-control-to)
* [raise alert to](/reference/devices/raise-alert-to)
* [on notified](/reference/devices/on-notified)
### Libraries
* [serial library](/js/serial-library)
### ~
### ~column
## Run
* [scripts in the browser](/js/simulator)
* [scripts on your @boardname@](/device/usb)
## Debugging
* use the [serial library](/js/serial-library) to print data from your @boardname@ on your computer
* learn about the [device error codes](/device/errors) that are displayed when sad faces occur
## Edit/Publish
* [the Touch Develop Editor](/js/editor)
* [publish a script](/js/publishing)
## Creating Tutorials
* [create a tutorial](/js/create-tutorials)
* [markdown syntax](/js/markdown)
### ~

View File

@ -1,58 +0,0 @@
# event handler
Event handlers - how they work.
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(Button.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(Button.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(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonPressed(Button.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(Button.A, () => {
basic.showString("hello", 150)
basic.showString("goodbye", 150)
})
```
### To learn more
To learn more about how the @boardname@ queues up and schedules event handlers, see [the @boardname@ - a reactive system](/device/reactive)
### see also
[on button pressed](/reference/input/on-button-pressed)

View File

@ -1,79 +0,0 @@
# Events Library
The functions in the events namespace allow the @boardname@ 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 @boardname@ 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

View File

@ -1,81 +0,0 @@
# For
Repeat code a preset number of times.
### @parent javascript/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](/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](/js/break) statement exits a loop before the end value is reached.
### ~
### Lessons
[looper](/lessons/looper), [strobe light](/lessons/strobe-light)
### See also
[while](/js/while), [break](/js/break), [if](/reference/logic/if)

View File

@ -1,117 +0,0 @@
# Create a Function
How to define a function with input and output parameters.
### @parent javascript/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](/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](/js/functionparameters)
* the function *body* (the code that performs a task)
- one or more [return](/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](/js/functionparameters) ([Number](/types/number) type)
* ``result`` is the [output parameter](/js/functionparameters) ([Number](/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](/js/types) to change the variable type. For more info, see [function parameters](/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](/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](/lessons/digital-pet)
### See also
[function parameters](/js/functionparameters), [call a function](/js/call), [return from a function](/js/return)

View File

@ -1,66 +0,0 @@
# Function Parameters
How to use parameters to pass info in and out of an function.
### @parent javascript/function
A [function](/js/function) can have multiple input parameters and/or a single output parameter. The parameters must be one of the supported variable [types](/js/types).
When you first [create a function](/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](/types/number):
```
export function oneInput(p: number) {
}
```
To change the default type, click the type ([Number](/types/number) in this case) and change it to [String](/types/string), [Boolean](/types/boolean), or [Image](/reference/image/image). You can add multiple input parameters to a function.
#### Output parameter
the default type for an output parameter is [Number](/types/number):
```
export function output() : number {
let r: number
return 42
return r
}
```
To change the default type, click the type ([Number](/types/number) in this case) and change it to [String](/types/string), [Boolean](/types/boolean), or [Image](/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](/js/call), [create a function](/js/function), [return](/js/return)

View File

@ -1,105 +0,0 @@
# Gallery
Overview of Touch Develop lessons for the @boardname@.
### @short Gallery
### ~column
## Maker
* [Telegraph](/pzeagwoudd), play the telegraph game between 2 @boardname@s
* [Ornament Chain](/rnvpgo), play the ornament chain game between 2 @boardname@s
### ~hide
* [The Watch](/lessons/the-watch), design and create The Watch
* [Hack your headphones](/lessons/hack-your-headphones), create music on the @boardname@ by hacking your headphones
* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits
### ~
## Beginner
* [Night light](/vltwrzuqto), dim the LEDs with set brightness
* [Beautiful image](/nudwzmphyx), show a beautiful image with show LEDs
* [Smiley,](/zsohipimef) smiley and frowney with show animation
* [Lucky 7](/rqhxxqppqu), show a number on the LED screen with show number
* [Answering machine](/bnkmeqymuh), show a text message with show string
* [Snowflake fall](/zhcfmiejlg), repeat an animation with forever
* [Screen wipe](/hlnitnqjjk), turn off the LEDs with clear screen
* [Flashing heart](/bwmxfwqswx), display images with a pause
* [Blink](/jbbutifslm), turn an LED on and off with plot
### ~hide
* [Magic logo](/lessons/magic-logo), show an image on logo up
* [Glowing sword](/lessons/glowing-sword), make a glowing sword with fade in and fade out
### ~
### ~column
## Intermediate
* [Zoomer](/fwrohhjqql), measure the force with acceleration
* [Strobe light](/jguqlzeayr), develop shapes with a nested for loops
* [Digi yoyo](/lppocrbpys), create a counter with a while loop
* [Die roll](/lzblatmknq), spin with more if statements
* [Spinner](/dzijduruek), spin the arrow with multiple if statements
* [Truth or dare](/filuzbwauo), a game that forces each player to reveal a secret or do something funny with if statement
* [Love meter](/rrmlrvojfa), create a love meter with on pin pressed
* [Guess the number](/ftsenbvqwz), guess a random number with random
* [Magic 8](/fyjinpjuqu), a fortune teller game with the @boardname@
* [Counter](/rerlmjgjut), display a number with a variable
* [Glowing pendulum](/xrnsveuwxj), construct a pendulum that glows using acceleration
* [Looper](/nxcddtbizi), display a series of numbers with a for loop index
### ~hide
* [Rotation animation](/lessons/rotation-animation), control an animation with a boolean variable
* [Offset image](/lessons/offset-image), shift an image horizontally with image offset
* [Compass](/lessons/compass), displays the direction the @boardname@ is pointing
### ~
### ~column
## Advanced
* [Rock paper scissors](/tnmtbvyyma), use image offsets with local variables
* [Digital pet](/vefocoajpb), a display of pet images with sub-functions
* [Catch the egg](/reczlreqob), catch falling eggs in a basket with an acceleration controller
* [Headbands](/bzrusu), create a charades game with a collection of strings that hold the words
* [Prank WiFi](/dceikq), create fake WiFi to trick your friends
* [Flipping bird](/lbhvywjzkv), use modulo with a conditional
* [Runaway pac man](/loafab), construct the game pac man with the @boardname@
* [Line of Fire](/fzcoly), make a game to test hand-eye coordination
* [The hat game](/njynsd), make a game to test your focus on the moving ball
* [Pong](/xcenyy), a light bouncing from left to right
* [Meteorite](/zaidka), a game where meteorites are coming for you one by one
* [Minesweeper](/jaeeve), make a game to test your memory for placing a LED mine then finding the hidden LED mine
* [Bop it](/zlpndm), a game where you have to keep up with the commands
* [Letter Up](/ftlqjo), a guessing game with string operators with string at
* [Racing Buttons](/hcuxid), racing game to determine if player 1 presses Button A faster or if player 2 presses Button B faster
### ~hide
* [Transformers](/lessons/transformers), use functions to return values
* [Speed button](/lessons/speed-button), code a speed game with running time
* [Jailbreak](/lessons/jailbreak), break out of a counting loop by pressing button "A"
* [2 player pong](/bzycll), collaborate with a classmate to develop Pong on multiple @boardname@s
### ~
### ~hide
* [Number psych](/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple @boardname@s and a breadboard
### ~
### @section full
The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach)

View File

@ -1,153 +0,0 @@
# Game Library
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(Button.A, () => {
game.addScore(1)
})
game.startCountdown(10000)
```
### [Countdown](/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](/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](/js/game-library/add-point-to-score)
* add score points to the current score
```
export function addScore(points: number)
```
[Score](/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](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter)

View File

@ -1,11 +0,0 @@
# game
A #microbit game library.
Gets the current score
```
init()
return _score
```

View File

@ -1,88 +0,0 @@
# Game Tutorials
Overview of Games for the @boardname@.
### @short Games
### ~column
## Beginner Games
* [The Watch](/lessons/the-watch/activity), design and create The Watch
* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits
### ~hide
* [Smiley,](/lessons/smiley) smiley and frowney with show animation
* [Lucky 7](/lessons/lucky-7), show a number on the LED screen with show number
* [Snowflake fall](/lessons/snowflake-fall), repeat an animation with forever
* [Answering machine](/lessons/answering-machine), show a text message with show string
* [Magic logo](/lessons/magic-logo), show an image on logo up
* [Screen wipe](/lessons/screen-wipe), turn off the LEDs with clear screen
* [Blink](/lessons/blink), turn an LED on and off with plot
* [Flashing heart](/lessons/flashing-heart/tutorial), display images with a pause
### ~
* [Night light](/lessons/night-light/tutorial), dim the LEDs with set brightness
* [Glowing sword](/lessons/glowing-sword/tutorial), make a glowing sword with fade in and fade out
* [Guess the number](/lessons/guess-the-number/tutorial), guess a random number with random
* [Rock paper scissors](/lessons/rock-paper-scissors/tutorial), use image offsets with local variables
* [Counter](/lessons/counter/tutorial), display a number with a variable
* [Love meter](/lessons/love-meter/tutorial), create a love meter with on pin pressed
### ~column
## Intermediate Games
* [Truth or dare](/lessons/truth-or-dare/tutorial), a game that forces each player to reveal a secret or do something funny with if statement
* [Spinner](/lessons/spinner/tutorial), spin the arrow with multiple if statements
* [Die roll](/lessons/die-roll/tutorial), spin with more if statements
* [Looper](/lessons/looper/tutorial), display a series of numbers with a for loop index
* [Strobe light](/lessons/strobe-light/tutorial), develop shapes with a nested for loops
* [Digi yoyo](/lessons/digi-yoyo/tutorial), create a counter with a while loop
* [Magic 8](/lessons/magic-8/tutorial), a fortune teller game with the @boardname@
* [Compass](/lessons/compass/tutorial), displays the direction the @boardname@ is pointing
* [Speed button](/lessons/speed-button/tutorial), code a speed game with running time
### ~hide
* [Zoomer](/lessons/zoomer/tutorial), measure the force with acceleration
* [Rotation animation](/lessons/rotation-animation/tutorial), control an animation with a boolean variable
* [Offset image](/lessons/offset-image/tutorial), shift an image horizontally with image offset
### ~
### ~column
## Advanced Games
### ~hide
* [Digital pet](/lessons/digital-pet/tutorial), a display of pet images with sub-functions
* [Jailbreak](/lessons/jailbreak/tutorial), break out of a counting loop by pressing button "A"
* [Transformers](/lessons/transformers/tutorial), use functions to return values
* [Flipping bird](/lessons/flipping-bird/tutorial), use modulo with a conditional
### ~
* [Catch the egg](/lessons/catch-the-egg-game/tutorial), catch falling eggs in a basket with an acceleration controller
* [Headbands](/lessons/headbands/tutorial), create a charades game with a collection of strings that hold the words
* [Pong](/lessons/pong/tutorial), a light bouncing from left to right
* [Meteorite](/lessons/meteorite/tutorial), a game where meteorites are coming for you one by one
* [Minesweeper](/lessons/minesweeper/tutorial), make a game to test your memory for placing a LED mine then finding the hidden LED mine
* [Bop it](/lessons/bop-it/tutorial), a game where you have to keep up with the commands
* [Letter Up](/lessons/letter-up/tutorial), a guessing game with string operators with string at
* [Prank WiFi](/lessons/prank-wifi/tutorial), create fake WiFi to trick your friends
* [Runaway pac man](/lessons/runaway-pacman/tutorial), construct the game pac man with the @boardname@
* [The hat game](/lessons/the-hat-game/tutorial), make a game to test your focus on the moving ball
* [2 player pong](/lessons/2-player-pong/tutorial), collaborate with a classmate to develop Pong on multiple @boardname@s
### ~hide
* [Glowing pendulum](/lessons/glowing-pendulum/tutorial), construct a pendulum that glows using acceleration
* [Line of Fire](/lessons/line-of-fire/tutorial), make a game to test hand-eye coordination
* [Number psych](/lessons/number-psych/tutorial), collaborate with multiple classmates to develop a game on multiple @boardname@s and a breadboard
### ~

View File

@ -1,84 +0,0 @@
# basic LED show.
### Challenge 0
You have successfully following the [guided tutorial] (https://live.microbit.co.uk/td/tutorials/blink). If not, we should make sure the @boardname@ 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 @boardname@. 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

View File

@ -1,109 +0,0 @@
# blink symbols.
### Challenge 0
You have successfully following the [blink tutorial](/hcwxud). If not, then let's start the tutorial now. Your @boardname@ 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 @boardname@.
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

View File

@ -1,43 +0,0 @@
# 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)
}
}
```

View File

@ -1,43 +0,0 @@
# 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)
}
}
```

View File

@ -1,22 +0,0 @@
# Scroll Image Docs
My script. #docs
**Challenge 0**
This [guided tutorial](/xuhkviyyxa) introduces how to make an image look like it's scrolling across the @boardname@!
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()
```

View File

@ -1,135 +0,0 @@
# TouchDevelop Lessons
Overview of TouchDevelop lessons for the @boardname@.
### @section full
### ~column
### LED screen
* [plot guided](/hcwxud) `guided tutorial ` `video available`
* [plots an LED](/njuzbvocit) [guided tutorial]
* [blink symbols](/rfchtfjmag) `docs`
* [clear screen](/jwqywu)
* [point](/reference/led/point)
* [set brightness](/tfrmcgdtxk)
## @boardname@
## functions
### Basic
* [show number](/doxhko)
* [show string](/hgsfxg)
* [forever - show image](/bniyze) `guided tutorial`
* [forever - show animation - two frames 1a](/rwsjmubtaa)
* [forever - show animation - two frames 1c](/fomtaxxdkk)
* [forever - show animation - two frames 1 d](/huguhgjmmn)
* [forever - show animation - multliple frames](/tweyhx)
## Language {#pconst}
### Variables
* [global variables ](/nkecii) `guided tutorial`
* [local variable - create image, show image](/dcvnwv)
* data types: [number](/types/number), [boolean](/types/boolean), [string](/types/string), [image](/reference/image/image)
### Statements and control structures
* [if](/reference/logic/if)
* [for](/reference/loops/for)
* [for loop nested - plot](/vpvhdnaqfm) **script**
* [while](/js/while)
* [while - show string, show number, show animation](/bidtzqdips) `docs`
* [while - create image ](/bnqbom)
* [return](/js/return)
* [break](/js/break)
* [function](/js/function)
* [assignment operation](/reference/variables/assign) `:=`
### Maths
* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [numbers](/types/number)
* comparison operators (such as `>`, `=`) on [numbers](/types/number)
* the [math](/js/math) library
* the [bits](/js/bits) library
### Logical
* boolean operators (`not`, `or`, `and`) on [booleans](/types/boolean)
### Strings
* concat operator combines [strings](/types/string)
### ~
### ~column
### Input
* [button is pressed](/reference/input/button-is-pressed)
* [on button pressed](/reference/input/on-button-pressed)
* [acceleration](/reference/input/acceleration)
* [compass heading](/reference/input/compass-heading)
* [calibrate](/functions/calibrate)
* [running time](/reference/input/running-time)
### ~
### ~column
### Authoring & Other Bits
* [TouchDevelop editor](/js/editor)
* [markdown](/js/markdown)
* [creating interactive tutorials](/js/creatinginteractivetutorials)
* [run scripts in a web browser](/js/simulator)
* [run scripts on your @boardname@](/usb)
* [libraries](/js/libraries)
### Functions and libraries
* [creating functions](/js/function)
* [function parameters](/js/functionparameters)
* [calling functions](/js/call)
* [libraries](/js/libraries)
### Images
* [create image](/reference/images/create-image)
* [clear](/reference/basic/clear-screen)
* [set pixel](/reference/images/set-pixel)
* [pixel](/reference/images/pixel)
* [show image](/reference/images/show-image)
* [scroll image](/reference/images/scroll-image)
* [width](/functions/width)
* [show animation](/reference/basic/show-animation)
### Pins
* [analog read pin](/reference/pins/analog-read-pin)
* [analog write pin](/reference/pins/analog-write-pin)
* [digital read pin](/reference/pins/digital-read-pin)
* [digital write pin](/reference/pins/digital-write-pin)
### Accessories
* [forever](/reference/basic/forever)
* [in background](/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)
### ~

View File

@ -1,60 +0,0 @@
# Hour of Code
learn how to run an Hour Of Code with the @boardname@. #docs
The @boardname@ 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 @boardname@ 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](/lessons/answering-machine/activity)
* [happy birthday](/lessons/happy-birthday/activity)
* [love meter](/lessons/love-meter/activity)
Print the following **challenges** (1 handout per student):
* [answering machine](/lessons/answering-machine/challenges)
* [happy birthday](/lessons/happy-birthday/challenges)
* [love meter](/lessons/love-meter/challenges)
## Timeline
* ``00:00`` students enter the website address (see step 3)
* ``10:00`` [answering machine](/lessons/answering-machine/activity)
* ``25:00`` [happy birthday](/lessons/happy-birthday/activity)
* ``35:00`` [love meter](/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](/js/games) are available with @boardname@ Tutorials
* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within @boardname@
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.

View File

@ -1,48 +0,0 @@
# Hour of Code notes
learn how to run an Hour Of Code with the @boardname@. #docs
The @boardname@ 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 @boardname@ 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](/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](/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](/lessonss) are available for @boardname@
* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within @boardname@
_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._

View File

@ -1,99 +0,0 @@
# If
Run code based on a condition.
### @parent javascript/language
Conditionally run code depending on whether a [Boolean](/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](/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](/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](/lessons/love-meter), [zoomer](/lessons/zoomer), [offset image](/lessons/offset-image)
### See also
[while loop](/js/while), [for](/reference/loops/for), [boolean](/types/boolean)

View File

@ -1,70 +0,0 @@
# Image
An image for the @boardname@ screen.
### @parent javascript/language
An *Image* is a matrix of pixels to show on the [LED screen](/device/screen)
### Touch Develop editor: plot an image
To display an image using the [Touch Develop editor](/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
![](/static/mb/plot-leds-0.png)
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](/reference/images/create-image) function.
### Block editor: create and show images
To create images using the [Block editor](/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](/js/editor) are [local variables](/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](/js/data) symbol `data->`.
### Image functions
* [create image](/reference/images/create-image): create an image from a series of on/off LED states
* [clear](/reference/basic/clear-screen): turn off all the pixels in an image
* [set pixel](/reference/images/set-pixel): set the state of a pixel in an image
* [pixel](/reference/images/pixel): get the state of a pixel in an image
* [plot-image](/reference/led/plot-image): show a single-frame image on the LED screen
* [show animation](/reference/basic/show-animation): show a series of image frames
* [show image](/reference/images/show-image): show an image on the screen
* [scroll image](/reference/images/scroll-image): scroll an image on the screen
* [width](/functions/width): get the width of an image
### Lessons
* [offset image](/lessons/offset-image)
### See also
[plot image](/reference/led/plot-image), [create image](/reference/images/create-image), [show image](/reference/images/show-image), [LED screen](/device/screen)

View File

@ -1,91 +0,0 @@
# Touch Develop Lessons
Overview of Touch Develop lessons for the @boardname@.
### @short Lessons
### ~column
## Maker
* [The Watch](/lessons/the-watch), design and create The Watch
* [Hack your Headphones](/lessons/hack-your-headphones), create music on the @boardname@ by hacking your headphones
* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits
* [Telegraph](/lessons/telegraph), play the telegraph game between 2 @boardname@s
* [Ornament Chain](/lessons/ornament-chain), play the ornament chain game between 2 @boardname@s
## Beginner
* [Beautiful Image](/lessons/beautiful-image), show a beautiful image with show LEDs
* [Smiley,](/lessons/smiley) smiley and frowney with show animation
* [Lucky 7](/lessons/lucky-7), show a number on the LED screen with show number
* [Answering Machine](/lessons/answering-machine), show a text message with show string
* [Snowflake Fall](/lessons/snowflake-fall), repeat an animation with forever
* [Magic Logo](/lessons/magic-logo), show an image on logo up
* [Screen Wipe](/lessons/screen-wipe), turn off the LEDs with clear screen
* [Flashing Heart](/lessons/flashing-heart), display images with a pause
* [Blink](/lessons/blink), turn an LED on and off with plot
* [Night Light](/lessons/night-light), dim the LEDs with set brightness
* [Glowing Sword](/lessons/glowing-sword), make a glowing sword with fade in and fade out
### ~column
## Intermediate
* [Magic 8](/lessons/magic-8), a fortune teller game with the @boardname@
* [Guess the Number](/lessons/guess-the-number), guess a random number with random
* [Rock Paper Scissors](/lessons/rock-paper-scissors), use image offsets with local variables
* [Counter](/lessons/counter), display a number with a variable
* [Love meter](/lessons/love-meter), create a love meter with on pin pressed
* [Zoomer](/lessons/zoomer), measure the force with acceleration
* [Glowing Pendulum](/lessons/glowing-pendulum), construct a pendulum that glows using acceleration
* [Truth or Dare](/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
* [Spinner](/lessons/spinner), spin the arrow with multiple if statements
* [Die Roll](/lessons/die-roll), spin with more if statements
* [Looper](/lessons/looper), display a series of numbers with a for loop index
* [Strobe Light](/lessons/strobe-light), develop shapes with a nested for loops
* [Digi Yoyo](/lessons/digi-yoyo), create a counter with a while loop
* [Rotation Animation](/lessons/rotation-animation), control an animation with a boolean variable
* [Offset Image](/lessons/offset-image), shift an image horizontally with image offset
* [Compass](/lessons/compass), displays the direction the @boardname@ is pointing
### ~
### ~column
## Advanced
* [Digital Pet](/lessons/digital-pet), a display of pet images with sub-functions
* [Transformers](/lessons/transformers), use functions to return values
* [Speed Button](/lessons/speed-button), code a speed game with running time
* [Catch the Egg](/lessons/catch-the-egg-game), catch falling eggs in a basket with an acceleration controller
* [Headbands](/lessons/headbands), create a charades game with a collection of strings that hold the words
* [Prank WiFi](/lessons/prank-wifi), create fake WiFi to trick your friends
* [Jailbreak](/lessons/jailbreak), break out of a counting loop by pressing button "A"
* [Flipping Bird](/lessons/flipping-bird), use modulo with a conditional
* [Runaway Pac Man](/lessons/runaway-pacman), construct the game pac man with the @boardname@
* [Line of Fire](/lessons/line-of-fire), make a game to test hand-eye coordination
* [The Hat Game](/lessons/the-hat-game), make a game to test your focus on the moving ball
* [2 Player Pong](/lessons/2-player-pong), collaborate with a classmate to develop Pong on multiple @boardname@s
### Games
* [Pong](/lessons/pong), a light bouncing from left to right
* [Meteorite](/lessons/meteorite), a game where meteorites are coming for you one by one
* [Minesweeper](/lessons/minesweeper), make a game to test your memory for placing a LED mine then finding the hidden LED mine
* [Bop it](/lessons/bop-it), a game where you have to keep up with the commands
* [Letter up](/lessons/letter-up), a guessing game with string operators with string at
### ~
### ~hide
* [Number Psych](/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple @boardname@s and a breadboard
### ~
### @section full
The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach)

View File

@ -1,103 +0,0 @@
# 2 player pong lesson
make a game to test your focus on the moving ball.
## Topic
Functions
## Quick Links
* [tutorial](/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 users name.
## Documentation
* **functions** : [read more...](/js/function)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **for** : [read more...](/reference/loops/for)
* **if** : [read more...](/reference/logic/if)
* **show animation** : [read more...](/reference/basic/show-animation)
## Resources
* Activity: [tutorial](/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](/lessons/2-player-pong/tutorial)
## Intended follow on
Publish script to the classroom.

View File

@ -1,91 +0,0 @@
# 2 player pong quiz answers
a two-player game of Pong using TWO @boardname@s!.
## Name
## Directions
Use this activity document to guide your work in the [2 player pong tutorial](/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(Button.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)
```

View File

@ -1,70 +0,0 @@
# 2 player pong quiz
a two-player game of Pong using TWO @boardname@s!.
## Name
## Directions
Use this activity document to guide your work in the [2 player pong tutorial](/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/>

View File

@ -1,59 +0,0 @@
# zoomer challenges
The acceleration function.
**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 @boardname@ 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 @boardname@ 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.

View File

@ -1,79 +0,0 @@
# 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.

View File

@ -1,91 +0,0 @@
# 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(Button.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(Button.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(Button.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(Button.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(Button.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.

View File

@ -1,85 +0,0 @@
# boxer mania challenges
My script. #docs
This [guided tutorial](/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 @boardname@ 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) // ***
```

View File

@ -1,86 +0,0 @@
# break challenges
This guide will show you how to use a break statement within a while loop. #docs
### Challenge 0
Welcome! This [guided tutorial](/lessons/break/tutorial) will assist you with this activity.
```
count = 0
shouldBreak = false
input.onButtonPressed(Button.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(Button.B, () => {
}) // ***
```
Next, set `shouldBreak` back to false to indicate we want to run the `while` loop again.
```
// **. . .**
input.onButtonPressed(Button.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(Button.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.

View File

@ -1,52 +0,0 @@
# button challenges
My script. #docs
### Challenge 0
Howdy! This [guided tutorial](/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(Button.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(Button.A, () => {
basic.showString("hello", 150)
})
```
### Challenge 1
Let's add an event handler for Button `B`.
```
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonPressed(Button.B, () => {
})
```
### Challenge 2
Display `bye` when the `B` button is pressed.
```
input.onButtonPressed(Button.A, () => {
basic.showString("hello", 150)
})
input.onButtonPressed(Button.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`.

View File

@ -1,128 +0,0 @@
# strobe lightquiz
Learn how to create a blinking LED script with a for loop.
## Name
## Directions
Use this activity document to guide your work in the [light column cascade tutorial](/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.
![](/static/mb/empty-microbit.png)
## 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.
![](/static/mb/empty-microbit.png)
## 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.
![](/static/mb/empty-microbit.png)
******************************
## 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.
![](/static/mb/lessons/cascade-0.png)
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.
![](/static/mb/lessons/cascade-1.png)
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.
![](/static/mb/lessons/cascade-2.png)
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)

View File

@ -1,77 +0,0 @@
# clear screen challenges
My script. #docs
### Challenge 0
Welcome! This [guided tutorial](/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(Button.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(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed(Button.B, () => {
})
```
### Challenge 2
Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed(Button.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!

View File

@ -1,128 +0,0 @@
# cascade quiz
Learn how to create a blinking LED script with a for loop.
## Name
## Directions
Use this activity document to guide your work in the [light column cascade tutorial](/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.
![](/static/mb/empty-microbit.png)
## 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.
![](/static/mb/empty-microbit.png)
## 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.
![](/static/mb/empty-microbit.png)
******************************
## 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.
![](/static/mb/lessons/cascade-0.png)
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.
![](/static/mb/lessons/column-0.png)
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.
![](/static/mb/lessons/column-1.png)
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)

View File

@ -1,79 +0,0 @@
# 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](/lessons/comparison/tutorial) will assist you with using the comparison operator.
```
counter = 0
input.onButtonPressed(Button.A, () => {
counter = counter + 1
if (counter == 10) {
counter = 1
}
basic.showNumber(counter, 150)
})
```
### Challenge 1
Now let's do something special when the @boardname@ 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(Button.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(Button.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 @boardname@ 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(Button.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 @boardname@. You will need to add an `else if` after the if statement of `counter = 5`.

View File

@ -1,131 +0,0 @@
# digital pet lesson
a display of pet images for the @boardname@.
## Topic
Functions
## Quick Links
* [tutorial](/lessons/digital-pet/tutorial)
* [quiz](/lessons/digital-pet/quiz)
* [quiz answers](/lessons/digital-pet/quiz-answers)
* [challenges](/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 users name.
**QuickStart Computing Glossary
## Documentation
* **function** : [read more...](/js/function)
* **call** : [read more...](/js/call)
* **global variable** : [read more...](/js/data)
* **assignment operator** : [read more...](/reference/variables/assign)
* **forever** : [read more...](/reference/basic/forever)
* **button is pressed** : [read more...](/reference/input/button-is-pressed)
* **show string** : [read more...](/reference/basic/show-string)
* **show number** : [read more...](/reference/basic/show-number)
* **create image** : [read more...](/reference/images/create-image)
* **show image** : [read more...](/reference/images/show-image)
* **pause** : [read more...](/reference/basic/pause)
## Resources
* Activity: [tutorial](/lessons/digital-pet/tutorial)
* Activity: [quiz](/lessons/digital-pet/quiz)
* Extended Activity: [challenges](/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 @boardname@'s LED screen
* learn how to show a string on the @boardname@'s LED screen
* learn how to create an image to show on the @boardname@'s LED screen
* learn how to show an image on the @boardname@'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](/lessons/digital-pet/tutorial)
* [quiz](/lessons/digital-pet/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/lessons/digital-pet/challenges)
## Homework
* Extended Activity: [challenges](/lessons/digital-pet/challenges)
## Intended follow on
Publish script to the classroom.

View File

@ -1,123 +0,0 @@
# digital pet challenges
Coding challenges for the digital pet tutorial.
## Before we get started
Complete the following guided tutorial:
* [tutorial](/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
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
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
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`

View File

@ -1,60 +0,0 @@
# digital pet quiz answers
A display of pet images for the @boardname@
## Name
## Directions
Use this activity document to guide your work in the [digital pet tutorial](/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)
```

View File

@ -1,32 +0,0 @@
# digital pet quiz
A display of pet images for the @boardname@
## Name
## Directions
Use this activity document to guide your work in the [digital pet tutorial](/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/>

View File

@ -1,85 +0,0 @@
# flipping bird challenges
Coding challenges for flipping bird. #docs
## Before we get started
Complete the following guided tutorial:
* [tutorial](/lessons/flipping-bird/tutorial)
At the end of the tutorial, click `keep editing`. Your code should look like this:
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
basic.plotImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`)
}
})
```
### Challenge 1
We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
basic.plotImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`)
}
if (math.mod(counter, 2) == 0) {
}
})
```
### Challenge 2
Inside of that `if` statement you created in challenge 1, add `basic->plot image()` and display an upside down flying bird.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
basic.plotImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`)
}
if (math.mod(counter, 2) == 0) {
basic.plotImage(`
. . . . .
. . . . .
. . . . .
. . # . .
# # . # #
`) // ***
}
})
```
* `Run` the code to see if it works as expected.
**Challenge 3**
Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display!

View File

@ -1,50 +0,0 @@
# flipping bird quiz answers
use modulo with a conditional.
This is the answer key for the [flipping bird quiz](/lessons/flipping-bird/quiz).
## 1. What does "modulo" mean in math?
<br/>
Modulo (or Mod) is the remainder of a division problem.
## 2. Consider the following code
If the rectangle below represents the @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
```
count = 1
count_ = count_ + 2
```
<br/>
<br/>
![](/static/mb/lessons/flipping-bird-0.png)
The variable `count` is now equal to 3.
<br/>
## 3. Consider the following directions
Modulo (Mod) tells us what the remainder of a division is. For example, `15 mod 4 is 3` since 15 divided by 4 has a remainder of 3.
```
count = 12
count = math.mod(count, 5)
```
If the rectangle below represents the @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
<br/>
<br/>
![](/static/mb/lessons/flipping-bird-1.png)
The display will show `2` because the remainder of 12 divided by 5 is 2.

View File

@ -1,60 +0,0 @@
# flipping bird quiz
use modulo with a conditional.
## Name
## Directions
Use this activity document to guide your work in the [flipping bird tutorial](/lessons/flipping-bird/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What does "modulo" mean in math?
## 2. Consider the following directions
If the rectangle below represents the @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`.
```
count = 1
```
![](/static/mb/empty-microbit.png)
<br/>
<br/>
## 3. Consider the following code
If the rectangle below represents the @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
```
count = 1
count_ = count_ + 2
```
![](/static/mb/empty-microbit.png)
<br/>
<br/>
## 4. Consider the following directions
Modulo (Mod) tells us what the remainder of a division is. For example, `15 mod 4 is 3` since 15 divided by 4 has a remainder of 3.
```
count = 12
count = math.mod(count, 5)
```
If the rectangle below represents the @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
![](/static/mb/empty-microbit.png)
<br/>
<br/>

View File

@ -1,41 +0,0 @@
# looper challenges
These challenges will allow you to create a counter from 0-5 and then from 5-0. #docs
### Challenge 0
Welcome! This [guided tutorial](/bcvgkf) will assist you with the following activity:
```
for (let i = 0; i < 6; i++) {
led.showNumber(i, 150)
basic.pause(2000)
}
```
### Challenge 1
Go through the loop faster by changing the length of the pause. This is the line you will be editing: `basic->pause(2000)`
```
for (let i1 = 0; i1 < 6; i1++) {
basic.showNumber(i1, 150)
basic.pause(500) // ***
}
```
### Challenge 2
Now, let's count down from 5 instead of counting up to 5. Change the line `basic->show number(i, 150)` to `basic->show number(5 - i, 150)`.
```
for (let i2 = 0; i2 < 6; i2++) {
basic.showNumber(5 - i2, 150) // ***
basic.pause(2000)
}
```
### Challenge 3
Have the number count up in 2's from zero. It should go: 0, 2, 4, 6, 8, 10.

View File

@ -1,56 +0,0 @@
# glowing mountain challenges
These challenges will help you display a glowing image that fades in and out at different speeds. #docs
**Challenge 0**
[This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out.
```
images.createImage(`
. . . . .
. . # . .
. # # # .
# # # # #
# # # # #
`).showImage(0)
led.fadeOut(700)
```
**Challenge 1**
Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond delay after the fade out.
```
images.createImage(`
. . . . .
. . # . .
. # # # .
# # # # #
# # # # #
`).showImage(0)
led.fadeOut(700)
basic.pause(1000) // ***
```
**Challenge 2**
After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect.
```
images.createImage(`
. . . . .
. . # . .
. # # # .
# # # # #
# # # # #
`).showImage(0)
led.fadeOut(700)
basic.pause(1000)
led.fadeIn(2000) // ***
```
**Challenge 3**
Now add another `basic->pause(1000)` and `led->fade out(900)` so that the mountain can fade out again.

View File

@ -1,60 +0,0 @@
# glowing sword challenges
These challenges will help you display a glowing image that fades in and out at different speeds. #docs
**Challenge 0**
[This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out.
```
images.createImage(`
. . . . #
# . . # .
# # # . .
. # # . .
# . # # .
`).showImage(0)
led.fadeOut(700)
```
**Challenge 1**
Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond delay after the fade out.
```
images.createImage(`
. . . . #
# . . # .
# # # . .
. # # . .
# . # # .
`).showImage(0)
led.fadeOut(700)
basic.pause(1000) // ***
```
* Run the code to see if it works as expected.
### Challenge 2
After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect.
```
images.createImage(`
. . . . #
# . . # .
# # # . .
. # # . .
# . # # .
`).showImage(0)
led.fadeOut(700)
basic.pause(1000)
led.fadeIn(2000) // ***
```
* Run the code to see if it works as expected.
**Challenge 3**
Now add another `basic->pause(1000)` and `led->fade out(900)` so that the mountain can fade out again.

View File

@ -1,95 +0,0 @@
# glowing sword lesson
make a glowing sword.
## Topic
Fade Out
## Quick Links
* [activity](/lessons/glowing-sword/activity)
* [quiz](/lessons/glowing-sword/quiz)
* [quiz answers](/lessons/glowing-sword/quiz-answers)
* [challenges](/lessons/glowing-sword/challenges)
* [tutorial](/lessons/glowing-sword/tutorial)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to manipulate an image through **fade out**, `led->fade out` to gradually decrease the LED screen brightness until the LED lights are turned off. We will be learning how to fade an image using simple commands, such as plot image, fade out, pause, and fade in.
## 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.
* Computational thinking: Thinking about systems or problems in a way that allows computer systems to be used to model or solve these.
* Hardware: The physical systems and components of digital devices; see also software.
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
* 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
* **plot image** : [read more...](/reference/led/plot-image)
* **fade out** : [read more...](/reference/led/fade-out)
* **pause** : [read more...](/reference/basic/pause)
* **fade in** : [read more...](/reference/led/fade-in)
## Resources
* Activity: [tutorial](/lessons/glowing-sword/tutorial)
* Activity: [quiz](/lessons/glowing-sword/quiz)
* Extended Activity: [challenges](/lessons/glowing-sword/challenges)
## Objectives
* learn how to plot an image
* learn how to gradually decrease the LED screen brightness until the LED lights are turned off
* pause your code for the specified number of milliseconds
* learn how to gradually increase the LED screen brightness until the LED lights are turned on
## Links to the National Curriculum Programmes of Study for Computing
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* 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)
#### 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](/lessons/glowing-sword/tutorial)
* [quiz](/lessons/lucky-7/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/lessons/glowing-sword/challenges)
## Homework
* Extended Activity: [challenges](/lessons/glowing-sword/challenges)
## Intended follow on
Publish script to the classroom.

View File

@ -1,61 +0,0 @@
# glowing sword activity
Make glowing sword.
### ~avatar avatar
In this activity, we will learn how to fade in and out the screen to create a glowing animation. Let's get started!
### ~
Let's start by adding the code to display an image. Use `basic->plot image` to draw your favorite image.
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`) // ***
```
We can control the brightness of the LED screen with code. That's just what we need to create a **glowing** animation: first we **fade out**, then **fade in**. Add a new line of code to **fade out** the screen.
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700) // ***
```
Run your script to make sure it works as expected then add another line of code to **fade in** the screen.
```
led.fadeIn(700)
```
Finally, add a `basic->forever` loop and move the fade out and fade in code into the forever to repeat the glow pattern.
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700) // ***
led.fadeIn(700) // ***
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/glowing-sword/challenges)!
### ~

View File

@ -1,60 +0,0 @@
# glowing sword challenges
Coding challenges for the glowing sword tutorial. #docs
## Before we get started
Complete the [glowing sword](/lessons/glowing-sword/activity) activity and your code will look like this:
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700)
```
### Challenge 1
Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond (1 second) delay after the fade out.
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700)
basic.pause(1000) // ***
```
* `run main` the code to see if it works as expected.
### Challenge 2
After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect.
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700)
basic.pause(1000)
led.fadeIn(2000) // ***
```
* `run main` the code to see if it works as expected.
### Challenge 3
Now add another `basic->pause(1000)` and `led->fade out(900)` so that the sword can fade out again.

View File

@ -1,48 +0,0 @@
# glowing sword quiz answers
The answers for the glowing sword quiz.
This is the answer key for the [glowing sword quiz](/lessons/glowing-sword/quiz).
## 1. What is "fade out" ?
Fade out is a method that gradually decreases the LED screen brightness until the LED lights are turned off.
## 2. Consider the following code
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700)
```
Rewrite the second line of code to decrease the speed of the fade out for the longest amount of time (Hint: 1000 milliseconds is longest amount of time for a fade out).
<br/>
led->fade out(1000)
## 4. Consider the following code
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(1000)
```
What will cause the image to fade back in twice as fast as it faded out?
<br/>
led->fade in(500)

View File

@ -1,46 +0,0 @@
# glowing sword quiz
make a glowing sword.
## Name
## Directions
Use this activity document to guide your work in the [glowing sword tutorial](/lessons/glowing-sword/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Describe what "led -> fade out" does?
<br />
## 2. Rewrite the second line of code to decrease the speed of the fade out for the longest amount of time Hint: 1000 milliseconds is longest amount of time for a fade out.
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(700)
```
<br/>
## 3. What will cause the image to fade back in twice as fast as it faded out?
```
basic.plotImage(`
. . . . #
# . . # .
. # # . .
. # # . .
# . . # .
`)
led.fadeOut(1000)
```
<br/>

View File

@ -1,24 +0,0 @@
# hack your headphones lesson
display beautiful images on the @boardname@.
## Topic
Hack your headphone
## Quick Links
* [activity](/lessons/hack-your-headphones/activity)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to convert your @boardname@ into a music player using pins P0 and GND, headphones (or speakers), as well as crocodile clips (or spring clips).
## Objectives
* learn how to setup the @boardname@ with headphones to play music

View File

@ -1,106 +0,0 @@
# jailbreak lesson
Break out of a counting loop by pressing button "A".
## Topic
Break
## Quick Links
* [tutorial](/lessons/jailbreak/tutorial)
* [quiz](/lessons/jailbreak/quiz)
* [quiz answers](/lessons/jailbreak/quiz-answers)
* [challenges](/lessons/jailbreak/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to create a **break**, `break` to exit a while or for loop before the loop is complete. We will be learning how to create a break using global variables, Boolean, If (conditionals), a While Loop as well as simple commands, such as show string, plot image, show number, and pause.
## Documentation
* **Global Variable** : [read more...](/js/data)
* **Boolean** : [read more...](/types/boolean)
* **On Button Pressed** : [read more...](/reference/input/on-button-pressed)
* **While Loop** : [read more...](/js/while)
* **Break** : [read more...](/js/break)
* **If (Conditional)** : [read more...](/reference/logic/if)
* **Show String** : [read more...](/reference/basic/show-string)
* **Plot Image ** : [read more...](/reference/led/plot-image)
* **Show Number** : [read more...](/reference/basic/show-number)
* **Pause** : [read more...](/reference/basic/pause)
## Objectives
* learn how to create global variables to store data so that you can use it later in your code, functions, and in nested code blocks
* learn how to use the variables to declare a new local Boolean variable that will have one of two possible values: true or false
* learn how to run code when an input button is pressed
* learn how to repeat code while a condition is true
* learn how to exit a while loop before the loop is complete
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to show a string on the LED screen one character at a time
* learn how to turn on LED lights on the LED screen
* learn how to show a number on the LED screen, one digit at a time
* 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 diagrams to express solutions.(AB)
* 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)
* Recognises that different algorithms exist for the same problem (AL) (GE)
* 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
* 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)
#### 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](/lessons/jailbreak/tutorial)
* [quiz](/lessons/jailbreak/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/lessons/jailbreak/challenges)
## Homework
* Extended Activity: [challenges](/lessons/jailbreak/challenges)

View File

@ -1,104 +0,0 @@
# jailbreak challenges
Coding challenges for the jailbreak tutorial.#docs
## Before we get started
Complete the following guided tutorial:
* [tutorial](/lessons/jailbreak/tutorial)
At the end of the tutorial, click `keep editing`. Your code should look like this:
```
count = 0
shouldBreak = false
input.onButtonPressed(Button.A, () => {
shouldBreak = true
})
while (true) {
if (shouldBreak) {
basic.showString("I'M OUT!", 150)
basic.plotImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
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)
basic.plotImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
break
}
count = count + 1
basic.showNumber(count, 150)
basic.pause(1000)
}
input.onButtonPressed(Button.B, () => {
}) // ***
```
Next, set `should break` back to false to indicate we want to run the `while` loop again.
```
// **. . .**
input.onButtonPressed(Button.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(Button.B, () => {
shouldBreak = false
while (true) {
if (shouldBreak) {
basic.showString("I'M OUT!", 150) // ***
basic.plotImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`) // ***
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.

View File

@ -1,46 +0,0 @@
# jailbreak quiz answers
break out of a counting loop by pressing button "A".
This is the answer key for the [jailbreak quiz](/lessons/jailbreak/quiz).
## 1. What does a 'break' statement do to a 'loop' ?
Exit a while or for loop before the loop is complete.
## 2. Consider the following directions
Write the line of code that will initialize a number `variable` to 0. Then create a second `variable` that tells us when we should `break` out of the loop. Set the `break` to false.
```
count = 0
shouldBreak = false
```
## 3. Consider the following directions
Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true).
```
input.onButtonPressed(Button.A, () => {
shouldBreak = true
})
```
## 4. Consider the following directions
Add an `if` statement to determine whether or not we should break out of the loop. Then include the message "I'm Out!" and a smiley face **image** displayed. This will happen right before you `break` from the `while` loop. **Do not include the break **
```
if (shouldBreak) {
basic.showString("I'M OUT!", 150)
images.createImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`).showImage(0)
}
```

View File

@ -1,34 +0,0 @@
# jailbreak quiz
break out of a counting loop by pressing button "A".
## Name
## Directions
Use this activity document to guide your work in the [jailbreak tutorial](/lessons/jailbreak/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What does a 'break' statement do to a 'loop' ?
## 2. Consider the following directions
Write the line of code that will initialize a number variable to 0. Then create a second variable that tells us when we should `break` out of the loop. Set the `break` to false.
<br/>
## 3. Consider the following directions
Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true).
<br/>
## 4. Consider the following directions
Add an `if` statement to determine whether or not we should break out of the loop. Then include the message "I'm Out!" and a smiley face **image** displayed. This will happen right before you `break` from the `while` loop. **Do not include the break **
<br />
<br/>

View File

@ -1,8 +0,0 @@
# landslide
Turn a LED on and off. #docs
Detect and show an image when the @boardname@ falls.
* [tutorial](/lessons/landslide/tutorial)
* [challenges](/lessons/landslide/challenges)

View File

@ -1,77 +0,0 @@
# landslide challenges
Coding challenges for the landslide tutorial.
### ~avatar avatar fail
Don't drop me on the ground without protection! I'm very fragile. Ouch!
### ~
## Before we get started
Complete the following guided tutorial:
* [tutorial](/lessons/landslide/tutorial)
At the end of the tutorial, click `keep editing`. Your code should look like this:
```
input.onFall(() => {
images.createImage(`
. . # . .
. . # . .
. . # . .
. . . . .
. . # . .
`).showImage(0) // ***
})
```
### Challenge 1
Add a pause within `input->on fall` after displaying `!`. This will allow us to display another image in the next challenge.
```
input.onFall(() => {
images.createImage(`
. . # . .
. . # . .
. . # . .
. . . . .
. . # . .
`).showImage(0)
basic.pause(2000) // ***
})
```
### Challenge 2
Create and show an `X` image after the pause from Challenge 1.
```
input.onFall(() => {
images.createImage(`
. . # . .
. . # . .
. . # . .
. . . . .
. . # . .
`).showImage(0)
basic.pause(2000)
images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`).showImage(0) // ***
})
```
* `Run` the program to see if it works as expected.
### Challenge 3
Now let's display a third image when the @boardname@ falls! First, add `basic->pause(2000)` followed by another image of your choice. Be creative!

View File

@ -1,112 +0,0 @@
# letter up lesson
create a guessing game that can be played with your friends.
## Topic
String Functions
## Quick Links
* [tutorial](/lessons/letter-up/tutorial)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to create a guessing game with **global variables** `var str: "this is a string" ` and **strings functions**, ` var first char := str -> at(0) ` , to develop a sequence of characters and get a character within a string . We will be learning how to create a guessing game using local variables, strings functions, input on logo up, string related functions, on screen up, the game library as well as simple commands, such as show string and show number.
## What the teacher needs to know
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
* 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.
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
* 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 users name.
**QuickStart Computing Glossary
## Documentation
* **string** : [read more...](/types/string)
* **string functions** : [read more...](/types/string-functions)
* **show string** : [read more...](/reference/basic/show-string)
* **local variables** : [read more...](/reference/variables/var)
* **assignment operator** : [read more...](/reference/variables/assign)
* **math random** : [read more...](/js/math)
## Resources
* Activity: [tutorial](/lessons/letter-up/tutorial)
## Objectives
* learn how to create a sequences of characters
* learn how to get a character within a string, using the specified index
* learn how to show a string on the LED screen
* learn how to create a local variable to store data so that you can use it later in your code
* learn how to set and change the value of a local variable
* learn how to register an event handler that executes whenever the LED screen is perpendicular to the ground and the @boardname@ logo is above the LED screen
* learn how to register an event handler that executes whenever the LED screen is facing the floor
* learn how to register an event handler that executes whenever the LED screen is facing the ceiling/sky
* learn how to return a random number
* learn how to use the game library to set the score, lives, and countdown
## Links to the National Curriculum Programmes of Study for Computing
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* 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 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
#### 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)
#### 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](/lessons/letter-up/tutorial)
## Intended follow on
Publish script to the classroom.

View File

@ -1,128 +0,0 @@
# cascade quiz
Learn how to create a blinking LED script with a for loop.
## Name
## Directions
Use this activity document to guide your work in the [light column cascade tutorial](/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.
![](/static/mb/empty-microbit.png)
## 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.
![](/static/mb/empty-microbit.png)
## 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.
![](/static/mb/empty-microbit.png)
******************************
## 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.
![](/static/mb/lessons/cascade-0.png)
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.
![](/static/mb/lessons/column-0.png)
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.
![](/static/mb/lessons/column-1.png)
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)

View File

@ -1,94 +0,0 @@
# line of fire lesson
Create a game that relies on precise instincts and timing reflexes #if #.
## Topic
Functions
## Quick Links
* [tutorial](/lessons/line-of-fire/tutorial)
* [quiz](/lessons/line-of-fire/quiz)
* [quiz answers](/lessons/line-of-fire/quiz-answers)
## 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 pong game using functions, global variable forever loop, global variables, Boolean, for loop, input on button pressed, if statements, as well as simple commands, such as plot, unplot and pause.
## Documentation
* **function** : [read more...](/js/function)
* **return** : [read more...](/js/return)
* **call** : [read more...](/js/call)
* **global variable** : [read more...](/js/data)
* **arithmetic operator** : [read more...](/types/number)
* **Boolean** : [read more...](/types/boolean)
* **forever** : [read more...](/reference/basic/forever)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **if** : [read more...](/reference/logic/if)
* **clear screen** : [read more...](/reference/basic/clear-screen)
* **show string** : [read more...](/reference/basic/show-string)
* **plot** : [read more...](/reference/led/plot)
* **unplot** : [read more...](/reference/led/unplot)
* **pause** : [read more...](/reference/basic/pause)
## Objectives
* learn how to create a function as a unit of code that performs a specific task and returns a result
* learn how a return statement exits a function and returns a value to the code
* 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 arithmetic operators operate on numbers and return a number
* learn how a Boolean type has one of two possible values: true or false
* learn how to repeat code in the background forever
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to run code when an input button is pressed
* learn how to show a string on the @boardname@'s LED screen
* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
* learn how to turn off a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
* 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 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)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [tutorial](/lessons/line-of-fire/tutorial)
## Extended Activity
* time: 20 min.
* [quiz](/lessons/line-of-fire/quiz)
## Homework
* Extended Activity: [quiz](/lessons/line-of-fire/quiz)

View File

@ -1,140 +0,0 @@
# line of fire quiz answers
create a game that relies on precise instincts and timing reflexes.
## Name
## Directions
Use this activity document to guide your work in the [line of fire tutorial](/lessons/line-of-fire/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the names of the two Global Variable used to store the mode of the game. Which of these variables is set to true when we are displaying the score?
<br/>
```
dotRunning = true
displayingStats = false
```
`displaying stats` is set to `true` when we are displaying the score.
## 2. Write the name of the Global Variable that represents the velocity and assign it to its initial value. Next, write the name of the Global Variable that represents the position of the dot and assign it to its initial value.
<br/>
```
dotX = 2
dotXVelocity = 1
```
## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values.
<br/>
```
wins = 0
losses = 0
```
## 4. Write the For Loop that will plot the 'line of fire'.
<br/>
```
for (let i = 0; i < 5; i++) {
led.plot(2, i)
}
```
## 5. If the dot is running, write the 'nested If statements' that will see when to change the direction by flipping the sign of the velocity. This occurs if the dot is on the edge of the board.
<br/>
**Questions 6-8 concern with moving the dot.**
## 6. Write the code to unplot the dot's current position. NOTE- if dotX was originally 2, then we must plot instead of unplot the dot's original position.
<br/>
Solution 1:
```
if (dotX == 2) {
led.plot(dotX, 2)
} else {
led.unplot(dotX, 2)
}
```
Alternative Solution:
```
if (dotX != 2) {
led.unplot(dotX, 2)
} else {
led.plot(dotX, 2)
}
```
## 7. Update its position variables by adding the velocity to the dot's current position.
<br/>
```
dotX = dotX + dotXVelocity
```
## 8. Finally, plot the dot's new position. NOTE- if dotX is now 2, then we must unplot instead of plot the dot's new position.
<br/>
Solution 1:
```
led.plot(dotX, 2)
if (dotX == 2) {
led.unplot(dotX, 2)
}
```
Alternative Solution:
```
if (dotX == 2) {
led.unplot(dotX, 2)
} else {
led.plot(dotX, 2)
}
```
## 9. Write the code that plots and unplots the dot 10 times when button A is pressed. Pause for 60 milliseconds in between plotting and unplotting the dot. (Don't include any if statements, and don't worry about updating 'dot running'.)
<br/>
```
for (let j = 0; j < 10; j++) {
led.plot(dotX, 2)
basic.pause(60)
led.unplot(dotX, 2)
basic.pause(60)
}
```
## 10. Write the code that will display the score when button B is pressed. (Don't include any IF statements, and don't worry about updating 'dot running' and 'displaying stats'.)
<br/>
```
input.onButtonPressed(Button.B, () => {
basic.showString("WINS", 150)
basic.showNumber(wins, 150)
basic.pause(500)
basic.showString("LOSSES", 150)
basic.showNumber(losses, 150)
basic.pause(500)
})
```

View File

@ -1,84 +0,0 @@
# line of fire quiz
create a game that relies on precise instincts and timing reflexes.
## Name
## Directions
Use this activity document to guide your work in the [line of fire tutorial](/lessons/line-of-fire/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the names of the two Global Variable used to store the mode of the game. Which of these variables is set to true when we are displaying the score?
<br/>
<br/>
## 2. Write the name of the Global Variable that represents the velocity and assign it to its initial value. Next, write the name of the Global Variable that represents the position of the dot and assign it to its initial value.
<br/>
<br/>
## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values.
<br/>
<br/>
## 4. Write the For Loop that will plot the 'line of fire'.
<br/>
<br/>
<br/>
## 5. If the dot is running, write the 'nested If statements' that will see when to change the direction by flipping the sign of the velocity. This occurs if the dot is on the edge of the board.
<br/>
**Questions 6-8 concern with moving the dot.**
## 6. Write the code to unplot the dot's current position. NOTE- if dot x was originally 2, then we must plot instead of unplot the dot's original position.
<br/>
<br/>
<br/>
## 7. Update its position variables by adding the velocity to the dot's current position.
<br/>
## 8. Finally, plot the dot's new position. NOTE- if dot x is now 2, then we must unplot instead of plot the dot's new position.
<br/>
<br/>
<br/>
## 9. Write the code that plots and unplots the dot 10 times when button A is pressed. Pause for 60 milliseconds in between plotting and unplotting the dot. (Don't include any if statements, and don't worry about updating 'dot running'.)
<br/>
<br/>
<br/>
## 10. Write the code that will display the score when button B is pressed. (Don't include any IF statements, and don't worry about updating 'dot running' and 'displaying stats'.)
<br/>
<br/>
<br/>
<br/>
<br/>

View File

@ -1,71 +0,0 @@
# magic logo challenges
These challenges will help you show arrows that point which way the logo is pointing! #docs
## Challenge 0
This [guided tutorial](/zysycw) will help you display an arrow pointing the direction the logo is oriented!
Let's display and upward pointing arrow when the logo is up!
```
input.onLogoUp(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`).showImage(0)
})
```
**Challenge 1**
How about when the logo is down? We should display the arrow pointing downward!
Let's start by adding a condition for if the logo is down.
```
input.onLogoUp(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`).showImage(0)
})
input.onLogoDown(() => {
}) // ***
```
## Challenge 2
Now we need to display the arrow!
```
input.onLogoUp(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`).showImage(0)
})
input.onLogoDown(() => {
images.createImage(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`).showImage(0) // ***
})
```
**Challenge 3**
Let's show a spinning arrow when the @boardname@ is shaken. We can do this by adding an on shake condition and showing an animation of the arrow spinning!

View File

@ -1,75 +0,0 @@
# looper challenges
Coding challenges for the looper tutorial. #docs
## Before we get started
Complete the following guided tutorial:
* [tutorial](/lessons/looper/tutorial)
At the end of the tutorial, click `keep editing`. Your code should look like this:
```
for (let i = 0; i < 6; i++) {
basic.showNumber(i, 150)
basic.pause(2000)
}
```
### Challenge 1
What if we want to count up to lucky number 7 instead? Let's do that by changing the ending value to `8` instead of `6`.
```
for (let i1 = 0; i1 < 8; i1++) {
basic.showNumber(i1, 150) // ***
basic.pause(2000)
}
```
* Run the program now to see your changes.
### Challenge 2
What about 9? Let's do that by changing the ending value to `10`.
```
for (let i2 = 0; i2 < 10; i2++) {
basic.showNumber(i2, 150)
basic.pause(2000)
}
```
* Run your code to see the new counter.
### Challenge 3
Now let's start counting from `3` instead! Our for loop will always start at `0` so we simply add `3` to the `i` variable when passing it to `basic->show number`.
```
for (let i3 = 0; i3 < 8; i3++) {
basic.showNumber(i3 + 3, 150) // ***
basic.pause(2000)
}
```
Run it on the simulator!
### Challenge 4
Now, let's **count down from 9**. Change the line `basic->show number(i + 3, 150)` to `basic->show number(9 - i, 150)`.
```
for (let i4 = 0; i4 < 10; i4++) {
basic.showNumber(9 - i4, 150) // ***
basic.pause(2000)
}
```
* Run the code to make sure it is doing what is expected.
### Challenge 5
After counting down from `9` let's show the string `BOOOM`!

View File

@ -1,103 +0,0 @@
# looper lesson
Learn to control blinking LEDs.
## Topic
For loop - Blinking LED
## Quick links
* [tutorial](/lessons/looper/tutorial)
* [quiz](/lessons/looper/quiz)
* [quiz answers](/lessons/looper/quiz-answers)
* [challenges](/lessons/looper/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 the for loop as well as simple commands, such as plot and pause.
## 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 programs control. ** The blink program introduces a While Loop. While Loop is a while loop that will repeat code forever while - true.
**Command:** An instruction for the computer to execute, written in a particular programming language.**
**QuickStart Computing Glossary
## Documentation
* **plot**: [read more...](/reference/led/plot)
* **pause**: [read more...](/reference/basic/pause)
* **for**: [read more...](/reference/loops/for)
## Resources
* Activity: [tutorial](/lessons/looper/tutorial)
* Activity: [quiz](/lessons/looper/quiz)
* Extended Activity: [challenges](/lessons/looper/challenges)
## Objectives
* learn how to blink a light
* create a for loop that will loop through each x-value, y-value from 0 to 4.
* learn how to pause 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
* 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)
* 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)
#### 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: 10 min.
* [tutorial](/lessons/looper/tutorial)
* [quiz](/lessons/looper/quiz)
* assessment opportunities: loops, plot, pause, clear screen
## Extended Activity
* time: 20 min.
* [challenges](/lessons/looper/challenges)
* assessment opportunities: loops, plot, pause, clear screen
## Homework
* Extended Activity: [challenges](/lessons/looper/challenges)
## Intended follow on
Publish script to the classroom.

View File

@ -1,99 +0,0 @@
# meteorite lesson
a game in which you must dodge the meteorites with your ship.
## Topic
Functions
## Quick Links
* [tutorial](/lessons/meteorite/tutorial)
* [quiz](/lessons/meteorite/quiz)
* [quiz answers](/lessons/meteorite/quiz-answers)
## 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 meteorite game using functions, forever loop, global variables, for loop, input on button pressed, if statements, math random, input on shake as well as simple commands, such as show string, show number, and pause.
## Documentation
* **function** : [read more...](/js/function)
* **call** : [read more...](/js/call)
* **global variable** : [read more...](/js/data)
* **arithmetic operators** : [read more...](/types/number)
* **math random** : [read more...](/js/math)
* **forever** : [read more...](/reference/basic/forever)
* **for** : [read more...](/reference/loops/for)
* **fade out** : [read more...](/reference/led/fade-out)
* **fade in** : [read more...](/reference/led/fade-in)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **if** : [read more...](/reference/logic/if)
* **show string** : [read more...](/reference/basic/show-string)
* **show number** : [read more...](/reference/basic/show-number)
* **show string** : [read more...](/reference/basic/show-string)
* **plot** : [read more...](/reference/led/plot)
* **plot all** : [read more...](/reference/led/plot-all)
* **pause** : [read more...](/reference/basic/pause)
## 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 arithmetic operators operate on numbers and return a number
* learn how to return a random number
* learn how to repeat code in the background forever
* learn how to gradually decrease the LED screen brightness until the LED lights are turned off
* learn how to gradually increase the LED screen brightness until the LED lights are turned on
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to run code when an input button is pressed
* learn how to show a number on the @boardname@'s LED screen
* learn how to show a string on the @boardname@'s LED screen
* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
* learn how to turn on all the 25 LEDs on the LED 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 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)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [tutorial](/lessons/meteorite/tutorial)
## Extended Activity
* time: 20 min.
* [quiz](/lessons/meteorite/quiz)
## Homework
* Extended Activity: [quiz](/lessons/meteorite/quiz)

View File

@ -1,88 +0,0 @@
# meteorite quiz answers
create the game meteorite.
## Name
## Directions
This is the answer key for the [meteorite quiz](/lessons/meteorite/quiz)
## 1. Write the code that sets up the position variables of meteorite 1. (Hint: look inside the function "initialize game".)
<br/>
```
meteorite_1X = Math.random(5)
meteorite_1Y = -4
```
## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".)
<br/>
```
led.plot(shipLeftX, 4)
led.plot(shipLeftX + 1, 4)
```
## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1".
<br/>
```
if (meteorite_1X == 4 && (shipLeftX == meteorite_1X || shipLeftX + 1 == meteorite_1X)) {
gameOver()
}
```
## 4. Write the code that increase the difficulty by making the game run faster.
<br/>
```
pauseDifficulty = (pauseDifficulty * 49) / 50
```
## 5. Write the code that moves the ship left.
<br/>
```
led.unplot(shipLeftX + 1, 4)
shipLeftX = shipLeftX - 1
led.plot(shipLeftX, 4)
```
## 6. Write the code that moves the ship right.
<br/>
```
led.unplot(shipLeftX, 4)
shipLeftX = shipLeftX + 1
led.plot(shipLeftX + 1, 4)
```
## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1.
<br/>
```
if (shipLeftX == meteorite_1X && meteorite_1Y == 4) {
gameOver()
}
```
## 8. Write the code that flashes all the LEDs thee times to create the effect of a crash. (Hint: look at the function "game over".)
<br/>
```
led.plotAll()
for (let i = 0; i < 3; i++) {
led.fadeIn(400)
led.fadeOut(400)
}
```

View File

@ -1,44 +0,0 @@
# meteorite quiz
create the game meteorite.
## Name
## Directions
Use this activity document to guide your work in the [meteorite tutorial](/lessons/meteorite/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the code that sets up the position variables of meteorite 1. (Hint: look inside the function "initialize game".)
<br/>
## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".)
<br/>
## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1".
<br/>
## 4. Write the code that increase the difficulty by making the game run faster.
<br/>
## 5. Write the code that moves the ship left.
<br/>
## 6. Write the code that moves the ship right.
<br/>
## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1.
<br/>
## 8. Write the code that flashes all the LEDs thee times to create the effect of a crash. (Hint: look at the function "game over".)
<br/>

View File

@ -1,110 +0,0 @@
# minesweeper lesson
A game that tests your memory for placing a LED mine then finding the hidden LED mine.
## Topic
Global Variables
## Quick Links
* [tutorial](/lessons/minesweeper/tutorial)
* [quiz](/lessons/minesweeper/quiz)
* [quiz answers](/lessons/minesweeper/quiz-answers)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to create a minesweeper game with **plot**, `led->plot` , **unplot**, `led->unplot`, **global variables** to keep track of the coordinates that the player is selecting. We will be learning how to create a minesweeper game using global variables, if (conditionals), input on button pressed, math random as well as simple commands such as led plot, led unplot, show string, 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.
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
* 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.
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the users name.
**QuickStart Computing Glossary
## Documentation
* **global variables** : [read more...](/js/data)
* **math random number** : [read more...](/js/math)
* **plot** : [read more...](/reference/led/plot)
* **unplot** : [read more...](/reference/led/unplot)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **if** : [read more...](/reference/logic/if)
* **show string** : [read more...](/reference/basic/show-string)
* **pause** : [read more...](/reference/basic/pause)
## Resources
* Activity: [tutorial](/lessons/minesweeper/tutorial)
* Activity: [quiz](/lessons/minesweeper/quiz)
## 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 return a random number
* learn how to turn on a LED light on the LED screen
* learn how to turn off a LED light on the LED screen
* learn how to run code when an input button is pressed
* 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 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 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)
#### 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)
* 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](/lessons/minesweeper/tutorial)
* [quiz](/lessons/minesweeper/quiz)

View File

@ -1,55 +0,0 @@
# minesweeper quiz answers
make a game to test your memory for placing a LED mine then finding the hidden LED mine.
## Name
## Directions
Use this activity document to guide your work in the [minesweeper tutorial](/lessons/minesweeper/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the code that randomly generates a number between 0 and 4 and stores that value in a global variable called 'mine x'.
<br />
```
mineX = Math.random(5)
```
## 2. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
![](/static/mb/lessons/blink-1.png)
<br />
```
selectX = 0
selectY = 0
led.plot(selectX, selectY)
```
## 3. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
![](/static/mb/lessons/blink-0.png)
<br />
```
selectX = 2
selectY = 2
led.plot(selectX, selectY)
```
## 4. How do you check if a dot is one away from given x and y coordinates?
<br />
<br />
```
if (mineX + 2 > selectX && selectX > mineX - 2 && mineY + 2 > selectY && selectY > mineY - 2) {
}
```

View File

@ -1,34 +0,0 @@
# minesweeper quiz
make a game to test your memory for placing a LED mine then finding the hidden LED mine.
## Name
## Directions
Use this activity document to guide your work in the [minesweeper tutorial](/lessons/minesweeper/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the code that randomly generates a number between 0 and 4 and stores that value in a global variable called 'mine x'.
<br />
## 2. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
![](/static/mb/lessons/blink-1.png)
<br />
## 3. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
![](/static/mb/lessons/blink-0.png)
<br />
## 4. How do you check if a dot is one away from given x and y coordinates?
<br />
<br />

View File

@ -1,207 +0,0 @@
# number psych quiz answers
a 4-player game in which each player must outwit his opponents.
## Name
## Directions
Use this activity document to guide your work in the [number psych console tutorial](/lessons/number-psych-console/tutorial) and the [number psych controller tutorial](/lessons/number-psych-controller/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
**Questions 1-9 are concerned with 'number pysch console tutorial'**
## 1. Create a 'collection of options' and save them in a local variable named 'options'.
<br/>
```
let options = (<number[]>[])
```
## 2. Add the options '1', '3', and '5' into the local variable 'options'.
<br/>
```
options.push(1)
options.push(3)
options.push(5)
```
## 3. Create a collection of scores and add four values of '0' into the collection.
<br />
```
let scores = (<number[]>[])
```
## 4. Write the code that reads a byte that indicates a controller is asking for a player number. (Don't bother checking if the byte received is 255.) Next, write the code that transfers the player number to the controller.
<br />
```
scores = (<number[]>[])
for (let i2 = 0; i2 < 4; i2++) {
scores.push(0)
}
```
## 5.Write the code that transfers the three options.
<br />
```
for (let i5 = 0; i5 < 3; i5++) {
micro_bitTransfer.transferByte(options[i5])
basic.pause(200)
}
```
## 6.Write the code that requests each player to send their choice in the player order number. Don't worry about reading their choice. (Hint: look at the four loop with 'k' as the index.)
<br />
```
for (let k = 0; k < 4; k++) {
micro_bitTransfer.transferByte(101 + k)
}
```
## 7.Write the code to create two collections. One collection ("choices") stores all the choices, while the other collection ("has common") stores whether or not the choice is unique. (If the choice is not unique, then "has common" will be set to true for that particular choice.)
<br />
```
let choices = (<number[]>[])
let hasCommon = (<boolean[]>[])
```
## 8. Write the code that compares each of the choices with each other. If the two choices are the same, then set the appropriate value inside 'has common' to true. (Hint: look at the for loops with 'l' and 'n' as their indexes.)
<br />
```
for (let l = 0; l < 4; l++) {
for (let n = 0; n < 4; n++) {
// ### ~avatar avatar
// If the choice at `l` and `n` are the same, assuming `l` isn't equal to `n`, then there is a match.
// {stcode}
// MACRO: stcode
// ### ~
if (choices[l] == choices[n] && ! (l == n)) {
// ### ~avatar avatar
// Set `has common` at `l` and `n` to true.
// {stcode}
// MACRO: stcode
// ### ~
hasCommon[l] = true
hasCommon[n] = true
}
}
}
```
## 9. For each value inside 'has common', transfer a '1' if there is a match and transfer a '0' if there isn't a match. Add a pause of 100 milliseconds at the beginning of each transfer.)
<br />
```
for (let i4 = 0; i4 < 4; i4++) {
basic.pause(100)
if (hasCommon[i4]) {
micro_bitTransfer.transferBit(1)
} else {
micro_bitTransfer.transferBit(0)
}
}
```
**Questions 10-14 are concerned with 'number pysch controller tutorial'**
## 10. Write the code that asks for a player number if button 'A' is pressed on the BBC controller @boardname@.
<br />
```
input.onButtonPressed(Button.A, () => {
if (gameMode == 0 && playerNumber == 0) {
micro_bitTransfer.transferByte(255)
}
})
```
## 11. Write the code that adds the three transferred options to the "options" collection. (Hint: look at the for loop with 'k' as the index.)
<br />
```
for (let k1 = 0; k1 < 3; k1++) {
options.push(micro_bitTransfer.readByte())
}
```
## 12. Write the code that detects when button 'B' is pressed. Inside this condition, if 'game mode' is 2, set 'game mode' back to 1 and plot a waiting image.
<br />
```
input.onButtonPressed(Button.B, () => {
if (gameMode == 2) {
gameMode = 1
basic.plotImage(`
. . . . .
. . . . .
. # # # .
. . . . .
. . . . .
`)
}
})
```
## 13. Create a while loop that first reads which controller the console @boardname@ is requesting data from. Plot a waiting image, and then write an IF statement to check if the request corresponds to the controller. (Don't worry about writing anything inside the if statement).
<br />
```
while (true) {
let playerRequest = micro_bitTransfer.readByte()
basic.plotImage(`
. . . . .
. . . . .
. # # # .
. . . . .
. . . . .
`)
if (playerRequest == 100 + playerNumber) {
}
}
```
## 14. Write the code that displays an "X" on the @boardname@ if 'result' is 1. Otherwise, display a "check mark".
<br />
```
if (result == 1) {
basic.plotImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`)
} else {
basic.plotImage(`
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .
`)
}
```

View File

@ -1,116 +0,0 @@
# number psych quiz
a 4-player game in which each player must outwit his opponents.
## Name
## Directions
Use this activity document to guide your work in the [number psych console tutorial](/lessons/number-psych-console/tutorial) and the [number psych controller tutorial](/lessons/number-psych-controller/tutorial).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
**Questions 1-9 are concerned with 'number pysch console tutorial'**
## 1. Create a 'collection of options' and save them in a local variable named 'options'.
<br/>
## 2. Add the options '1', '3', and '5' into the local variable 'options'.
<br/>
<br/>
## 3. Create a collection of scores and add four values of '0' into the collection.
<br />
<br/>
## 4. Write the code that reads a byte that indicates a controller is asking for a player number. (Don't bother checking if the byte received is 255.) Next, write the code that transfers the player number to the controller.
<br />
<br/>
<br/>
## 5.Write the code that transfers the three options.
<br />
<br/>
## 6.Write the code that requests each player to send their choice in the player order number. Don't worry about reading their choice. (Hint: look at the four loop with 'k' as the index.)
<br />
<br/>
<br/>
## 7.Write the code to create two collections. One collection ("choices") stores all the choices, while the other collection ("has common") stores whether or not the choice is unique. (If the choice is not unique, then "has common" will be set to true for that particular choice.)
<br />
<br/>
## 8. Write the code that compares each of the choices with each other. If the two choices are the same, then set the appropriate value inside 'has common' to true. (Hint: look at the for loops with 'l' and 'n' as their indexes.)
<br />
<br/>
<br/>
<br/>
<br/>
<br/>
## 9. For each value inside 'has common', transfer a '1' if there is a match and transfer a '0' if there isn't a match. Add a pause of 100 milliseconds at the beginning of each transfer.)
<br />
<br/>
<br/>
**Questions 10-14 are concerned with 'number pysch controller tutorial'**
## 10. Write the code that asks for a player number if button 'A' is pressed on the BBC controller @boardname@.
<br />
<br/>
## 11. Write the code that adds the three transferred options to the "options" collection. (Hint: look at the for loop with 'k' as the index.)
<br />
<br/>
<br/>
## 12. Write the code that detects when button 'B' is pressed. Inside this condition, if 'game mode' is 2, set 'game mode' back to 1 and plot a waiting image.
<br />
<br/>
## 13. Create a while loop that first reads which controller the console @boardname@ is requesting data from. Plot a waiting image, and then write an IF statement to check if the request corresponds to the controller. (Don't worry about writing anything inside the if statement).
<br />
<br/>
<br/>
## 14. Write the code that displays an "X" on the @boardname@ if 'result' is 1. Otherwise, display a "check mark".
<br />
<br/>

View File

@ -1,69 +0,0 @@
# landslide challenges
The on fall function.
### Challenge 0
Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/on-fall/tutorial) will show you how to detect when the @boardname@ is falling. Your goal is to write a program that detects when the @boardname@ falls!
```
input.onFall(() => {
images.createImage(`
. . # . .
. . # . .
. . # . .
. . . . .
. . # . .
`).showImage(0) // ***
})
```
### Challenge 1
Add a pause within `input->on fall`. This will allow us to display another image in the next challenge.
```
input.onFall(() => {
images.createImage(`
. . # . .
. . # . .
. . # . .
. . . . .
. . # . .
`).showImage(0)
basic.pause(2000) // ***
})
```
### Challenge 2
Create and display an `X` after the pause from Challenge 1
```
input.onFall(() => {
images.createImage(`
. . # . .
. . # . .
. . # . .
. . . . .
. . # . .
`).showImage(0)
basic.pause(2000)
images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`).showImage(0) // ***
})
```
### Challenge 3
Create a loop so that the @boardname@ alternates between the exclamation point and "X" images when the @boardname@ falls. You will need a `forever` loop and a pause at the end of the loop to do this.
## See Also
[on shake](/reference/input/on-gesture)

View File

@ -1,67 +0,0 @@
# on logo up and down challenges
My script. #docs
**Challenge 0**
This [guided tutorial](/zysycw) will help you display an arrow pointing the direction the logo is orientated!
Let's display and upward pointing arrow when the logo is up!
```
input.onLogoUp(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`).showImage(0)
})
```
**Challenge 1**
How about when the logo is down? We should display the arrow pointing downward!
Let's start by adding a condition for if the logo is down.
```
input.onLogoUp(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`).showImage(0)
})
input.onLogoDown(() => {
})
```
**Challenge 2**
Now we need to display the arrow!
```
input.onLogoUp(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`).showImage(0)
})
input.onLogoDown(() => {
images.createImage(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`).showImage(0) // ***
})
```

View File

@ -1,81 +0,0 @@
# flipping bird challenges
These challenges will allow you to create and display a flipping image of a bird when the @boardname@ is shaken. #docs
### Challenge 0
Greetings! This [guided tutorial](/lessons/flipping-bird/tutorial) will begin to show you how to flip a bird.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
images.createImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`).showImage(0)
}
})
```
### Challenge 1
We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
images.createImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`).showImage(0)
}
if (math.mod(counter, 2) == 0) {
}
})
```
### Challenge 2
Inside of that `if` statement you created in challenge 1, add `image->create image()->show image(0)` and display an upside down flying bird.
```
counter = 0
input.onGesture(Gesture.Shake, () => {
counter = counter + 1
if (math.mod(counter, 2) == 1) {
images.createImage(`
# # . # #
. . # . .
. . . . .
. . . . .
. . . . .
`).showImage(0)
}
if (math.mod(counter, 2) == 0) {
images.createImage(`
. . . . .
. . . . .
. . . . .
. . # . .
# # . # #
`).showImage(0) // ***
}
})
```
* Run the code to see if it works as expected.
### Challenge 3
Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display!

View File

@ -1,133 +0,0 @@
# pong lesson
code your own game of Pong on the @boardname@. #.
## Topic
Functions
## Quick Links
* [tutorial](/lessons/pong/tutorial)
* [quiz](/lessons/pong/quiz)
* [quiz answers](/lessons/pong/quiz-answers)
## 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 pong game using functions, global variable forever loop, global variables, Boolean, for loop, input on button pressed, if statements, as well as simple commands, such as plot, unplot 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 users name.
**QuickStart Computing Glossary
## Documentation
* **function** : [read more...](/js/function)
* **return** : [read more...](/js/return)
* **call** : [read more...](/js/call)
* **global variable** : [read more...](/js/data)
* **arithmetic operator** : [read more...](/types/number)
* **Boolean** : [/td/Boolean]()
* **forever** : [read more...](/reference/basic/forever)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **if** : [read more...](/reference/logic/if)
* **clear screen** : [read more...](/reference/basic/clear-screen)
* **show string** : [read more...](/reference/basic/show-string)
* **plot** : [read more...](/reference/led/plot)
* **unplot** : [read more...](/reference/led/unplot)
* **pause** : [read more...](/reference/basic/pause)
## Resources
* Activity: [tutorial](/lessons/pong/tutorial)
* Activity: [quiz](/lessons/pong/quiz)
## Objectives
* learn how to create a function as a unit of code that performs a specific task and returns a result
* learn how a return statement exits a function and returns a value to the code
* 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 arithmetic operators operate on numbers and return a number
* learn how a Boolean type has one of two possible values: true or false
* learn how to repeat code in the background forever
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to run code when an input button is pressed
* learn how to show a string on the @boardname@'s LED screen
* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
* learn how to turn off a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
* 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](/lessons/pong/tutorial)
## Extended Activity
* time: 20 min.
* [quiz](/lessons/pong/quiz)
## Homework
* Extended Activity: [quiz](/lessons/pong/quiz)
## Intended follow on
Publish script to the classroom.

View File

@ -1,63 +0,0 @@
# pong activity
Building a game of pong with sprites.
### ~avatar avatar
Welcome! This tutorial will teach you how to build a simple pong game using sprites.
### ~
The game works as follow: the user moves a paddle on the left of the screen and a ball bounces on the other side. Let's start by creating the 2 sprites.
```
let paddle = game.createSprite(0, 2)
let ball = game.createSprite(4, 2)
```
Let's make the ball start with an angle.
```
ball.setDirection(-45)
```
The user will control the paddle by pressing ``A`` to go up and ``B`` to go down. Let's add ``on button pressed`` event handlers to do that.
```
input.onButtonPressed(Button.A, () => {
paddle.changeYBy(-1)
})
input.onButtonPressed(Button.B, () => {
paddle.changeYBy(1)
})
```
Let's add a ``forever`` loop to start the main game logic.
```
basic.forever(() => {
// Leave the sprite on screen for a little while.
basic.pause(400)
// Let's move the ball in whatever direction it is currently going.
ball.move(1)
// The ball might be on the left side of the screen (``x = 0``), let's test for that.
if (ball.x() == 0) {
// Let's add a little pause to let the user know that the ball is on the side.
basic.pause(400)
// If the paddle is not at the same ``y`` coordinate, it missed the ball and we can trigger a game over. If not, we add a point to the score.
if (paddle.y() != ball.y()) {
game.gameOver()
} else {
game.addScore(1)
basic.pause(500)
}
}
// The ball moved and might be on a side, let's make sure it bounces.
ball.ifOnEdge_Bounce()
// If the ball is on the left side, slide it forward to change slightly the bouncing mechanics.
if (ball.x() == 0) {
ball.changeXBy(1)
}
})
```

View File

@ -1,87 +0,0 @@
# pong quiz answers
create the game Pong.
## Name
## Directions
Use this activity document to guide your work in the [pong tutorial](/lessons/pong/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values.
<br/>
```
ballX = 2
ballY = 1
```
## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values.
<br/>
```
ballXVelocity = 1
ballYVelocity = 1
```
## 3. Write the code that plots the initial position of the paddle and the ball.
<br/>
```
led.plot(0, paddleY)
led.plot(ballX, ballY)
```
## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.)
<br/>
```
input.onButtonPressed(Button.A, () => {
if (paddleNotUp()) {
led.unplot(0, paddleY)
paddleY = paddleY - 1
led.plot(0, paddleY)
}
})
```
## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.)
<br/>
```
input.onButtonPressed(Button.A, () => {
if (paddleNotDown()) {
led.unplot(0, paddleY)
paddleY = paddleY + 1
led.plot(0, paddleY)
}
})
```
## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".)
<br/>
```
if (ballY == 4 || ballY == 0) {
ballYVelocity = (-1) * ballYVelocity
}
```
## 7. Write the code to move the ball. (Hint: look at the function "move ball".)
<br/>
```
led.unplot(ballX, ballY)
ballX = ballX + ballXVelocity
ballY = ballY + ballYVelocity
```

View File

@ -1,40 +0,0 @@
# pong quiz
create the game Pong.
## Name
## Directions
Use this activity document to guide your work in the [pong tutorial](/lessons/pong/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values.
<br/>
## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values.
<br/>
## 3. Write the code that plots the initial position of the paddle and the ball.
<br/>
## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.)
<br/>
## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.)
<br/>
## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".)
<br/>
## 7. Write the code to move the ball. (Hint: look at the function "move ball".)
<br/>

View File

@ -1,77 +0,0 @@
# snowflake fall challenges
These challenges will allow you to make an exploding rectangle. #docs
**Challenge 0**
This [guided tutorial](https://test.microbit.co.uk/td/lessons/rectangle-explosion/tutorial) will help you create a snowflake animation!
```
basic.forever(() => {
basic.showAnimation(`
. . . . .
. . # . .
. # # # .
. . # . .
. . . . .
`, 400)
})
```
**Challenge 1**
Let's begin creating our falling effect by adding another snowflake with `show animation` that displays a different snowflake pattern after the first one.
```
basic.forever(() => {
basic.showAnimation(`
. . . . .
. . # . .
. # # # .
. . # . .
. . . . .
`, 400)
basic.showAnimation(`
. . . . . . . # . .
. . # . . . # . # .
. # # # . # . . . #
. . # . . . # . # .
. . . . . . . # . .
`, 400) // ***
})
```
**Challenge 2**
To finalize our snowflake fall, let's add a different snowflake pattern.
```
basic.forever(() => {
basic.showAnimation(`
. . . . .
. . # . .
. # # # .
. . # . .
. . . . .
`, 400)
basic.showAnimation(`
. . . . . . . # . .
. . # . . . # . # .
. # # # . # . . . #
. . # . . . # . # .
. . . . . . . # . .
`, 400)
basic.showAnimation(`
. . . . . . . # . . . # . # .
. . # . . . # . # . # # . # #
. # # # . # . . . # . . . . .
. . # . . . # . # . # # . # #
. . . . . . . # . . . # . # .
`, 400) // ***
})
```
**Challenge 3**
If you notice, we have three `basic->show animation()` functions. Try to create the snowflake fall effect by just using one `basic->show animation()`.

View File

@ -1,46 +0,0 @@
# return challenges
This script will teach you how to create a function and use an output parameter. #docs
### Challenge 0
Welcome! This [guided tutorial](/lessons/return/tutorial) will help you code the following script!
```
let original1 = 5
input.onButtonPressed(Button.A, () => {
let doubled = doubleIt_(5)
basic.showNumber(doubled, 150) // ***
})
```
### Challenge 1
Create a new function called `square` that returns squares the number passed into the function. (Squaring means that you multiply the number by itself.)
```
export function squareIt(n: number) : number {
let num: number
return n * n
return num
}
```
### Challenge 2
Add a condition to know when button `B` is pressed. We will use this condition in the last challenge.
```
let original = 5
input.onButtonPressed(Button.A, () => {
let one = doubleIt_(original)
basic.showNumber(one, 150)
})
input.onButtonPressed(Button.B, () => {
})
```
### Challenge 3
When the `B` button is pressed, display the square of the original value. Use the function `square it`. You should get the value 25.

View File

@ -1,235 +0,0 @@
# rock paper scissors book version
My script. #docs
Welcome! This guide will show you how to complete the challenges for the game of rock, paper, scissors!
## Challenge 1
### Step 16
Awesome! You have just created your game of rock paper scissors. However, why don't we add a little more to it? We can keep track of your score against the @boardname@ using global variables. Create a global variable to keep track of the wins against the @boardname@. To do so, click on `add new`, then `Data`, and then `Number`.
```
var wins: number = 0
```
### Step 17
At the beginning of the game, you don't have any wins against the @boardname@. As a result, let's set the `data->wins` variable to 0 at the top of your main function.
```
wins = 0 // ***
input.onGesture(Gesture.Shake, () => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset = 5 * Math.random(3)
img.showImage(offset)
})
```
### Step 18
Now let's keep track of wins by using button `A`. Every time button `A` is pressed, we want to increment `data->wins` by 1. We can begin by adding a condition `input->on button pressed("A")`.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img1 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset1 = 5 * Math.random(3)
img1.showImage(offset1)
})
input.onButtonPressed(Button.A, () => {
}) // ***
```
### Step 19
Nice! Now that we added the condition for when button `A` is pressed, we can increment `data->wins` by 1. Add the following statement in the condition.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img2 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset2 = 5 * Math.random(3)
img2.showImage(offset2)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1 // ***
})
```
### Step 20
You have tracked the number of wins you have against the @boardname@. However, how will you ever know how many wins you have? After we increment `data->wins`, let's display the total number of wins you have.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img3 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset3 = 5 * Math.random(3)
img3.showImage(offset3)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150) // ***
basic.showNumber(wins, 150) // ***
})
```
* Tap `run` to run the program on the simulator. Notice the number of wins you have against the @boardname@.
## Challenge 2
### Step 21
You have managed to keep score of the number of wins you have against the @boardname@. However, what about losses? Let's begin by creating another global variable to keep track of losses.
```
var losses: number = 0
```
### Step 22
Add a condition for when button `B` is pressed. When this occurs, we will increment your losses against the @boardname@ by 1. Let's hope that this button will not be pressed too often!
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img4 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset4 = 5 * Math.random(3)
img4.showImage(offset4)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed(Button.B, () => {
}) // ***
```
### Step 23
Now let's continue where we left off. Just as we did for `data->wins` when button `A` is pressed, we need to increment `losses` by 1 when button `B` is pressed.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img5 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset5 = 5 * Math.random(3)
img5.showImage(offset5)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed(Button.B, () => {
losses = losses + 1 // ***
})
```
### Step 24
Let's also display the score when button `B` is pressed, just as we have done for button `A`. This will help us keep track of the number of wins and losses you have against the @boardname@.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img6 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset6 = 5 * Math.random(3)
img6.showImage(offset6)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150) // ***
basic.showNumber(wins, 150) // ***
basic.showString("LOSSES:", 150) // ***
basic.showNumber(losses, 150) // ***
})
```
### Step 25
You have managed to keep track of both the wins and losses you have against the @boardname@! But did you notice that you haven't updated something? Take a look at condition of `input->on button pressed("A")`.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img7 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset7 = 5 * Math.random(3)
img7.showImage(offset7)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
basic.showString("LOSSES:", 150) // ***
basic.showNumber(losses, 150) // ***
})
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150)
basic.showNumber(wins, 150)
basic.showString("LOSSES:", 150)
basic.showNumber(losses, 150)
})
```
* Tap the `run` button to run your game on the simulator. See if you can get more wins than the @boardname@ can!
Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the @boardname@. Challenge your friends to see who can get a better score against the @boardname@.

View File

@ -1,235 +0,0 @@
# rock paper scissors teacher guide
My script. #docs
Welcome! This guide will show you how to complete the challenges for the game of rock, paper, scissors!
## Challenge 1
### Step 16
Awesome! You have just created your game of rock paper scissors. However, why don't we add a little more to it? We can keep track of your score against the @boardname@ using global variables. Create a global variable to keep track of the wins against the @boardname@. To do so, click on `add new`, then `Data`, and then `Number`.
```
var wins: number = 0
```
### Step 17
At the beginning of the game, you don't have any wins against the @boardname@. As a result, let's set the `data->wins` variable to 0 at the top of your main function.
```
wins = 0 // ***
input.onGesture(Gesture.Shake, () => {
let img = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset = 5 * Math.random(3)
img.showImage(offset)
})
```
### Step 18
Now let's keep track of wins by using button `A`. Every time button `A` is pressed, we want to increment `data->wins` by 1. We can begin by adding a condition `input->on button pressed("A")`.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img1 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset1 = 5 * Math.random(3)
img1.showImage(offset1)
})
input.onButtonPressed(Button.A, () => {
}) // ***
```
### Step 19
Nice! Now that we added the condition for when button `A` is pressed, we can increment `data->wins` by 1. Add the following statement in the condition.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img2 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset2 = 5 * Math.random(3)
img2.showImage(offset2)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1 // ***
})
```
### Step 20
You have tracked the number of wins you have against the @boardname@. However, how will you ever know how many wins you have? After we increment `data->wins`, let's display the total number of wins you have.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img3 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset3 = 5 * Math.random(3)
img3.showImage(offset3)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150) // ***
basic.showNumber(wins, 150) // ***
})
```
* Tap `run` to run the program on the simulator. Notice the number of wins you have against the @boardname@.
## Challenge 2
### Step 21
You have managed to keep score of the number of wins you have against the @boardname@. However, what about losses? Let's begin by creating another global variable to keep track of losses.
```
var losses: number = 0
```
### Step 22
Add a condition for when button `B` is pressed. When this occurs, we will increment your losses against the @boardname@ by 1. Let's hope that this button will not be pressed too often!
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img4 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset4 = 5 * Math.random(3)
img4.showImage(offset4)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed(Button.B, () => {
}) // ***
```
### Step 23
Now let's continue where we left off. Just as we did for `data->wins` when button `A` is pressed, we need to increment `losses` by 1 when button `B` is pressed.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img5 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset5 = 5 * Math.random(3)
img5.showImage(offset5)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed(Button.B, () => {
losses = losses + 1 // ***
})
```
### Step 24
Let's also display the score when button `B` is pressed, just as we have done for button `A`. This will help us keep track of the number of wins and losses you have against the @boardname@.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img6 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset6 = 5 * Math.random(3)
img6.showImage(offset6)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
})
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150) // ***
basic.showNumber(wins, 150) // ***
basic.showString("LOSSES:", 150) // ***
basic.showNumber(losses, 150) // ***
})
```
### Step 25
You have managed to keep track of both the wins and losses you have against the @boardname@! But did you notice that you haven't updated something? Take a look at condition of `input->on button pressed("A")`.
```
wins = 0
input.onGesture(Gesture.Shake, () => {
let img7 = images.createImage(`
. . . . . # # # # # . . . . #
. # # # . # . . . # # # . # .
. # # # . # . . . # . # # . .
. # # # . # . . . # # # . # .
. . . . . # # # # # . . . . #
`)
let offset7 = 5 * Math.random(3)
img7.showImage(offset7)
})
input.onButtonPressed(Button.A, () => {
wins = wins + 1
basic.showString("WINS:", 150)
basic.showNumber(wins, 150)
basic.showString("LOSSES:", 150) // ***
basic.showNumber(losses, 150) // ***
})
input.onButtonPressed(Button.B, () => {
losses = losses + 1
basic.showString("WINS", 150)
basic.showNumber(wins, 150)
basic.showString("LOSSES:", 150)
basic.showNumber(losses, 150)
})
```
* Tap the `run` button to run your game on the simulator. See if you can get more wins than the @boardname@ can!
Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the @boardname@. Challenge your friends to see who can get a better score against the @boardname@.

View File

@ -1,7 +0,0 @@
# runaway pacman lessons
make a game to test hand-eye coordination.
Make a game to test hand-eye coordination
* [tutorial](/lessons/runaway-pacman/tutorial)

View File

@ -1,117 +0,0 @@
# runaway pacman quiz answers
create a game that is inspired by the classic arcade game Pac Man.
## Name
## Directions
Use this activity document to guide your work in the [runaway pacman tutorial](/lessons/runaway-pacman/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the the method name created that will set up the game board.
<br/>
```
initializeState()
```
## 2. Write the the method name created that will draw the player and the monster(s)
<br/>
```
redraw()
```
## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.)
<br/>
```
basic.forever(() => {
levelTime = levelTime + 12
basic.pause(12)
})
```
## 4. Write the code that will reset the time and continue playing if we have been eaten.
<br/>
```
if ( ! playing) {
levelTime = 0
playing = true
}
```
## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds.
<br/>
```
if (levelTime >= 5000) {
}
```
## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.)
<br/>
```
gameSuspended = true
```
## 7. Write the code to add a monster. (Hint: look in the function "add monster".)
<br/>
```
let m = new Entity()
monsters.push(m)
totalMonsters = totalMonsters + 1
```
## 8. Write the code that will restart the time to 0 after you begin the next level.
<br/>
```
levelTime = 0
```
## 9. Write the code that makes the player go either North or East when button 'A' is pressed.
<br/>
```
input.onButtonPressed(Button.A, () => {
let temp = math.abs(person.dirX) * (-1)
// {stcode}
// MACRO: stcode
person.dirX = math.abs(person.dirY) * (-1)
// {stcode}
// MACRO: stcode
person.dirY = temp
})
```
## 10. Write the code that makes the player go either South or West when button 'B' is pressed.
<br/>
```
input.onButtonPressed(Button.B, () => {
let temp1 = math.abs(person.dirX)
// {stcode}
// MACRO: stcode
person.dirX = math.abs(person.dirY)
// {stcode}
// MACRO: stcode
person.dirY = temp1
})
```

View File

@ -1,60 +0,0 @@
# runaway pacman quiz
create a game that is inspired by the classic arcade game Pac Man.
## Name
## Directions
Use this activity document to guide your work in the [runaway pacman tutorial](/lessons/runaway-pacman/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the the method name created that will set up the game board.
<br/>
## 2. Write the the method name created that will draw the player and the monster(s)
<br/>
## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.)
<br/>
## 4. Write the code that will reset the time and continue playing if we have been eaten.
<br/>
## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds.
<br/>
## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.)
<br/>
## 7. Write the code to add a monster. (Hint: look in the function "add monster".)
<br/>
## 8. Write the code that will restart the time to 0 after you begin the next level.
<br/>
## 9. Write the code that makes the player go either North or East when button 'A' is pressed.
<br/>
<br/>
<br/>
## 10. Write the code that makes the player go either South or West when button 'B' is pressed.
<br/>
<br/>
<br/>

View File

@ -1,30 +0,0 @@
# running time challenges
My script. #docs
**Challenge 0**
Great job! You have successfully completed the [Running Time tutorial](/lessons/running-time/tutorial) . You have a forever loop that declares a variable in it that holds the running time in milliseconds of the @boardname@ and then shows the seconds on the LED screen.
```
basic.forever(() => {
let now = input.runningTime()
basic.showNumber(now / 1000, 150)
})
```
**Challenge 1**
When button A is pressed, reset the time by subtracting the current time from the variable now.
```
basic.forever(() => {
let now1 = input.runningTime()
basic.showNumber(now1 / 1000, 150)
})
if (input.buttonIsPressed("A")) {
let now2 = 0 // ***
}
```
* Run the code to see if it works as expected.

View File

@ -1,64 +0,0 @@
# screen up and down challenges
The on screen up function.
**Challenge 0**
Congratulations! You have completed the [Screen Up/Down tutorial](/hqjwkb) . You should have an image of a heart created and shown when the screen is moved up.
```
input.onScreenUp(() => {
images.createImage(`
# # . # #
# # # # #
# # # # #
. # # # .
. . # . .
`).showImage(0)
})
```
**Challenge 1**
Now have the @boardname@ do something when the screen is moved downward. You can do this by calling the on screen down method. Do not do anything when you call the on screen down method.
```
input.onScreenUp(() => {
images.createImage(`
# # . # #
# # # # #
# # # # #
. # # # .
. . # . .
`).showImage(0)
})
input.onScreenDown(() => {
})
```
**Challenge 2**
When the @boardname@ is moved downward, create and show an image of an upside down heart.
```
input.onScreenUp(() => {
images.createImage(`
# # . # #
# # # # #
# # # # #
. # # # .
. . # . .
`).showImage(0)
})
input.onScreenDown(() => {
images.createImage(`
. . # . .
. # # # .
# # # # #
# # # # #
# # . # #
`).showImage(0) // ***
})
```

View File

@ -1,45 +0,0 @@
# screen wipe activity
Clear the screen by pressing buttons on the @boardname@.
### ~avatar avatar
This activity will teach how to clear the screen by pressing button ``A`` on the @boardname@.
### ~
You can use the `basic->clear screen` function to turn off all the LED on the screen. Let's illustrate this concept with a small script where the user has to press the button ``A`` to turn off the screen. Let's start by adding the code to show an animation.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400) // ***
```
We add another line of code that registers an **event handler** on the `input->on button pressed(A)` and calls `basic->clear screen`.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
basic.clearScreen() // ***
}) // ***
```
Run the script in the simulator or on the @boardname@ to see how this works!
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/screen-wipe/challenges)!
### ~

View File

@ -1,71 +0,0 @@
# screen wipe challenges
Coding challenges for the screen wipe tutorial. #docs
## Before we get started
Complete the [screen wipe](/lessons/screen-wipe) activity and your code will look like this:
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
```
**Challenge 1**
Create an event handler for Button "B".
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed(Button.B, () => {
})
```
**Challenge 2**
Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`.
```
basic.showAnimation(`
# # # # # # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
input.onButtonPressed(Button.A, () => {
basic.clearScreen()
})
input.onButtonPressed(Button.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!

View File

@ -1,45 +0,0 @@
# screen wipe quiz answers
clear the screen by pressing the "A" button after an animation has been played.
This is the answer key for the [screen wipe quiz](/lessons/screen-wipe/quiz).
## 1. What does the function "clear screen" do on the @boardname@?
This function turns off all the LED lights on the LED screen.
## 2. Write the line of code that creates and displays this animation.
![](/static/mb/lessons/screen-wipe-0.png)
<br/>
```
basic.showAnimation(`
# # # # . # # # # # . . . . . . . . . .
# # # # # # # # # # . . . . . . . . . .
. . . . . # # # # # # # # # # . . . . .
. . . . . # # # # # # # # # # # # # # #
. . . . . . . . . . . . . . . # # # # #
`, 400)
```
## 3. Write the condition that will detect when the @boardname@ is shaken.
<br/>
```
input.onGesture(Gesture.Shake, () => {
})
```
## 4. Write the code that will clear an animation from the screen after shaking the @boardname@.
<br/>
```
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
})
```

View File

@ -1,32 +0,0 @@
# screen wipe quiz
clear the screen by pressing the "A" button after an animation has been played.
## Name
## Directions
Use this activity document to guide your work in the [screen wipe tutorial](/lessons/screen-wipe/tutorial)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What does the function "clear screen" do on the @boardname@?
<br/>
## 2. We can show all of these images in one line of code. What method can we use to do this?
![](/static/mb/lessons/screen-wipe-0.png)
<br/>
## 3. How can the @boardname@ detect when it is shaken?
<br/>
<br/>
## 4. Write the code that will clear an animation from the screen after shaking the @boardname@.
<br/>

View File

@ -1,50 +0,0 @@
# set brightness challenges
These challenges will allow you to change the brightness of the @boardname@. docs
**Challenge 0**
[This tutorial](/lessons/set-brightness/tutorial) will show you how to set the brightness on the @boardname@.
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
```
**Challenge 1**
What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add a condition for `input->on button pressed("B")`.
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
input.onButtonPressed(Button.B, () => {
}) // ***
```
**Challenge 2**
Inside of the condition `input->on button pressed("B")`, add `led->set brightness(0)` to turn off the LEDs.
```
led.setBrightness(255)
led.plotAll()
input.onButtonPressed(Button.A, () => {
led.setBrightness(64)
})
input.onButtonPressed(Button.B, () => {
led.setBrightness(0) // ***
})
```
**Challenge 3**
Now, in the condition `input->on button pressed("B")`, add `basic->pause(1000)` and then set the brightness to a new value!
* `Run` your script to see the LEDs change brightness.

Some files were not shown because too many files have changed in this diff Show More