docs cleanup

This commit is contained in:
Peli de Halleux 2017-02-28 06:45:08 -08:00
parent 24c240c7de
commit ad2acb244a
246 changed files with 0 additions and 15424 deletions

View File

@ -1,17 +0,0 @@
# Command Line Interface
```sim
basic.forever(() => {
basic.showString("CLI<3")
})
```
It is possible to use the tools from a command line interface (CLI). The PXT CLI allows to
* edit, compile or deploy JavaScript programs
* can easily be integrated in most IDEs. It comes with built-in support for [Visual Studio Code](/code)!
* run a local web server for the web editor
* author packages using JavaScript and/or C++
Using the CLI assumes that you have some experience with programming and will require to install tools on your machine as well.
* **[LET'S GET STARTED](https://pxt.io/cli)**

View File

@ -1,16 +0,0 @@
# Visual Studio Code
[Visual Studio Code](https://code.visualstudio.com) is a Free Open Source code editor that you can use to edit your programs.
Working from Visual Studio code allows you to benefit from all the features
of a professional IDE while working with PXT: working with files,
git integration (or source control of your choice), hundreds of extensions.
* background compilation
* auto-completion
* pxt command line integration
**Follow [these instructions](https://pxt.io/cli)** to setup your machine and edit your programs in Visual Studio Code.
![](/static/mb/vscode.png)

View File

@ -1,93 +0,0 @@
# Device
All the bits and pieces that make up the BBC micro:bit
![](/static/mb/device-0.png)
### LED Screen and Status LED
The red lights are [LEDs](/device/screen) (light emitting diodes) and form a 5 x 5 LED Screen.
They can be set to on/off and the brightness can be controlled.
The yellow light on the back of the micro:bit is the status LED.
It flashes yellow when the system wants to tell the user that something has happened.
### Buttons
Buttons A and B are a form of input. When you press a button, it completes an electrical circuit.
The micro:bit can detect either of its two buttons being pressed/released and be programmed
to act on these events.
Button R on the back of the micro:bit is a system button. It has different uses.
When you have downloaded and run your code onto your micro:bit, press Button R to restart and run your program from the beginning.
### USB connection
When you plug in your micro:bit, it should appear as ``MICROBIT``.
If you accidentally hold down the reset button as youre plugging in your micro:bit,
the micro:bit will appear as a MAINTENANCE drive instead of ``MICROBIT``. This is known as maintenance mode.**
To continue programming your micro:bit YOU MUST unplug your USB and reconnect it. Check that the drive now shows as ``MICROBIT``.
**Use with caution. If you click on the drive while it shows as ``MAINTENANCE``,
you can see which version of firmware you have running on your micro:bit.
Firmware on your micro:bit should be up-to-date already.
You can find the version of firmware in the 'version.txt' file on the micro:bit. Further information on the firmware can be found here:
https://developer.mbed.org/platforms/Microbit/#firmware
### Compass
The compass can detect magnetic fields such as the Earths magnetic field.
As the micro:bit has this compass, it is possible to detect the direction it is moving in.
The micro:bit can detect where it is facing and movement in degrees.
This data can be used by the micro:bit in a program or be sent to another device.
### Accelerometer
There is an accelerometer on your micro:bit which detects changes in the micro:bits speed.
It converts analogue information into digital form that can be used in micro:bit programs.
Output is in milli-g. The device will also detect a small number of standard actions e.g. shake, tilt and free-fall.
### Pins
The pins can be a form of input or output.
There are labels for the input/output pins P0, P1, P2, which you can attach external sensors to such as thermometers or moisture detectors.
You can read more about large and small pins [here](/device/pins).
### Light level
The screen can also be used a light level sensor (it's a really cool trick).
### How do I connect the micro:bit to my computer?
Your micro:bit can be connected to your computer via a micro USB cable.
Data can be sent and received between the micro:bit and the computer so programs
can be downloaded from Windows, Macs and Chromebooks onto the micro:bit via this USB data connection.
You can read more information on how to run scripts on your micro:bit [here](/device/usb),
and about the error messages you might get [here](/device/error-codes).
### Powering your micro:bit
When your micro:bit is connected to your computer with the micro USB, it doesnt need another power source.
When your micro:bit isnt connected to your computer, tablet or mobile, you will need 2 x AAA 1.5 V batteries to power it.
The pins labelled 3V and GND are the power supply pins.
You can attach an external device such as a motor to these and power it using the battery or USB.
### Serial Communication
The micro:bit can send an receive data via [serial communication](/device/serial). The serial data can be transfered via USB or BLE.
### Bluetooth Low Energy (BLE) Antenna
You will see the label BLE ANTENNA on the back of your micro:bit. It is for a messaging service,
so that devices can talk to each other. The micro:bit is a peripheral
device which can talk to a central device like a smart phone or tablet that has Bluetooth Low Energy (BLE).
The micro:bit can send signals and receive signals from a central device so another BLE device can
control the micro:bit or the micro:bit can control another BLE device.
### Technical Information
The micro:bit has been designed to be a bare-board micro controller for use by children aged 11-12.
More information is available at the [BBC web site](http://www.microbit.co.uk/device).

View File

@ -1,19 +0,0 @@
# micro:bit - the device
The micro:bit is a very capable device with many components:
* [the USB connector](/device/usb)
* [the LED screen](/device/screen)
* [the buttons]
* [the accelerometer]
* [the compass]
* [the pins](/device/pins)
* [the battery plug]
The micro:bit embodies many fundamental concepts in computer science. To learn more, read:
* [the micro:bit - a reactive system](/device/reactive)
Sometimes, your micro:bit may display an error code. For more information, see:
* [the error codes](/device/error-codes)

View File

@ -1,47 +0,0 @@
# crocodile clips
The large holes at the bottom of the board are designed to attach alligator/crocodile clips
to create electrical circuit with other components.
# ~hint
**No crocodile clips!?!?!** Use wires or Aluminium foil! [Read more...](/device/foil-circuits)
# ~
## Connecting Crocodile Clips
The hole for ``P0`` and ``GND`` allow to grab the board on the side which makes for a great grip.
![](/static/mb/device/croc-clips/crocclipsclamped.jpg)
Pass one jaw in the hole and grab the side of the board with the other jaw.
![](/static/mb/device/croc-clips/sideclamp.jpg)
For the center holes, ``P1`` and ``P2``, you can also grab the bottom of the board but they are a bit harder to grip.
You can also grip the board between the jaws. In which case, you will want to make sure to avoid overlapping the jaws
with the other pins as it will create short-circuit in the board.
![](/static/mb/device/croc-clips/badclamp.jpg)
Adding a little tape helps keeping the crocodile clips in place.
![](/static/mb/device/croc-clips/frontclamp.jpg)
## Example: on pin pressed with random numbers
This example displays a random number every time the crocodile clip holds `GND` then connects and disconnects the `P0` pin.
Each time the crocodile clip is firmly connected and disconnected from pin `P0`, the micro:bit will return a random Number between 0 and the parameter limit.
```blocks
input.onPinPressed(TouchPin.P0, () => {
basic.showNumber(Math.random(10))
})
```
## See also
[micro:bit pins](/device/pins)

View File

@ -1,23 +0,0 @@
# Error codes
Your micro:bit may encounter a situation that prevents it from running your code. When this happens, a frowny face will appear on your micro:bit screen (see picture) followed by an error number.
Below is a list of error numbers and what they mean:
* **10** (`MICROBIT_I2C_LOCKUP`): the micro:bit's I2C bus is not working
* **20** (`MICROBIT_OOM`): there is no free memory on the micro:bit
```sim
basic.showLeds(`
# . . . #
# # . # #
. . . . .
. # # # .
# . . . #
`)
```
### See also
[Run scripts on your micro:bit](/device/usb)

View File

@ -1,52 +0,0 @@
# foil circuits
The large holes at the bottom of the board are designed to attach alligator/crocodile clips
to create electrical circuit with other components.
If you do not have crocodile clips at hand, dyou can use wires or even Aluminium foil to acheive the same result.
We will show you how to connect the micro:bit to headphones using Alumunium foil and tape.
https://youtu.be/mhXYyPuvpz0
### Materials
* micro:bit and battery pack (you can also power it via USB)
* a small piece of cardboard
* Aluminium foil
* tape
### Assembly instructions
Tape the micro:bit and battery pack to the card board. Make sure to remove the batteries while you are building your circuit.
![](/static/mb/device/croc-clips/microbitattached.jpg)
Cut the thinest strip of foil possible and roll it into a cable. You can also try to fold, whatever works for you.
Build two of those wires.
![](/static/mb/device/croc-clips/foilcut.jpg)
Place the foil wire on the ``GND`` pin and attach with a piece of tape. Press hard to get the best connection between
the foil and the pin board. Make sure the foil is not overlapping with the other pins!
![](/static/mb/device/croc-clips/groundconnected.jpg)
Place the second wire on the ``P0`` pin the same way. Make sure the wire does not overlap with the other pins!
![](/static/mb/device/croc-clips/microbitconnect.jpg)
Tape the headphone jack connector to the cardboard and roll the wire coming from ``GND`` around the metal base.
Make sure the wire does not touch the other metal rings on the jack.
![](/static/mb/device/croc-clips/jackground.jpg)
Tape the second wire on the head of the jack connector.
![](/static/mb/device/croc-clips/jackconnect.jpg)
![](/static/mb/device/croc-clips/foilcircuit.jpg)
## See also
[micro:bit pins](/device/pins)

View File

@ -1,63 +0,0 @@
# micro:bit pins
The micro:bit pins
![](/static/mb/device/pins-0.png)
The micro:bit has 25 external connections on the edge connector of the board, which we refer to as pins. The edge connector is the grey area on the right side of the figure above.
There are five large pins, that are also connected to holes in the board labelled: 0, 1, 2, 3V, and GND. And along the same edge, there are 20 small pins that you can use when plugging the micro:bit into an edge connector.
### Large pins
You can easily attach crocodile clips or 4mm banana plugs to the five large pins.
The first three, labelled 0, 1 and 2 are flexible and can be used for many different things - which means they are often called general purpose input and output (shortened to GPIO). These three pins also have the ability to read analogue voltages using something called an analogue-to-digital converter (ADC). They all have the same function:
* **0**: GPIO (general purpose digital input and output) with analogue to digital convertor (ADC).
* **1**: GPIO with ADC
* **2**: GPIO with ADC
The other two large pins (3V and GND) are very different!/td/td
### ~hint
Watch out! The pins labelled 3V and GND relate to the power supply of the board, and they should NEVER be connected together.
### ~
*power input*: If the micro:bit is powered by USB or a battery, then you can use the 3V pin as a *power output* to power peripherals with.
* **3V**: *3 volt power output* or *power input*. (1) *power output*: If the micro:bit is powered by USB or a battery, then you can use the 3V pin as a power output to power peripherals with; (2) *power input*: If the micro:bit is not being powered by USB or battery, you can use the 3V pin as a power input to power the micro:bit
* **GND**: attaches to ground in order to complete a circuit (required when using the 3V pin)
If you hold the GND pin with one hand, you can program the microbit to detect yourself touching the 0,1 or 2 pins with your other hand, giving you three more buttons to experiment with (you just used your body to complete an electrical circuit).
### Small pins
There are 20 small pins numbered sequentially from 3-22 (these pins are not labeled on the micro:bit, however, they are labelled in the picture above).
Unlike the three large pins that are dedicated to being used for external connections, some of the small pins are shared with other components on the micro:bit board. For example, pin 3 is shared with some of the LEDs on the screen of the micro:bit, so if you are using the screen to scroll messages, you cant use this pin as well.
* **pin 3**: GPIO shared with LED Col 1 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.
* **pin 4**: GPIO shared with LED Col 2 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.
* **pin 5**: GPIO shared with Button A. This lets you trigger or detect a button "A" click externally. This pin has a pull-up resistor, which means that by default it is at voltage of 3V. To replace button A on the micro:bit with an external button, connect one end of the external button to pin 4 and the other end to GND. When the button is pressed, the voltage on pin 4 is pulled down to 0, which generates a button click event.
* **pin 6**: GPIO shared with LED Col 9 of the LED screen; can be used for digital I/O when the LED screen is turned off.
* **pin 7**: GPIO shared with LED Col 8 of the LED screen; can be used for digital I/O when the LED screen is turned off.
* **pin 8**: Dedicated GPIO, for sending and sensing digital signals.
* **pin 9**: GPIO shared with LED Col 7 of the LED screen; can be used for digital I/O when the LED screen is turned off.
* **pin 10**: GPIO shared with LED Col 3 of the LED screen; can be used for ADC and digital I/O when the LED screen is turned off.
* **pin 11**: GPIO shared with Button B. This lets you trigger or detect a button “B” click externally.
* **pin 12**: this GPIO pin has been reserved to provide support for accessibility.
* **pin 13**: GPIO that is conventionally used for the serial clock (SCK) signal of the 3-wire Serial Peripheral Interface (SPI) bus.
* **pin 14**: GPIO that is conventionally used for the Master In Slave Out (MISO) signal of the SPI bus.
* **pin 15**: GPIO that is conventionally used for the Master Out Slave In (MOSI) signal of the SPI bus.
* **pin 16**: Dedicated GPIO (conventionally also used for SPI Chip Select function).
* **pins 17 and 18**: these pins are wired to the 3V supply, like the large 3V pad.
* **pins 19 and 20**: implement the clock signal (SCL) and data line (SDA) of the I2C bus communication protocol. With I2C, several devices can be connected on the same bus and send/read messages to and from the CPU. Internally, the accelerometer and the compass are connected to i2c.
* **pins 21 and 22**: these pins are wired to the GND pin and serve no other function
### Connecting to the small pins
It is recommended that an edge connector be acquired to connect to the small pins. More information on compatible edge connectors will be available later.

View File

@ -1,158 +0,0 @@
# The micro:bit - a reactive system
### Computing systems
What sort of a *computing system* is the micro:bit?
### ~hint
There are different types of computing systems, to address different kinds of problems that arise in practice: *transaction processing systems* are used by banks to handle huge numbers of financial transactions by their customers; *distributed systems* make a set of networked computers appear as one big computer (like Googles search engine); there are also *parallel systems*, such as graphic cards, which perform a huge number of primitive operations simultaneously, using a great number of small processing cores.
### ~
The micro:bit is a *reactive system* it reacts continuously to external events, such as a person pressing the A button of the micro:bit or shaking the device. The reaction to an event may be to perform a computation, update variables, and change the display. After the device reacts to an event, it is ready to react to the next one. If this sounds like a computer game, thats because most computer games are reactive systems too!
### Responsiveness
We want reactive systems to be responsive, which means to react in a timely manner to events. For example, when you play a computer game, its frustrating if you press a button to make a character jump, but it doesnt immediately jump. A delay in reacting, or lack of responsiveness , can be the difference between life and death, both in the real and virtual worlds.
Lets consider a simple example: you want to program your micro:bit to accurately count the number of times the A button has been pressed and continuously display the current count on the 5x5 [LED screen](/device/screen). Because the LED screen is small, we can only display one digit of a number at a time on it. The [show number](/reference/basic/show-number) function will scroll the digits of a number across the screen so you can read it.
Lets say that the current count is 42 and the number 42 is scrolling across the LED screen. This means there is some code executing to perform the scroll. So, what should happen if you press the A button during the scroll? It would be a bad idea to ignore the button press, so some code should record the occurrence of the button press. But we just said there already is code running in order to scroll the number 42! If we wait until the code scrolling the 42 has finished to look for a button press, we will miss the button press. We want to avoid this sort of unresponsiveness.
### Concurrency
To be responsive, a reactive system needs to be able to do several things at the same time (concurrently), just like you can. But the micro:bit only has one CPU for executing your program, which means it can only execute one program instruction at a time. On the other hand, it can execute millions of instructions in a single second. This points the way to a solution.
Think about how a motion picture projector works - it projects only 24 frames per second, yet this is good enough to provide the illusion of fluid motion on the screen. The micro:bit can execute millions of instructions per second, so it seems quite possible for the device to both to smoothly scroll the number 42 across the LED screen while looking for button presses and counting them.
Lets think about three sequences of instructions:
* Sequence S1 contains the instructions (lets say several hundred thousand or so) that scroll the number 42 across the LED screen;
* Sequence S2 contains a few instructions to check if button A is pressed;
* Sequence S3 contains a few instructions to increment a counter.
In order to be responsive, we would like to *interrupt* the execution of sequence S1 *periodically* to execute the sequence S2, which will check if button A is pressed, which looks like:
TODO Diagram
The result is that it takes sequence S1 a little longer to complete, due to the interruptions to execute sequence S2, but we are checking often enough to detect a press of button A . When S2 detects a press of button A, then the sequence S3 can be executed before S1 resumes:
TODO Diagram
As well soon see, there are other choices for how the sequences can be ordered to achieve the desired result.
### The micro:bit scheduler and queuing up subprograms
The micro:bits *scheduler* provides the capability to concurrently execute different code sequences, relieving us of a lot of low-level programming. In fact, scheduling is so useful that it is a part of every *operating system*!
The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses.
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count++;
})
basic.forever(() => {
basic.showNumber(count, 150)
})
```
The program above contains three statements that execute in order from top to bottom.
The first statement initializes the global variable `count` to zero.
```blocks
let count = 0
```
The second statement informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the global variable `count` by one.
```blocks
let count = 0
// ...
input.onButtonPressed(Button.A, () => {
count++;
})
```
The third statement queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of global variable `count` on the LED screen. The third statement
```blocks
let count = 0
// ...
basic.forever(() => {
basic.showNumber(count, 150)
})
```
The function ends after the execution of these three statements, but this is not the end of program execution! Thats because the function queued the `forever` loop for execution by the scheduler.
The second job of the scheduler is to periodically interrupt execution to read (poll) the various inputs to the micro:bit (the buttons, pins, etc.) and fire off events (such as “button A pressed”). Recall that the firing of an event causes the event handler subprogram associated with that event to be queued for later execution. The scheduler uses a timer built into the micro:bit hardware to interrupt execution every 6 milliseconds and poll the inputs, which is more than fast enough to catch the quickest press of a button.
### Cooperative passing of control
How does the forever loop get to start execution? Furthermore, once the forever loop is running, how does any other subprogram (like the event handler that increments the count) ever get a chance to execute?
The answer is “cooperation” and “passing”. Think of a football team doing a drill there is one ball and each footballer gets to dribble the ball for a certain number of touches, after which they pass to another footballer. A footballer who never passes prevents all other footballers from dribbling. A cooperative footballer always passes to some other footballer after taking a few touches.
If you hadnt guessed already, a footballer represents subprogram and dribbling the ball corresponds to that subprogram executing. Only one subprogram gets to execute at a time, as there is only one ball (processor). Footballer Alice passing the ball to footballer Bob corresponds to stopping execution of Alices subprogram (and remembering where it stopped) and starting/resuming execution of Bobs subprogram.
We will call this “passing control of execution” rather than “passing the ball”. However, in the world of the micro:bit, the concurrently executing subprograms are not aware of each other, so they dont actually pass control directly to one another. Rather they pass control of execution back to the scheduler and the scheduler determines the subprogram to pass control to next. The programmer inserts a call to the `pause` function to indicate a point in the subprogram where control of execution passes to the scheduler. Also, when a subprogram ends execution, control passes to the scheduler.
Lets take a look at the implementation of the `basic.forever` function to see an example of cooperative scheduling:
```typescript
function forever(body: () => void) {
control.inBackground(() => {
while(true) {
body()
basic.pause(20)
}
})
}
```
The `forever` loop actually is a function that takes a subprogram (an *Action* in Touch Develop) as a parameter. The function uses the `control -> in background` function of the micro:bit runtime to queue a `while true` loop for execution by the scheduler. The while loop has two statements. The first statement runs the subprogram represented by the `body` parameter. The second statement passes control to the scheduler (requesting to “sleep” for 20 milliseconds).
Though the `while true` loop will repeatedly execute the body subprogram, between each execution of the body it will permit the scheduler to execute other subprograms. If the while loop did not contain the call to `pause`, then once control passed into the while loop, it would never pass back to the scheduler and no other subprogram would be able to execute (unless the body subprogram contained a call to `pause` itself).
### Round-robin scheduling
Now, we come to the third and final job of the scheduler, which is to determine which subprogram to pass control to next. The scheduler uses two queues to perform this task, the sleep queue and the run queue. The sleep queue contains the subprograms that have called the pause function and still have time left to sleep. The run queue contains all the non-sleeping subprograms, such as the event handlers queued by the firing of an event.
The scheduler moves the subprogram that has just paused into the sleep queue and then removes the subprogram at the head of the run queue and resumes its execution. Once a subprograms sleep period is over, the scheduler moves it from the sleep queue to the back of the run queue.
The property of such round-robin scheduling is that under the assumption that every subprogram periodically enters the sleep queue, then every subprogram will periodically get a chance to execute.
### Putting it all together
Lets go back to the `count button presses` function and revisit its execution based on what we have learned about the micro:bit scheduler. As detailed before, the function executes three steps to: (1) set up the event handler for each press of button A; (2) queue the forever loop to the run queue; (3) initialize the global variable `count` to zero.
The function then ends execution and control passes back to the scheduler. Lets assume the user has not pressed any buttons . The scheduler finds the `forever` loop in the run queue and passes control to it. The loop first calls `basic -> show number(0,150)`. In the diagram below, we use “Show 0” to refer to the execution of this function:
![](/static/mb/device/reactive-3.png)
While "Show 0" (the blue sequence) is running, periodic interrupts by the scheduler (every 6 milliseconds) poll for button presses and queue an event handler for each press of button A. Lets say that one button press takes place during this time, as shown above. This will cause an event handler (labelled “inc”) to be queued for later execution by the scheduler. Once the "Show 0" has completed, the loop then calls `basic -> pause(20)` to put the forever loop to sleep for 20 milliseconds and give the scheduler an opportunity to run any newly queued event handler. Control passes to the “inc” event handler which will increment the global variable `count` from 0 to 1 and then complete, returning control to the scheduler. At some point, the `forever` loop moves from the sleep queue to the run queue; the `forever` loop then will resume and call `basic -> show number(1,150)`.
### Final thoughts
Through this example, we have seen that the micro:bit scheduler enables you to create a program that is composed of concurrent subprograms. In essence, the programmer needs to only think about the concurrent subprograms cooperatively passing control back to the scheduler, making sure no subprogram hogs control (or “dribbles the ball without passing”) for too long. While a subprogram runs, the scheduler polls the buttons and other IO peripherals at a high frequency in order to fire off events and queue event handlers for later execution, but this is invisible to the programmer.
As a result, you can easily add a new capability to the micro:bit by just adding a new subprogram. For example, if you want to add a reset feature to the counter program, all you need to do is add a new event handler for a press of button B that sets the global variable "count" to zero, as shown below:
```typescript
export function countButtonPressesWithReset() {
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
input.onButtonPressed(Button.B, () => {
count = 0
})
}
```

View File

@ -1,100 +0,0 @@
# LED screen
The micro:bit LED screen
```sim
basic.showLeds(`
# . # . #
. # . # .
# . # . #
. # . # .
# . # . #
`);
```
The micro:bit LED screen consists of 25 red LED lights arranged in a 5X5 grid (5 LEDs across by 5 LEDs down).
In the screen above, we created a checkerboard pattern using the LEDs.
### Which LED?
You use `(x ,y)` coordinates to specify a particular LED in the grid;
where `x` is the horizontal position (0,1,2,3,4) and `y` is the vertical position
(0, 1, 2, 3, 4).
To figure out the ``x``, ``y`` coordinates, position your micro:bit horizontally, like a credit card (see picture above).
Here are the x, y coordinates for the LEDs in the 5X5 grid:
`(0,0)` `(1,0)` `(2,0)` `(3,0)` `(4,0)`
`(0,1)` `(1,1)` `(2,1)` `(3,1)` `(4,1)`
`(0,2)` `(1,2)` `(2,2)` `(3,2)` `(4,2)`
`(0,3)` `(1,3)` `(2,3)` `(3,3)` `(4,3)`
`(0,4)` `(1,4)` `(2,4)` `(3,4)` `(4,4)`
The x, y coordinates for the LED in the centre of the grid are `(2,2)`. Starting from `(0,0)` count over 2 columns and then down 2 rows.
### Check your understanding
Which LEDs are turned on in the checkboard pattern above?
### Row, column - 1
Since the row and column numbers start at 0, an easy way to figure out the (x,y) coordinates
is to subtract 1 from the row and column number (when counting from 1).
In other words, to specify the LED in the 4th column 5th row, subtract 1 from each number to get coordinates `(3,4)`.
### Turn a LED on/off
Use [plot](/reference/led/plot) and [unplot](/reference/led/unplot) to turn a LED on or off
```blocks
led.plot(0,0);
led.plot(1,1);
basic.pause(1000);
led.unplot(0,0);
basic.pause(1000);
led.unplot(1,1);
```
### Is a LED on/off?
Use the [point](/reference/led/point) function to find out if a LED is on or off.
```blocks
if(led.point(0,0)) {
}
```
### Display images, strings and numbers
Instead of turning individual LEDs on or off, as above, you can display an [image](/reference/images/image) directly to the screen or show text/numbers on screen using the [show number](/reference/basic/show-number)/[show string](/reference/basic/show-string) function.
### The display buffer
The micro:bit runtime keeps an in-memory representation of the state of all 25 LEDS. This state is known as the "display buffer" and controls which LEDS are on and which are off. The plot/unplot/point functions access the display buffer directly. On the other hand, the functions that show an image, number or string overwrite the buffer completely. To illustrate, first try running this code sequence
```blocks
basic.showString("d")
led.plot(0, 0)
```
You will see the letter "d" displayed as well as the LED in position `0,0` lit up. Now try reversing the order of the two statements above:
```blocks
led.plot(0, 0)
basic.showString("d", 150)
```
You will not see the LED at position `0,0` lit up because the `show string` function overwrites the whole display buffer.
### Pins: P3, P4, P6, P7, P9, P10
These pins are coupled to the LED matrix display, and also its associated ambient light sensing mode.
To disable the display driver feature (which will automatically disable the light sensing feature) use the function [led.enable](/reference/led/enable).
More information at http://tech.microbit.org/hardware/edgeconnector_ds/ .

View File

@ -1,93 +0,0 @@
# Serial
The [serial](/reference/serial) supports [serial communication](https://en.wikipedia.org/wiki/Serial_port) between the BBC micro:bit and another computer. Basically, this allows you to send data from the micro:bit to your own computer. This is very useful for debugging purposes: you can add `write line` statements in your code and see them display on your computer as the program executes.
The code below shows a simple script that sends a line when the BBC micro:bit starts and another line each time the button ``A`` is pressed.
```blocks
serial.writeLine("started...")
input.onButtonPressed(Button.A, () => {
serial.writeLine("A pressed")
})
```
Data is also automatically streamed to serial by the ** bar graph** block
and picked up by the editor. This data can be streamed to the cloud as well.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration(Dimension.X), 0);
});
```
## How to read the micro:bit's serial output from your computer
Unfortunately, using the serial library requires quite a bit of a setup.
### BBC micro:bit Chrome Extension
If you are using the Google Chrome browser, you can use our extension to get serial data streaming in the editor.
* Install the [Extension for BBC micro:bit](https://chrome.google.com/webstore/detail/extension-for-bbc-microbi/cihhkhnngbjlhahcfmhekmbnnjcjdbge?hl=en-US) on the Chrome Web Store.
* Restart Chrome and open the [web editor](https://pxt.microbit.org)
* The serial data will show below the simulator
### Windows
You must install a device driver (for the computer to recognize the
serial interface of the micro:bit); then, you must also install a
terminal emulator (which is going to connect to the micro:bit and read
its output).
* Follow the instructions at
https://developer.mbed.org/handbook/Windows-serial-configuration to
install the device driver.
* Instructions for installing a terminal emulator are below.
#### Windows > Tera Term
* Install the terminal emulator [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer.
Once both the driver and the terminal emulator are installed, plug in the micro:bit and wait until the device is fully setup. Then, open TeraTerm.
* Hit `File` > `New Connection`
* Check "Serial"; in the dropdown menu, pick the COM port that says "mbed Serial Port". Hit `Ok`.
* In the menus, hit `Setup` > `Serial Port` and set the baud rate to `115200`.
You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to erase the default configuration file with a new one so that you don't have to type in the settings again.
Please note that Windows will assign you a different COM port if you plug in another micro:bit. If you're juggling between micro:bits, you'll have to change the COM port every time.
#### Windows > Putty
If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions.
* Open Windows's [Device Manager](https://windows.microsoft.com/en-us/windows/open-device-manager); expand the section called "Ports (COM & LPT)"; write down the com number for "mbed Serial Port" (e.g. COM14)
* Open PuTTY; on the main screen, use the following settings: Serial / COM14 / 115200. Replace COM14 with the COM port number you wrote down previously. Feel free to type in a name and hit "Save" to remember this configuration.
![](/static/mb/serial-library-0.png)
* (optional): in the "Terminal" section, check "implicit cr in every lf"
![](/static/mb/serial-library-1.png)
### Linux
* Install the program `screen` if it is not already installed.
* Plug in the micro:bit.
* Open a terminal.
* Find which device node the micro:bit was assigned to with the command `ls /dev/ttyACM*`.
* If it was `/dev/ttyACM0`, type the command `screen /dev/ttyACM0 115200`. If it was some other device node,
use that one in the command instead. **Note:** You may need root access to run `screen`
successfully. You can probably use the command `sudo` like this: `sudo screen /dev/ttyACM0 115200`.
* To exit `screen`, type `Ctrl-A` `Ctrl-D`.
Alternative programs include `minicom` and so on.
### Mac OS
* Plug in the micro:bit
* Open a terminal
* `ls /dev/cu.*` will return to you a list of serial devices; one of them will look like `/dev/cu.usbmodem1422` (the exact number depends on your computer)
* `screen /dev/cu.usbmodem1422 115200` will open up the micro:bit's serial output. To exit, hit `Ctrl-A` `Ctrl-D`.

View File

@ -1,25 +0,0 @@
# Simulator
The JavaScript simulator allows to test and execute most BBC micro:bit programs in the browser.
It allows to emulate sensor data or user interactions.
```sim
input.onButtonPressed(Button.A, () => {
basic.showString("A");
});
input.onButtonPressed(Button.B, () => {
basic.showString("B");
});
input.onPinPressed(TouchPin.P0, () => {
basic.showString("0");
});
input.onPinPressed(TouchPin.P1, () => {
basic.showString("1");
});
input.onPinPressed(TouchPin.P2, () => {
basic.showString("2");
});
input.temperature()
input.compassHeading()
input.lightLevel()
```

View File

@ -1,31 +0,0 @@
# Uploading programs on your micro:bit
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
![](/static/mb/device/usb-thin.jpg)
## Instructions
Pick the instructions for your operating system and browser:
* [Windows - Microsoft Edge](/device/usb/windows-edge)
* [Windows - Internet Explorer](/device/usb/windows-ie)
* [Windows - Chrome](/device/usb/windows-chrome)
* [Windows - Firefox](/device/usb/windows-firefox)
* [Mac - Safari](/device/usb/mac-safari)
* [Mac - Chrome](/device/usb/mac-chrome)
* [Mac - Firefox](/device/usb/mac-firefox)
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,69 +0,0 @@
# Uploading from Chrome for Mac
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-osx-device.png)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
When you select **Download** in Chrome, the file will appear at the bottom of
the browser. Click on the small arrow and select **Show in Finder**. This will
show the file in your download folder. Drag and drop the file onto your
`MICROBIT` drive.
![](/static/mb/device/usb-osx-chrome.png)
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,71 +0,0 @@
# Uploading from Firefox for Mac
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-osx-device.png)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
A dialogue box will appear, asking whether you would like to open or save your
hex file. Select **Save file** and click **OK** and the file will then appear in
your downloads in the top right of your browser. Right click on the file and
click on **Show in Finder** and the file will appear in your downloads folder.
Select the file and drag and drop it onto your `MICROBIT` drive.
![](/static/mb/device/usb-osx-firefox-1.jpg)
![](/static/mb/device/usb-osx-firefox-2.png)
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,68 +0,0 @@
# Uploading from Safari for Mac
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-osx-device.png)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
When you select **Download** in Safari a file called `Unknown` will be
downloaded into your Downloads folder. Open your Downloads folder and drag and
drop the file onto your `MICROBIT` drive, under Devices:
![](/static/mb/device/usb-osx-dnd.png)
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,24 +0,0 @@
# Troubleshooting Transfer
You cant drag and drop more than one hex file at once onto your micro:bit. If
you try to drag and drop a second hex file onto your micro:bit before the first
file has finished downloading, then the second file may fail in different ways.
When the first program has been written to the micro:bit, the drive will
disengage. If you drag and drop a second file at this point it may not find the
drive and the second write will fail.
The errors may look like this:
**Windows**
![](/static/mb/device/usb-windows-copy-file-error.jpg)
**Mac**
![](/static/mb/device/usb-osx-copy-file-error.png)
Or it may appear that there are two hex files on your micro:bit so the micro:bit
wont be able to run multiple files. To rectify this, unplug your micro:bit and
plug it in again. Make sure that your micro:bit appears as `MICROBIT` and not
`MAINTENANCE`.

View File

@ -1,79 +0,0 @@
# Uploading from Chrome for Windows
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
### ~hint
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
![](/static/uploader/tooltip.png)
### ~
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-windows-device.jpg)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
Your `.hex` file appears as a download at the bottom of the browser. Click on
the arrow next to the name of the file and then click **Show in folder**.
![](/static/mb/device/usb-windows-chrome.png)
Drag and drop the `.hex` file from the download folder onto the `MICROBIT` drive.
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
![](/static/mb/device/usb-windows-sendto.jpg)
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,89 +0,0 @@
# Uploading from Edge on Windows
How to compile, transfer, and run a program on your micro:bit on **Microsoft Edge**.
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
### ~hint
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
![](/static/uploader/tooltip.png)
### ~
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-windows-device.jpg)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
A message will appear at the bottom of the browser asking what you want to do
with the file. Click **Save**:
![](/static/mb/device/usb-windows-edge-1.png)
Then click **Open folder** and drag and drop the file from your Downloads to
your `MICROBIT` drive.
![](/static/mb/device/usb-windows-edge-2.png)
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* If you're using Windows, you can use **Send to** as described below
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
![](/static/mb/device/usb-windows-sendto.jpg)
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
If you want to save time, you can use the [micro:bit uploader](/uploader) to
automatically deploy hex files to your micro:bit. It works on Windows and is
compatible with any browser.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,86 +0,0 @@
# Uploading from Firefox on Windows
How to compile, transfer, and run a program on your micro:bit on **Firefox for Windows**.
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
### ~hint
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
![](/static/uploader/tooltip.png)
### ~
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-windows-device.jpg)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
A window will appear asking whether you want to save or open the `.hex` file.
Select **Save File** and then select **OK**.
![](/static/mb/device/usb-windows-firefox-1.png)
The file will then appear in your downloads in the top right of your browser.
Click the **folder icon** next to the filename to open it in Windows Explorer.
![](/static/mb/device/usb-windows-firefox-2.jpg)
Drag and drop the `.hex` file from the download folder onto the `MICROBIT` drive.
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* If you're using Windows, you can use **Send to** as described below
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
![](/static/mb/device/usb-windows-sendto.jpg)
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -1,86 +0,0 @@
# Uploading from Internet Explorer on Windows
While you're writing and testing your programs, you'll mostly be [running them
in the simulator](/device/simulator), but once you've finished your program you
can **compile** it and run it on your micro:bit.
The basic steps are:
1. Connect your micro:bit to your computer via USB
2. Click **Download** and download the `.hex` file
3. Copy the `.hex` file from your computer onto the micro:bit drive
### ~hint
You can use the [micro:bit uploader](/uploader) to automatically deploy ``.hex`` files to your micro:bit!
![](/static/uploader/tooltip.png)
### ~
## Requirements
You need the following things to transfer and run a script on your micro:bit:
* A-Male to Micro USB cable to connect your computer to your micro:bit. This is
the same cable that is commonly used to connect a smart phone to a computer.
* A PC running Windows 7 or later, or a Mac running OS X 10.6 or later
## Step 1: Connect your micro:bit to your computer
First, connect the micro:bit:
1. Connect the small end of the USB cable to the micro USB port on your micro:bit.
2. Connect the other end of the USB cable to a USB port on your computer.
Your computer should recognise your micro:bit as a new drive. On computers
running Windows, `MICROBIT` appears as a drive under Devices and drives. On a Mac
it appears as a new drive under Devices.
![](/static/mb/device/usb-windows-device.jpg)
## Step 2: Download your program
1. Open your project on [pxt.microbit.org](https://pxt.microbit.org)
2. Click **Download**
3. When prompted, choose to **save** the compiled file onto your computer. The
prompt will be different depending on which browser you are using, or
whether you are using a Windows computer or a Mac
A message will appear at the bottom of the browser asking what you want to do
with the file. Click **Save**:
![](/static/mb/device/usb-windows-ie11-1.png)
Then click **Open folder** and drag and drop the file from your Downloads to
your `MICROBIT` drive.
![](/static/mb/device/usb-windows-ie11-2.png)
## Step 3: Transfer the file to your micro:bit
* Once you've found the folder containing your `.hex` file, drag and drop it
onto your `MICROBIT` drive
* If you're using Windows, you can use **Send to** as described below
* The LED on the back of your micro:bit flashes during the transfer (which
should only take a few seconds).
* Once transferred, the code will run automatically on your micro:bit. To rerun
your program, press the reset button on the back of your micro:bit. The reset
button automatically runs the newest file on the micro:bit.
**Send to**: If you're using Windows you use *Send to* in File Explorer:
In File Explorer, right-click on the hex file (created in Step 2 above), choose **Send to**, and then **MICROBIT**.
![](/static/mb/device/usb-windows-sendto.jpg)
By copying the script onto the `MICROBIT` drive, you have programmed it into the
flash memory on the micro:bit, which means even after you unplug the micro:bit,
your program will still run if the micro:bit is powered by battery.
### ~hint
Transfer not working? See some [troubleshooting tips](/device/usb/troubleshooting).
### ~

View File

@ -2,12 +2,6 @@
### @description Links to the documentation, reference and projects.
### @boardname@ reference
* [The @boardname@ APIs](/reference)
* [The @boardname@ device](/device)
### Language and data reference
* [Blocks language](/blocks)
* [JavaScript language](/javascript)

View File

@ -1,14 +0,0 @@
# Frequently Asked Questions
### @description Frequently asked questions and answers from our users.
## Which web sites do I need to unblock for pxt.microbit.org?
This is the list of domains that need to be unblocked to allow the web editor to load:
* https://pxt.microbit.org
* https://www.pxt.io
* https://trg-microbit.userpxt.io
* https://pxt.azureedge.net
Can't find your question? Please search for solutions or open a ticket at [support.microbit.org](https://support.microbit.org)!

View File

@ -1,43 +0,0 @@
# Getting started
### @description An activity for beginners to get started with the @boardname@
## ~avatar
Here are some challenges for you. Arrange the blocks in the editor
to make real programs that work!
## ~
Use the **Basic** drawer in the editor
to drag out and arrange three blocks to create this program:
```blocks
basic.forever(() => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
});
```
When this program runs, you will see a smiley face, then a blank
screen, then a smiley again -- it never stops! (That's because of the
``forever`` block.)
Click **Download** to move your program to the @boardname@!
Make sure to follow the instructions.
### ~button /getting-started/screen
NEXT: THE SCREEN
### ~

View File

@ -1,81 +0,0 @@
# Button A and button B
### ~avatar avatar
Buttons are great to build games!
### ~
This program will show the word **ANTEATER** on the LED
screen when you press button `A`.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showString("ANTEATER");
});
```
#### ~hint
The ``showString`` block can show letters, numbers, and punctuation
on the @boardname@ screen.
#### ~
Now try to unscramble these blocks in the editor so that the @boardname@
shows **BANANA** when you press button `B`.
```shuffle
input.onButtonPressed(Button.B, () => {
basic.showString("BANANA");
});
```
#### ~hint
You can find the letter `B` by clicking the letter `A` on the
``onButtonPressed`` block.
#### ~
Click **Download** to move your program to the @boardname@!
#### Your turn!
Can you combine these blocks so your program shows your real name
instead of **ANTEATER** when you press `A`, but _your secret agent
name_ instead of **BANANA** when you press `B`?
### Pins
You can also use the pins as buttons. (The pins are the holes in the
metal stripe at the bottom of the @boardname@ board.) For example, hold
the ``GND`` button with one hand and touch the ``0`` pin (called
``P0``) with your other hand to tell the @boardname@ you're pressing it.
Unscramble the blocks in the editor to show a heart when you touch
pin ``P0``.
```shuffle
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
. # . # .
# . # . #
# . . . #
. # . # .
. . # . .`);
});
```
Click **Download** to move your program to the @boardname@!
## ~hint
Try this experiment: find a friend and hold hands. Touch the ``GND``
pin while your friend presses the ``P0`` pin. You should see the
heart! The electric current is going through your bodies and across
your handshake to make it happen!
## ~
### ~button /getting-started/shake
NEXT: SHAKE
### ~

View File

@ -1,78 +0,0 @@
# The amazing coin flipper
### ~avatar avatar
Are you trying to choose whether to play soccer or go to the movies
instead, or which toppings to have on your pizza? Build a coin
flipping machine with the @boardname@ to choose for you!
### ~
Here are the blocks to make your coin flipper. When you press button
`B`, the coin flipper will show either `H` for heads or `T` for tails
on the LED screen.
```blocks
input.onButtonPressed(Button.B, () => {
if (Math.randomBoolean()) {
basic.showString("H");
} else {
basic.showString("T");
}
});
```
### ~hint
The ``pick random true or false`` block randomly tells the ``if``
block `true` or `false`. If the ``pick`` block picked `true`, the
``if`` block shows the letter `H`. Otherwise, it shows the letter `T`.
That's it!
### ~
### Keeping score
#### ~avatar
To keep track out of how many guesses you've won,
add these blocks to your coin flipper:
#### ~
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1);
});
input.onButtonPressed(Button.AB, () => {
basic.showNumber(game.score());
});
```
These blocks mean that if you press button `A`, you will add `1` to
your score, and if you press `A` and `B` together, the @boardname@ will
show your score.
When you're done, your coin flipping program should look like this:
```blocks
input.onButtonPressed(Button.B, () => {
if (Math.randomBoolean()) {
basic.showString("H");
} else {
basic.showString("T");
}
});
input.onButtonPressed(Button.A, () => {
game.addScore(1);
});
input.onButtonPressed(Button.AB, () => {
basic.showNumber(game.score());
});
```
Flip until your thumbs get tired!
### ~button /getting-started/rock-paper-scissors
NEXT: ROCK PAPER SCISSORS
### ~

View File

@ -1,205 +0,0 @@
# Rock Paper Scissors
### ~avatar avatar
Build a Rock Paper Scissors game with the @boardname@! You can play
the game with a friend who has it on a @boardname@. You can also play
it with friends who are just using their hands. (The game is built
like a coin flipper, but with three choices instead of two.)
### ~
## Step 1: Getting started
We want the @boardname@ to choose rock, paper, or scissors when you
shake it. Try creating an ``on shake`` block so when you shake the
@boardname@, it will run part of a program.
Clear up the blocks and add the blocks below.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
Next, when you shake the @boardname@, it should pick a random number from `0` to `2`
and store it in the variable `item`.
Add a ``set`` block with a variable. Then add a ``pick random`` block,
and store the random number in the variable,
like this:
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
})
```
### ~hint
No one can predict random numbers. That's what makes them great for Rock Paper Scissors!
### ~
Each possible number these blocks can make (`0`, `1`, or `2`) means a different picture.
We will show the right picture for that number on the LED screen.
## Step 2: Picking paper
Put an ``if`` block after the ``let`` block that checks whether
`item` is `0`. Make sure the ``if`` block has an ``else if`` part
and an ``else`` part.
Next, add a ``show leds`` block that shows a
picture of a piece of paper:
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
if (item == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (false) {
} else {
}
})
```
## Step 3: A random rock
Now we are going to add a new picture for the @boardname@ to show
when another random number comes up.
Make the ``else if`` part check if the variable `item` is `1`.
Then add a ``show leds`` block with a picture of a rock.
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
if (item == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (item == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
}
})
```
## Step 4: Suddenly scissors
Add a ``show leds`` block with a picture of scissors to the ``else`` part:
```blocks
input.onGesture(Gesture.Shake, () => {
let item = Math.random(3)
if (item == 0) {
basic.showLeds(`
# # # # #
# . . . #
# . . . #
# . . . #
# # # # #
`)
} else if (item == 1) {
basic.showLeds(`
. . . . .
. # # # .
. # # # .
. # # # .
. . . . .
`)
} else {
basic.showLeds(`
# # . . #
# # . # .
. . # . .
# # . # .
# # . . #
`)
}
})
```
### ~hint
You don't need to check if `item` is `2` because `2` is the only number left out of `0`, `1`, and `2`.
That's why you can use an ``else`` instead of an ``else if``.
### ~
Your game is ready!
Click **Download** to move your program to the @boardname@!
Have fun!
## Step 5: Are you the greatest?
Here is a way you can make your Rock Paper Scissors game better.
When button ``A`` is pressed,
the @boardname@ will add `1` to your score.
Open the ``Game`` drawer, and then add the block ``change score by 1`` to your program,
like this:
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
})
```
## Step 6: Prove you're the greatest!
After your @boardname@ can add `1` to the score, show how many wins you have.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1)
basic.showString("WINS:")
basic.showNumber(game.score())
})
```
## Step 7: Staying honest
Success! Your @boardname@ can track wins!
But what about losses?
Use the ``Game`` drawer to subtract `1` from your score when you press button `B`.
Here are all the blocks you will need:
```shuffle
input.onButtonPressed(Button.B, () => {
game.addScore(-1)
basic.showString("LOSSES:")
basic.showNumber(game.score())
})
```
Click **Download** to move your program to the @boardname@!
### ~button /projects
NEXT: PROJECTS!
### ~

View File

@ -1,98 +0,0 @@
# Screen
### ~avatar avatar
There are 25 bright LEDs on the @boardname@ screen. Let's use them to create some cool animations!
### ~
### Happy unhappy face
Draw an unhappy face instead of the blank screen. Click on the dots
in the second ``show leds`` block until it matches the blocks below.
Now you have an **animation** (cartoon) that shows a happy face,
then an unhappy one, then a happy one again, forever (or until
you turn off your @boardname@)!
```blocks
basic.forever(() => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
});
```
Click **Download** to move your program to the @boardname@!
### Your turn!
Pile up more ``show leds`` blocks to create an animation! Create an
animation with at least 5 pictures. What does this animation show?
```blocks
basic.forever(() => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# # # # #
. . . . .
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
basic.showLeds(`
. . . . .
. # . # .
. . . . .
# # # # #
. . . # #
`)
basic.showLeds(`
. . . . .
# . # . .
. . . . .
# . . . #
. # # # .
`)
basic.showLeds(`
. . . . .
. . # . #
. . . . .
# . . . #
. # # # .
`)
});
```
Click **Download** to move your program to the @boardname@!
#### ~hint
You can find the ``show leds`` block in the **Basic** part of the editor.
#### ~
### ~button /getting-started/buttons
NEXT: BUTTONS
### ~

View File

@ -1,24 +0,0 @@
# Shake
You can find when someone is shaking the @boardname@ by checking its
**accelerometer** (it finds whether the @boardname@ is speeding up or
slowing down).
Unscramble these blocks in the editor to show a frownie when someone
shakes the @boardname@. (Ouch!)
```shuffle
input.onGesture(Gesture.Shake, () => {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #`);
});
```
Click **Download** to move your program to the @boardname@!
### ~button /getting-started/coin-flipper
NEXT: COIN FLIPPER GAME
### ~

View File

@ -1,67 +0,0 @@
# Lessons
### @description Lessons to teach computer science and coding.
### @short Lessons
### ~column
## Beginner
* [Beautiful Image](/lessons/beautiful-image), show a beautiful image with show LEDs
* [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
* [Game of Chance](/lessons/game-of-chance), show a text message with game over
* [Smiley,](/lessons/smiley) smiley and frowney faces that transition on button pressed
* [Magic Logo,](/lessons/magic-logo) show an image on logo up
* [Snowflake Fall](/lessons/snowflake-fall), repeat a series of images with forever
* [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
* [Game Counter](/lessons/game-counter), displays the player's score with score and add points to score
* [Happy Birthday](/lessons/happy-birthday), create a popular song
### ~
### ~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 pick number
* [Counter](/lessons/counter), display a number with a variable
* [Love Meter](/lessons/love-meter), create a love meter with on pin pressed
* [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
* [Dice Roll](/lessons/dice-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
* [Temperature](/lessons/temperature), get the ambient temperature (degree Celsius °C)
* [Digi Yoyo](/lessons/digi-yoyo), create a counter with a while loop
* [Rotation Animation](/lessons/rotation-animation), control an animation with a boolean variable
* [Compass](/lessons/compass), displays the direction the @boardname@ is pointing with compass
* [Zoomer](/lessons/zoomer), measure the force with acceleration
* [Glowing Pendulum](/lessons/glowing-pendulum), construct a pendulum that glows using acceleration
* [Classic Beatbox](/lessons/classic-beatbox), make a beatbox music player with variables
### ~
### ~column
## Maker
* [Pogo](/lessons/pogo), create a pogo game to test your jumping abilities
## Science
* [Charting](/lessons/charting), measure and chart acceleration
* [Seismograph](/lessons/seismograph), create a seismograph with household items
## Advanced
* [Prank WiFi](/lessons/prank-wifi), create fake WiFi to trick your friends
* [Speed Button](/lessons/speed-button), code a speed game with running time
* [Headbands](/lessons/headbands), create a charades game with a collection of strings that hold the words
* [Hero](/lessons/hero), reconstruct the classic arcade game pac man with the @boardname@
* [Catch the Egg](/lessons/catch-the-egg-game), catch falling eggs in a basket with an acceleration controller
### ~
### @section full

View File

@ -1,32 +0,0 @@
# answering machine blocks lesson
Create an answering machine on the @boardname@
## Topic
Show String
## Quick Links
* [activity](/lessons/answering-machine/activity)
* [quiz](/lessons/answering-machine/quiz)
* [quiz answers](/lessons/answering-machine/quiz-answers)
* [challenges](/lessons/answering-machine/challenges)
## Prior learning / place of lesson in scheme of work
Learn how to creating a message with a **string**, `show string` to write your message. We will be learning how to create a message using simple commands, such as show string and on button pressed.
## Documentation
```cards
basic.showString('Hi!')
input.onButtonPressed(Button.A, () => {})
```
## Objectives
* learn how to show a string on the LED screen one character at a time
* learn how to use to register an event handler that will execute whenever an input button is pressed

View File

@ -1,23 +0,0 @@
# answering machine blocks activity
Learn to create an answering machine on the @boardname@
### ~avatar avatar
Let's learn how to create an answering machine!
### ~
We will use `show string` to show text on the LED screen. *String* is a common name for *text* in programming languages. The function `show string` scrolls the text column by column at a *150* milliseconds interval.
```blocks
basic.showString("ASK ME A QUESTION")
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/answering-machine/challenges)!
### ~

View File

@ -1,45 +0,0 @@
# answering machine blocks challenges
Coding challenges for the answering machine tutorial.
## Before we get started
Complete the [answering machine](/lessons/answering-machine/activity) activity and your code will look like this:
```blocks
basic.showString("ASK ME A QUESTION")
```
### Challenge 1
Now we need to reply after someone asks @boardname@ a yes or no question. We want to respond `YES` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YES`.
```blocks
basic.showString("ASK ME A QUESTION")
input.onButtonPressed(Button.A, () => {
basic.showString("Yes")
})
```
* `Run` the code to see if it works as expected.
### Challenge 2
What if @boardname@'s answer to the question is no? Let's have `NO` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the string `NO`.
```blocks
basic.showString("ASK ME A QUESTION")
input.onButtonPressed(Button.A, () => {
basic.showString("Yes")
})
input.onButtonPressed(Button.B, () => {
basic.showString("NO")
})
```
* `Run` the code to see if it works as expected.
### Challenge 3
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `MAYBE`.

View File

@ -1,38 +0,0 @@
# answering machine blocks quiz answers
Create an answering machine on the @boardname@.
This is the answer key for the [answering machine quiz](/lessons/answering-machine/quiz).
## 1. Define what `show string` does?
Answers may vary. This is a function that will show a string on the LED screen one character at a time (scrolling from left to right).
## 2. Draw which LED is ON after running this code
```blocks
basic.showString("Y")
```
![](/static/mb/lessons/answering-machine-0.png)
## 3. Draw which LED is ON after running this code
```blocks
basic.showString("Hi")
```
![](/static/mb/lessons/answering-machine-1.png)
## 4. If the rectangle below represents the @boardname@, write the code to display the letter "Z".
![](/static/mb/lessons/answering-machine-2.png)
```blocks
basic.showString("Z")
```

View File

@ -1,46 +0,0 @@
# answering machine blocks quiz
Create an answering machine on the @boardname@.
## Name
## Directions
Use this activity document to guide your work in the [answering machine activity](/lessons/answering-machine/activity).
Answer the questions while completing the activity. Pay attention to the dialogues!
## 1. Define what `show string` does?
## 2. Draw which LED is ON after running this code
```blocks
basic.showString("Y")
```
![](/static/mb/empty-microbit.png)
## 3. Draw which LED is ON after running this code
```blocks
basic.showString("Hi")
```
![](/static/mb/lessons/answering-machine-4.png)
## 4. If the rectangle below represents the @boardname@, write the code to display the letter "Z".
```blocks
basic.showString("Z")
```

View File

@ -1,36 +0,0 @@
# beautiful image lesson
Display beautiful images on the @boardname@.
## Topic
Show LEDs
## Quick Links
* [activity](/lessons/beautiful-image/activity)
* [challenges](/lessons/beautiful-image/challenges)
## Prior learning/place of lesson in scheme of work
Learn how to **show LEDs**, to show an image on the @boardname@'s LED screen. We will be learning how to Show LEDs using simple commands such as Show LEDs and pause.
## Documentation
```cards
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
basic.pause(100)
```
## Objectives
* learn how to display an image on the @boardname@'s LED screen
* learn how to pause your code for the specified number of milliseconds

View File

@ -1,28 +0,0 @@
# beautiful image blocks activity
Generate and show a beautiful image.
### ~avatar avatar
Let's learn how to show an image on the LED screen.
### ~
We will use *show LEDs* to draw an image on the LED screen. This function immediately writes on the screen.
```blocks
basic.showLeds(`
# # # # #
# # . # #
# . # . #
# # . # #
# # # # #
`)
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/beautiful-image/challenges)!
### ~

View File

@ -1,45 +0,0 @@
# beautiful image blocks challenges
Coding challenges for the beautiful image tutorial.
## Before we get started
Complete the [beautiful image](/lessons/beautiful-image/activity) activity and your code will look like this:
```blocks
basic.showLeds(`
# # # # #
# # . # #
# . # . #
# # . # #
# # # # #
`)
```
### Challenge 1
Now show an new image that will display on the @boardname@.
```blocks
basic.showLeds(`
# # # # #
# # . # #
# . # . #
# # . # #
# # # # #
`)
basic.showLeds(`
# . # . #
. # # # .
. . # . .
. # # # .
# . # . #
`)
```
* Does your code work as expected?
### Challenge 2
Nice job! Why don't we create a third image that will show after the other two?

View File

@ -1,48 +0,0 @@
# beautiful image blocks challenges
Beautiful Image tutorial.
### ~avatar avatar
### @video td/videos/beautiful-image-0
Rebuild the game!
The blocks have been shuffled! Put them back together so that…
* display images on the screen with show LEDs
```shuffle
basic.showLeds(`
# # # # #
# # . # #
# . # . #
# # . # #
# # # # #
`)
basic.showLeds(`
# . # . #
. # # # .
. . # . .
. # # # .
# . # . #
`)
basic.pause(100)
```
Hints and tips
Cut out these documentation cards to help you!
```cards
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
basic.pause(100)
```

View File

@ -1,36 +0,0 @@
# blink blocks lesson
Learn how to create a blinking LED.
## Topic
Plot
## Quick links
* [activity](/lessons/blink/activity)
* [quiz](/lessons/blink/quiz)
* [quiz answers](/lessons/blink/quiz-answers)
* [challenges](/lessons/blink/challenges)
## Prior learning / place of lesson in scheme of work
Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, unplot and pause.
## Documentation
```cards
led.plot(0, 0)
led.unplot(0, 0)
basic.pause(100)
basic.forever(() => {})
```
## Objectives
* learn how to turn on LED lights on the LED screen
* learn how to turn off LED lights on the LED screen
* learn how to pause program execution for the specified number of milliseconds

View File

@ -1,61 +0,0 @@
# blink blocks activity
Turn an LED on and off with forever
### ~avatar avatar
```sim
basic.forever(() => {
led.plot(2, 2)
basic.pause(500)
led.unplot(2, 2)
basic.pause(500)
})
```
Let's build a blinking light!
### ~
Have you ever tried to blink a flashlight at night? The concept is fairly simply: turn on the light, wait for a little, turn off the light, wait again, and repeat. That's exactly what we need to code to get a blinking LED.
Let's start by adding a line of code that turns on the LED at position 2, 2.
```blocks
led.plot(2, 2)
```
Run your script to make sure it's correct. Then, let's add code to `pause` 500 milliseconds and turn off the LED.
```blocks
led.plot(2, 2)
basic.pause(500)
led.unplot(2,2)
```
We've got the LED blinking once. Let's add another pause and turn on the LED again.
```blocks
led.plot(2, 2)
basic.pause(500)
led.unplot(2, 2)
basic.pause(500)
led.plot(2, 2)
```
The current code works but it only blinks once! We are going to use a `forever` loop and move the code inside it to repeat it forever. We've dropped the second `plot` line since we don't need it in the loop.
```blocks
basic.forever(() => {
led.plot(2, 2)
basic.pause(500)
led.unplot(2, 2)
basic.pause(500)
})
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/blink/challenges)!
### ~

View File

@ -1,79 +0,0 @@
# blink blocks challenges
Coding challenges for the blink tutorial
## Before we get started
Complete the [blink](/lessons/blink/activity) activity and your code will look like this:
```blocks
basic.forever(() => {
led.plot(2, 2)
basic.pause(500)
led.unplot(2, 2)
basic.pause(500)
})
```
### Challenge 1
Let's display a "smiley face" on the screen! We'll start by plotting the eyes.
Add `plot(1,1)` and `plot(3,1)` under `plot(2,2)` ; then add `unplot(1,1)`, `unplot(3,1)` and `unplot(2,2)` after `pause`. When you're ready, don't forget to run your code to try it out!
```blocks
basic.forever(() => {
led.plot(2, 2)
led.plot(1, 1)
led.plot(3, 1)
basic.pause(500)
led.unplot(2, 2)
led.unplot(1, 1)
led.unplot(3, 1)
basic.pause(500)
})
```
### Challenge 2
Let's add the code to plot the mouth by using `plot` and `unplot` to the following coordinates: (1,4), (2,4) and (3,4). When you're ready, don't forget to run your code to try it out!
```blocks
basic.forever(() => {
led.plot(2, 2)
led.plot(1, 1)
led.plot(3, 1)
led.plot(1, 4)
led.plot(2, 4)
led.plot(3, 4)
basic.pause(500)
led.unplot(2, 2)
led.unplot(1, 1)
led.unplot(3, 1)
led.unplot(1, 4)
led.unplot(2, 4)
led.unplot(3, 4)
basic.pause(500)
})
```
### Challenge 3
Let's keep using `plot` to convert the mouth into a smiley face.
```` bitmatrix
0 0 0 0 0
0 1 0 1 0
0 0 1 0 0
1 0 0 0 1
0 1 1 1 0
````
### Challenge 4
Let's make it blink a bit faster. To do so, we need to reduce the amount of time used in ``pause`` to 100 milliseconds.
### Challenge 5
Create your own image by changing the coordinates in `plot` and `unplot`!

View File

@ -1,49 +0,0 @@
# blink blocks quiz answers
Learn how to create a blinking LED script.
This is the answer key for the [blink quiz](/lessons/blink/quiz).
## 1. Describe what `plot` does?
Answers will vary. In general, plot refers to the code that turns on a specific LED. We specify the LED using x, y coordinates.
## 2. Draw which LED is ON after running this code
```blocks
led.plot(2, 2)
```
![](/static/mb/lessons/blink-0.png)
By default, the position of an LED on *Blink Tutorial* is set to the centre of the screen. This code turns on the centre LED
## 3. Draw which LED is ON after running this code
```blocks
led.plot(0, 0)
```
![](/static/mb/lessons/blink-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)
* ``y`` - the y coordinate or vertical position (0)
## 4. Draw which LED is ON after running this code
```blocks
led.plot(4, 4)
```
![](/static/mb/lessons/blink-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 (4)
* ``y`` - the y coordinate or vertical position (4)

View File

@ -1,45 +0,0 @@
# blink blocks quiz
Learn how to create a blinking LED script.
## Name
## Directions
Use this activity document to guide your work in the [blink activity](/lessons/blink/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Describe what `plot` does?
## 2. Draw which LED is ON after running this code
```blocks
led.plot(2, 2)
```
![](/static/mb/empty-microbit.png)
## 3. Draw which LED is ON after running this code
```blocks
led.plot(0, 0)
```
![](/static/mb/empty-microbit.png)
## 4. Draw which LED is ON after running this code
```blocks
led.plot(4, 4)
```
![](/static/mb/empty-microbit.png)

View File

@ -1,62 +0,0 @@
# blocks - if statements
An introduction to conditions for the Block Editor.
## Introduction to conditions
In the introduction to code, we made the @boardname@ automatically shows the message hello world!:
```blocks
basic.showString("hello world!")
```
This statement, or code, will happen as soon as the @boardname@ is activated. This means it is unconditional. We can add a condition to make code function in certain ways:
* A calculator waits for the user in input numbers and a function, before outputting a result
* A game waits for the user to press a button at the right time before outputting their score
* A quiz waits for the user to choose the correct option, and if they are wrong the quiz will tell the user
In programming we use an if statement: if this condition is met, do something. Lets add an if statement to the code we had before; the @boardname@ will wait for the user to press a button before showing the image.
```blocks
basic.forever(() => {
if (input.buttonIsPressed(Button.A)) {
basic.showString("hello world!")
}
})
```
Again, test the code in the simulator. Try clicking **Button A** to display the "hello, world!" message every time the `button is pressed`.
### More 'if' statements
You could now add additional conditions to your 'if statement'. Here are some ideas:
* Change the 'get button' to ask for button B
* Add another 'if' statement within the current one, and make it so both buttons must be pressed to show the message
* Create a mini quiz that asks for one button to be pressed which represents an answer
## Else
What if the user does not press a button? What if the user presses the wrong button? We call this an else, because if the criteria of the if statement are not met then something else is done.
For example, we could make it so our @boardname@ tells us to press the A button. Remove the `button pressed` and `show string` blocks from the `if` block and right click it and select **Delete**. Now click the **If** category and drag out an `else if` block. Plug the `button pressed` and `show string` blocks in the correct places.
We want the message "Press A!" to scroll across the @boardname@, so right-click the `show string` block and select **Duplicate**. Drag this new block into the `else` section and replace the “hello, world!” with "Press A!". Your code should look like this:
```blocks
basic.forever(() => {
if (input.buttonIsPressed(Button.A)) {
basic.showString("hello world!")
} else {
basic.showString("PRESS A")
}
})
```
So, to recap: the `forever` block makes sure our code runs forever. The @boardname@ checks if the user is pressing the left button, if the user is not then the “Press the button!” message will scroll across the LEDs. If the user is pressing the button then the “hello, world!” message will scroll across the screen. Check this in the simulator or attach the @boardname@ to the computer then click **Download** to send the code onto the @boardname@.
## What is a condition?
A condition is criteria that the user must meet for a certain function to be carried out.

View File

@ -1,86 +0,0 @@
# bop it challenges
a game similar to "Simon Says" with the @boardname@.
## Before we get started
Complete the following guided tutorial. Your code should look like this:
```typescript
let action = 0;
function newAction() {}
input.onButtonPressed(Button.A, () => {
if (action == 0) {
game.addScore(1);
newAction();
}
})
input.onLogoDown(() => {
if (action == 1) {
game.addScore(1);
newAction();
}
})
input.onGesture(Gesture.Shake, () => {
if (action == 2) {
game.addScore(1);
newAction();
}
})
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score(), 150);
basic.pause(2000);
newAction();
})
```
### Challenge 1
Now let's add some more types of instructions for the player to follow. Let's add `PRESS PIN 0`.
Change the global variable `action` to `math->random(4)` so that we can add a new **IF** statement that checks if `action=3`. If it does, display instructions to press pin 0.
```typescript
let action = 0;
export function newAction() {
action = Math.random(4)
if (action == 0) {
basic.showString("PUSH A", 150) // ***
}
if (action == 1) {
basic.showString("LOGO DOWN", 150) // ***
}
if (action == 2) {
basic.showString("SHAKE", 150) // ***
}
if (action == 3) {
basic.showString("PRESS PIN 0", 150) // ***
}
}
```
### Challenge 2
Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`.
```typescript
let action = 0;
export function newAction() {
// ...
}
input.onButtonPressed(Button.B, () => {
basic.showNumber(game.score(), 150)
basic.pause(2000)
newAction()
})
input.onPinPressed(TouchPin.P0, () => {
if (action == 3) {
game.addScore(1)
newAction()
}
})
```
### Challenge 3
Add `POINT ME NORTH` to the list of possible commands.

View File

@ -1,77 +0,0 @@
# bop it quiz answers
a game where you have to keep up with the commands.
## Name
## Directions
Use this activity document to guide your work in the [bop it activity](/lessons/bop-it/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
```blocks
let action = Math.random(3)
```
## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
```blocks
let action = Math.random(3)
if (action == 0) {
basic.showString("PUSH A", 150)
}
```
## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
```blocks
input.onButtonPressed(Button.A, () => {
let action = Math.random(3)
if (action == 0) {
game.addScore(1)
}
})
```
## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
```blocks
let action = Math.random(3)
if (action == 1) {
basic.showString("LOGO DOWN", 150)
}
```
## 5. Write the code that increments the score if the @boardname@ logo is tilted down when the global variable called 'action' is equal to 1
```blocks
input.onLogoDown(() => {
let action = Math.random(3)
if (action == 1) {
game.addScore(1)
}
})
```
## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
```blocks
let action = Math.random(3)
if (action == 2) {
basic.showString("SHAKE", 150)
}
```
## 7. Write the code that increments the score if the @boardname@ is shaken when the global variable called 'action' is equal to 2
```blocks
input.onLogoDown(() => {
let action = Math.random(3)
if (action == 1) {
game.addScore(1)
}
})
```

View File

@ -1,38 +0,0 @@
# bop it quiz
a game where you have to keep up with the commands.
## Name
## Directions
Use this activity document to guide your work in the [bop it activity](/lessons/bop-it/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
### 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2
<br/>
### 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0
<br />
### 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1
<br />
### 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1
<br />
### 5. Write the code that increments the score if the @boardname@ logo is tilted down when the global variable called 'action' is equal to 1
<br />
### 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2
<br />
### 7. Write the code that increments the score if the @boardname@ is shaken when the global variable called 'action' is equal to 2

View File

@ -1,51 +0,0 @@
# catch the egg game lesson
A game to catch eggs in a basket.
## Topic
Variables
## Quick Links
* [activity](/lessons/catch-the-egg-game/activity)
* [tutorial](/lessons/catch-the-egg-game/tutorial)
* [quiz](/lessons/catch-the-egg-game/quiz)
* [quiz answers](/lessons/catch-the-egg-game/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to create a catch the egg game game with **plot**, `led->plot` , **unplot**, `led->unplot`, and **acceleration** `input -> acceleration` to turn on and off LED lights on the LED screen. We will be learning how to create a catch the egg game app using global variables, forever loop, local variable, input acceleration, math min, math max, math random, math mod, if (conditionals), game library as well as simple commands, such as led plot, led unplot, and pause.
## Documentation
```cards
let x = 2;
led.unplot(0, 0);
basic.forever(() => {});
x += 1;
led.plot(0, 0);
basic.pause(300);
input.acceleration(Dimension.X);
Math.min(0,0);
Math.max(0,1);
Math.random(5);
game.addScore(1);
game.score();
game.removeLife(1);
```
## Objectives
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
* learn how to repeat code in the background forever
* learn how to turn off a LED light on the LED screen
* learn how to turn on a LED light on the LED screen
* learn how to learn how to conditionally run code depending on whether a condition is true or not
* learn how to learn how to get the acceleration value (g-force), in one of three specified dimensions
* learn how to return the smaller of two numbers
* learn how to return the larger of two numbers
* learn how to return a random number
* learn how to return the modulus
* learn how to show a number of the @boardname@ screen
* learn how to pause your code for the specified number of milliseconds

View File

@ -1,148 +0,0 @@
# catch the egg game challenges
## Before we get started
Your starting code should look like this:
```blocks
let basketX = 2
let eggX = 2
let eggY = 0
basic.forever(() => {
led.unplot(basketX, 4)
led.unplot(eggX, eggY)
eggY = eggY + 1
led.plot(eggX, eggY)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
led.plot(basketX, 4)
if (eggY > 4) {
eggY = -1
eggX = Math.random(5)
}
basic.pause(300)
})
```
### ~avatar avatar impressed
### Challenge 1
Let's use an **IF** statement to detect if the egg and the basket are lined up.
Now that we know when an egg is caught, we can keep track of the score! We need to use the `add score` function built into the game library to add `1` point for every egg that is caught. However, let's not forget to `remove life` if an egg falls off the display before it's caught!
### ~
```blocks
let basketX1 = 2
let eggX1 = 2
let eggY1 = 0
basic.forever(() => {
led.unplot(basketX1, 4)
led.unplot(eggX1, eggY1)
eggY1 = eggY1 + 1
led.plot(eggX1, eggY1)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX1 = 2 + Math.min(2, Math.max(-2, accX / 200))
led.plot(basketX1, 4)
if (eggY1 > 4) {
eggY1 = -1
eggX1 = Math.random(5)
}
if (eggY1 == 4) {
if (basketX1 == eggX1) {
game.addScore(1)
} else {
game.removeLife(1)
}
}
basic.pause(300)
})
```
* Press the `run` button to test out your game.
### ~avatar avatar encourage
### Challenge 2
Catching eggs gets easier with practice so let's make the eggs fall faster every 5 catches. We can do this by tracking how long the egg pauses in each position while falling with a global variable called **falling pause**. Let's create this variable and set it to `300` initially. Don't forget to also create a condition that will be true every 5 catches.
### ~
```blocks
let basketX2 = 2
let eggX2 = 2
let eggY2 = 0
let fallingPause = 300 // ***
basic.forever(() => {
led.unplot(basketX2, 4)
led.unplot(eggX2, eggY2)
eggY2 = eggY2 + 1
led.plot(eggX2, eggY2)
basic.pause(300)
let accX2 = input.acceleration(Dimension.X)
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
led.plot(basketX2, 4)
if (eggY2 > 4) {
eggY2 = -1
eggX2 = Math.random(5)
}
if (eggY2 == 4) {
if (basketX2 == eggX2) {
game.addScore(1)
if (game.score() %5 == 0) {
}
} else {
game.removeLife(1)
}
}
basic.pause(300)
})
```
### ~avatar avatar surprised
### Challenge 3
Let's make the egg fall faster by decreasing the amount of time it pauses in each position by decreasing **falling pause** by `25` every 5 catches. Now, instead of pausing for 300 milliseconds we can pause for the value of **falling pause**.
```blocks
let basketX3 = 2
let eggX3 = 2
let eggY3 = 0
let fallingPause1 = 300
basic.forever(() => {
led.unplot(basketX3, 4)
led.unplot(eggX3, eggY3)
eggY3 = eggY3 + 1
led.plot(eggX3, eggY3)
basic.pause(300)
let accX3 = input.acceleration(Dimension.X)
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
led.plot(basketX3, 4)
if (eggY3 > 4) {
eggY3 = -1
eggX3 = Math.random(5)
}
if (eggY3 == 4) {
if (basketX3 == eggX3) {
game.addScore(1)
if (game.score()% 5 == 0) {
fallingPause1 = fallingPause1 - 25 // ***
}
} else {
game.removeLife(1)
}
}
basic.pause(fallingPause1)
})
```
Fantastic! Your game is now ready to show off.
* Press the `run` button to see your finished game!

View File

@ -1,58 +0,0 @@
# catch the egg game quiz answers
Programming a game of catch the egg using the accelerometer
## Name
## Directions
Use this activity document to guide your work in the [catch the egg activity](/lessons/catch-the-egg-game/activity)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the data type for the global variables 'basket' and 'egg'.
<br/>
'Basket' and 'egg' are stored as **Number**.
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
![](/static/mb/lessons/catch-the-egg-game-0.png)
<br/>
```blocks
let basketX = 2
let eggX = 2
let eggY = 0
led.plot(eggX, eggY)
led.plot(basketX, 4)
```
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
<br/>
```blocks
let basketX = 2
let eggX = 2
let eggY = 0
led.unplot(eggX, eggY)
eggY = eggY + 1
led.plot(eggX, eggY)
```
## 4. . Write the code that resets the egg after it has fallen past the bottom of the @boardname@.
<br/>
```blocks
let eggX = 2
let eggY = 0
if (eggY > 4) {
eggY = -1
eggX = Math.random(5)
}
```

View File

@ -1,30 +0,0 @@
# catch the egg game quiz
Programming a game of catch the egg using the accelerometer.
## Name
## Directions
Use this activity document to guide your work in the [catch the egg challenges](/lessons/catch-the-egg-game/activity)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the data type for the variables 'basket' and 'egg'.
<br/>
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
![](/static/mb/lessons/catch-the-egg-game-0.png)
<br/>
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
<br/>
## 4. Write the code that resets the egg after it has fallen past the bottom of the @boardname@.
<br/>

View File

@ -1,29 +0,0 @@
# catch the egg game tutorial
### Rebuild the game!
The blocks have been shuffled! Put them back together so that...
* an egg LED falls from the top of the screen, row by row.
* a basket LED is on the bottom row and can be moved by using the accelerometer `X` data.
* if the egg LED reaches the last row, reset the egg position to the first row.
```shuffle
let basketX = 2
let eggX = 2
let eggY = 0
basic.forever(() => {
led.unplot(basketX, 4)
led.unplot(eggX, eggY)
eggY = eggY + 1
led.plot(eggX, eggY)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
led.plot(basketX, 4)
if (eggY > 4) {
eggY = -1
eggX = Math.random(5)
}
basic.pause(300)
})
```

View File

@ -1,36 +0,0 @@
# charting lesson
Create a charting app for simulating and measuring the acceleration applied to the @boardname@
## Topic
Acceleration
## Quick Links
* [activity](/lessons/charting/activity)
* [challenge](/lessons/charting/challenge)
* [quiz](/lessons/charting/quiz)
* [answers](/lessons/charting/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn the functions of **on data received**, **send number** and **receive number** and chart `plot bar graph` for `acceleration` in the "x" dimension.
## Documentation
```cards
input.acceleration(Dimension.X)
led.plotBarGraph(0, 1023)
basic.showNumber(0)
radio.onDataPacketReceived(() => {})
radio.sendNumber(0)
```
## Objectives
* learn how to repeat code in the background forever
* learn how to get the acceleration value (g-force), in one of three specified dimensions
* learn how to display a vertical bar graph based on the value and high value.
* learn how to register code to run when a packet is received over radio
* learn how to broadcast a number data packet to other @boardname@s connected via radio
* learn how to read the next radio packet as a number data packet

View File

@ -1,68 +0,0 @@
# Activity
Measure the acceleration on the @boardname@ in the "x" direction.
### ~avatar avatar
Welcome! This activity will teach how to use the @boardname@ to chart the acceleration in the "x" direction. Let's get started!
### ~
Let's measure `acceleration (mg)` in the "x" direction. Get the acceleration value (milli g-force), in one of three specified dimensions.
```blocks
input.acceleration(Dimension.X)
```
### ~
Use the plot bar chart to visualize the acceleration on the LED screen of the @boardname@ in the specified range. You implement plot Bar Graph to display a vertical bar graph based on the "value" and "high" value. Then you must insert acceleration in the X dimension to measure the acceleration.
```blocks
basic.forever(() => {
led.plotBarGraph(input.acceleration(Dimension.X), 0)
})
```
### ~
Notice that moving the @boardname@ in the simulator from left to right (x direction) changes the values beneath the @boardname@ in a range from 1023 to -1023 as measured in milli-gravities. By hovering over the @boardname@ from left to right, you can observe changing values beneath the @boardname@ simulator. Also, the LEDs shown on the Bar Graph fluctates based on the movement of the @boardname@ simulator in the x direction. The line underneath the @boardname@ simulator reflect the acceleration in the x direction.
NOTE: The colors of the charts reflect the color of the @boardname@ simulator. In this instance, the @boardname@ is yellow. So the color of the data line reflects the color of the @boardname@
![](/static/mb/data4.png)
### ~
Vigorously move the @boardname@ in the @boardname@ simulatator by moving the @boardname@ image from side to side. Every time the @boardname@ moves in the x direction in the simulator, you are generating data points that can be reviewed in Excel. The more attempts to move the @boardname@ from side to side, the more data being saved in Excel. After you have vigarously moved the @boardname@ simulator from side to side for a sufficient amount of time, you are ready to graph or chart the accceleration of the @boardname@. We want a printout of our acceleration on Excel that can be graphed in Excel.
### ~
We want to chart the data collected by using a tool in Excel.
The final part of this experiment is opening and reviewing the data in the Excel CSV file. Simply click on the line beneath the simulator. A CSV file will be generated to display the data points collected by moving the @boardname@ in the X direction. Then click or tap on the data Excel file that was downloaded to your local ``Downloads`` Folder.
### ~
First, click or tap on the first two columns (A, B) to include the time of the data being collected; b) the results of acceleration data on the @boardname@
![](/static/mb/data7.png)
Use the Recommended Charts command on the Insert tab to quickly create a chart thats just right for your data.
* Select the data that you want to include in your chart.
* Click Insert > Recommended Charts.
![](/static/mb/lessons/chart1.png)
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data. Pick the **scatter plot**.
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/charting/challenge)
### ~

View File

@ -1,92 +0,0 @@
# Challenge
### ~avatar avatar
Welcome! The activity will teach you how to use the acceleration of the 1st @boardname@ and to visualize the acceleration on the 2nd @boardname@.
Let's get started!
### ~
Let's measure `acceleration (mg)` and then `send number`. `Acceleration` is measured in **milli-gravities**, so a value of -1000 is equivalent to -1g or -9.81m/s^2. We will be able to get the acceleration value (g-force), in the specified "x" dimension. `Send number` will broadcast a number data packet to other @boardname@s connected via radio.
```blocks
radio.sendNumber(input.acceleration(Dimension.X));
```
### ~
We want to display the acceleration forever. In order to do so, we need a `forever` loop. A forever loop will repeat code in the background forever.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X));
});
```
### ~
We want to register code to run when a packet is received over radio. We can implement this code by adding `on data received`.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataPacketReceived(() => {
})
```
### ~
Finally, we want to chart the acceleration. So we must first implement `plot bar graph`. `Plot Bar Graph` will display a vertical bar graph based on the value and high value. In order to transfer the receive the number from the 1st @boardname@, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the @boardname@'s acceleration in the "x" direction.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataPacketReceived(({ receivedNumber }) => {
led.plotBarGraph(receivedNumber, 1023)
})
```
### ~
Notice that moving the @boardname@ the farthest direction in the x direction will be -1023 on the charting beneath the simulator. The second observation will be that the LEDs will be full brightness on the 2nd @boardname@. There is a single LED turned on with the 1st @boardname@. Additionally, the graphs will reflect 0 acceleation for the 1st @boardname@. In this scenario, if you are adjusting the acceleration in the simualator, you are also changing your chart that will be produced.
![](/static/mb/acc.png)
### ~
NOTE: The colors of the charts reflect the color of the @boardname@ simulator. In this instance, the @boardname@s are blue and green. So the colors of the line graphs reflect the colors of the @boardname@
### ~
After running this simulation several seconds by moving the @boardname@ side to side in the x direction, you are ready to graph or chart the accceleration of the @boardname@. We want a printout of our acceleration on Excel. We will graph the fluctuating acceleration of the simulation experiment.
![](/static/mb/acc2.png)
### ~
Finally, you must open the Excel CSV file by clicking on the data.xls file that was downloaded to Downloads Folder.
![](/static/mb/data3.png)
Use the Recommended Charts command on the Insert tab to quickly create a chart thats just right for your data.
* Select the data that you want to include in your chart.
* Click Insert > Recommended Charts.
![](/static/mb/lessons/chart1.png)
* On the Recommended Charts tab, scroll through the list of chart types that Excel recommends for your data. Pick the **scatter plot**.
![](/static/mb/chart_title.png)
* Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right corner of the chart to add chart elements like axis titles or data labels, to customize the look of your chart
![](/static/mb/elements_styles_filters.png)
### ~
Have fun reviewing your simulation and analyze the acceleration by chart the Excel data using Excel.
* Connect the first @boardname@ to your computer using your USB cable and run the charting script on it.
* Connect the second @boardname@ to your computer using your USB cable and run the charting script on it.
* The first person and second person take turns tilting the @boardname@ in the "x" direction while the other player charts the data on the @boardname@!
* Review and analyze the actual @boardname@ device acceleration data on Excel
* Display acceleration with y or z using plot bar graph by changing acceleration from "x" to "y" or "z"
```package
radio
```

View File

@ -1,33 +0,0 @@
# charting quiz answers
Measure the acceleration on the @boardname@ in the "x" direction.
## Name
## Directions
Use this activity document to guide your work in the [charting activity](/lessons/charting)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Why are you creating a 'forever' loop?
<br/>
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
## 2. Write the line of code to measure the acceleration with respect to the "x" axis and display this value in a bar graph.
<br/>
```blocks
led.plotBarGraph(input.acceleration(Dimension.X), 0)
```
## 3. After vigarously moving the @boardname@ from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.
<br/>
![](/static/mb/line_chart.png)

View File

@ -1,23 +0,0 @@
# charting quiz
Measure the acceleration on the @boardname@ in the "x" direction.
## Name
## Directions
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/activity)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Why are you creating a 'forever' loop?
<br/>
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
<br/>
## 3. After vigarously moving the @boardname@ from side to side along the "x" axis for a sufficient amount of time,insert the Excel graph for displaying a line chart used to display trends over time.

View File

@ -1,23 +0,0 @@
# classic beatbox
display beautiful images on the @boardname@.
## Topic
Music
## Quick Links
* [activity](/lessons/classic-beatbox/activity)
* [challenges](/lessons/classic-beatbox/challenges)
## Prior learning/place of lesson in scheme of work
Learn how to make a beatbox music player using pins P1 and P2. We will be learning how to code musical notes using a local variable, for loop, on pin pressed as well as simple commands such as play and notes.
## Objectives
* learn how to code music on the @boardname@

View File

@ -1,54 +0,0 @@
# beatbox activity
Control images with variables.
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
Let's start by adding a variable where you can store data. Then rename the variable to "sound". Then set the value of the variable to the note block `A` from the Music drawer. Modify your code so that your code looks like this.
```blocks
let sound = music.noteFrequency(Note.A);
```
We want to play music on pin pressed in order to register an event handler that will execute whenever when you run a script and click pin 1 on the simulator. We must start by opening the Input drawer and adding `on pin pressed` P1. Modify your code so that your code looks like this.
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
})
```
We want to code the notes that will be played `on pin pressed`. We click on the Input drawer then insert a `for loop` that will increment by *i*. Click on the Variables drawer. Add `set item` block. Rename the variable block to "sound." Then add a Maths block to increase the variable sound from the note frequency of block `A` to `A` plus 25.Modify your code so that your code looks like this
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 4; i++) {
sound = sound + 25
}
})
```
Include a play block with the variable called "sound" and insert a music note block `1/16`. Modify your code so that your code looks like this
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 5; i++) {
sound = sound + 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
```
* click *run* to see if the code works as expected.
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/classic-beatbox/challenges)!
### ~

View File

@ -1,48 +0,0 @@
# beatbox challenges
Create sounds with variables.
## Before we get started
Complete the [beatbox](/lessons/classic-beatbox/activity) activity and your code will look like this:
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 4; i++) {
sound = sound + 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
```
### Challenge 1
Let's include a second sound `on pin pressed` *P2*. To do this, you need to add the same blocks as the banana keyboard activity. However, you must change alter `on pin pressed` from P1 to P2. Additionally, you must *decrease* the frequency of the variable "sound" by 25. Modify your code so that your code looks like this
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 5; i++) {
sound = sound + 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
input.onPinPressed(TouchPin.P2, () => {
for (let i = 0; i < 5; i++) {
sound = sound - 25
music.playTone(music.noteFrequency(sound), music.beat(BeatFraction.Sixteenth));
}
})
```
* click *run* to see if the code works as expected.
### Challenge 2
Finally, we want images to be displayed with sounds `on pin pressed`. Add `show LEDs` blocks under `on pin pressed` P1 and P2.

View File

@ -1,45 +0,0 @@
# compass lesson
create a die on the @boardname@.
## Topic
If (Conditionals)
## Quick Links
* [activity](/lessons/compass/activity)
* [challenges](/lessons/compass/challenges)
* [quiz](/lessons/compass/quiz)
* [quiz answers](/lessons/compass/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a compass with If statements, Forever, Variables, Assignment Operator, Comparison Operator, Show String, and Show LEDs
## Documentation
```cards
input.compassHeading()
basic.forever(() => {})
let x = 0
if (true) {}
basic.showString("Hello!")
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
```
## Objectives
* learn how to run code when the @boardname@ is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
* learn how to create a local variable as a place where you can store and retrieve data
* learn how the assignment operator is used to declare a new local variable
* learn how to declare a new local variable or update the value of a variable
* learn how to return a random number
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to show an image on the LED screen

View File

@ -1,98 +0,0 @@
# compass activity
Display the direction that the @boardname@ is facing using the compass
### ~avatar avatar
Welcome! This guided tutorial will show you how to program a script that displays the direction the @boardname@ is pointing. Let's get started!
### ~
Create a loop that will continuously update the reading of the compass.
```blocks
basic.forever(() => {
})
```
Store the reading of the @boardname@ in a variable called `degrees`.
```blocks
basic.forever(() => {
let degrees = input.compassHeading()
})
```
If `degrees` is less than `45`, then the compass heading is mostly pointing toward North. Display `N` on the @boardname@.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
});
```
If `degrees` is less than 135, the @boardname@ is mostly pointing East. Display `E` on the @boardname@.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
});
```
If `degrees` is less than 225, the @boardname@ is mostly pointing South. Display `S` on the @boardname@.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
else if (degrees < 225) {
basic.showString("S");
}
});
```
If none of these conditions returned true, then the @boardname@ must be pointing West. Display `W` on the @boardname@.
```blocks
basic.forever(() => {
let degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
else if (degrees < 225) {
basic.showString("S");
}
else {
basic.showString("W");
}
});
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/compass/challenges)!
### ~

View File

@ -1,88 +0,0 @@
# compass challenges
Display the direction that the @boardname@ is facing using the compass
## Before we get started
Complete the following [guided tutorial](/lessons/compass/activity), your code should look like this:
```blocks
let degrees = 0;
basic.forever(() => {
degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
else if (degrees < 225) {
basic.showString("S");
}
else {
basic.showString("W");
}
});
```
### Challenge 1
Instead of displaying `N` when the @boardname@ is pointing North, display a star to indicate the north star.
```blocks
let degrees = 0;
basic.forever(() => {
degrees = input.compassHeading();
if (degrees < 45) {
basic.showLeds(`
# . # . #
. # # # .
# # # # #
. # # # .
# . # . #`);
}
else if (degrees < 135) {
basic.showString("E");
}
else if (degrees < 225) {
basic.showString("S");
}
else {
basic.showString("W");
}
});
```
* Run your code to see if it works as expected
### Challenge 2
Instead of displaying just `N`, `W`, `S`, or `E`, display the full word.
```blocks
let degrees = 0;
basic.forever(() => {
degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("NORTH");
}
else if (degrees < 135) {
basic.showString("EAST");
}
else if (degrees < 225) {
basic.showString("SOUTH");
}
else {
basic.showString("WEST");
}
});
```
* Run your code to see if it works as expected
### Challenge 3
Display your own unique message for each direction.

View File

@ -1,54 +0,0 @@
# compass quiz answers
Create an actual compass to show your direction: North, South, East, or West
## Name
## Directions
Use this activity document to guide your work in the [compass tutorial](/lessons/compass/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What is the purpose of the 'compass heading' block?
Gets the compass heading of the @boardname@ in degrees
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
```blocks
let degrees = input.compassHeading()
```
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the @boardname@
```blocks
let degrees = input.compassHeading()
if (degrees < 45) {
basic.showString("N", 150)
}
```
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the @boardname@
```blocks
let degrees = input.compassHeading()
if (degrees < 135) {
basic.showString("E", 150)
}
```
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the @boardname@
```blocks
let degrees = input.compassHeading()
if (degrees < 225) {
basic.showString("S", 150)
}
```

View File

@ -1,26 +0,0 @@
# compass quiz
Create an actual compass to show your direction: North, South, East, or West
## Name
## Directions
Use this activity document to guide your work in the [compass activity](/lessons/compass/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What is the purpose of the 'compass heading' block?
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the @boardname@
## 4. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the @boardname@
## 5. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the @boardname@

View File

@ -1,48 +0,0 @@
# counter lesson
Learn how to create a counter with with on button pressed.
## Topic
Variables
## Quick Links
* [activity](/lessons/counter/activity)
* [challenges](/lessons/counter/challenges)
* [quiz](/lessons/counter/quiz)
* [quiz answers](/lessons/counter/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using a variable as well as simple commands, such as on button pressed, and show number.
## Documentation
```cards
input.compassHeading()
basic.forever(() => {})
let x = 0
if (true) {}
basic.showString("Hello!")
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
```
* **variable**: [read more...](/blocks/variables)
* **arithmetic operators**: [read more...](/reference/types/number)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **show number** : [read more...](/reference/basic/show-number)
## Objectives
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across all functions, and in nested code blocks
* learn how arithmetic operators operate on numbers and return a number
* learn how to run code when an input button is pressed
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)

View File

@ -1,43 +0,0 @@
# counter activity
Display a number with a variable.
### ~avatar avatar
Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. Let's get started!
### ~
Let's start by creating a **local variable** `count` to keep track of the current count.
```blocks
let count = 0
```
The code under ``on button pressed("A")`` will run each time the user presses A. Let's add a line of code that increments `count` by `1`.
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
})
```
Since the count has changed, it's time to refresh the screen display. Let's add a line of code to display the count on screen.
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/counter/challenges)
### ~

View File

@ -1,37 +0,0 @@
# counter challenges
Coding challenges for the counter.
## Before we get started
Complete the following [guided tutorial](/lessons/counter/activity) At the end of the tutorial, click **keep editing**. Your code should look like this:
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
```
### Challenge 1
Let's add the code to `count` when `B` is pressed. Add an event handler with `on button pressed(B)` then add the code to `count`.
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
input.onButtonPressed(Button.B, () => {
count = count - 1
basic.showNumber(count)
})
```
### Challenge 3
Now let's try to reset the counter when the @boardname@ is shaken. You will need to register an event handler with `on shake`.

View File

@ -1,54 +0,0 @@
# counter quiz answers
Learn how to create a counter with the @boardname@ button.
This is the answer key for the [counter quiz](/lessons/counter/quiz).
## 1. What is a variable?
Answers may vary but a variable is a place where you can store and retrieve data
## 2. Draw the stored value for the variable called count
```blocks
let count = 0
```
![](/static/mb/lessons/counter-0.png)
We create a **variable**, `count` to keep track of the current count. The number 0 is stored into memory of the variable.
<br/>
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
```
![](/static/mb/lessons/counter-1.png)
We are only pressing on button pressed once. So the number to display on the @boardname@ is also one.
<br/>
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
```blocks
let count = 0
input.onButtonPressed(Button.A, () => {
count = + 1
basic.showNumber(count)
})
```
![](/static/mb/lessons/counter-2.png)
We included the code ``on button pressed("A")`` that runs each time the user presses A. The code increments `count` by `1`. We increase `count` by 1 whenever the user presses the button. So the third time the A button is pressed on the @boardname@, the number 3 is displayed
<br/>

View File

@ -1,54 +0,0 @@
# counter quiz
Learn how to create a counter with the @boardname@ button.
## Name
## Directions
Use this activity document to guide your work in the [counter tutorial](/lessons/counter/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. What is a variable?
<br/>
## 2. Draw the stored value for the variable called count
```blocks
let count = 0
```
![](/static/mb/empty-microbit.png)
<br/>
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
```blocks
let counts = 0
input.onButtonPressed(Button.A, () => {
counts = counts + 1
basic.showNumber(counts, 150)
})
```
![](/static/mb/empty-microbit.png)
<br/>
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
```blocks
let counting= 0
input.onButtonPressed(Button.A, () => {
counting = counting + 1
basic.showNumber(counting, 100)
})
```
![](/static/mb/empty-microbit.png)
<br/>

View File

@ -1,44 +0,0 @@
# dice roll lesson
Create a dice on the @boardname@.
## Topic
If (Conditionals)
## Quick Links
* [activity](/lessons/dice-roll/activity)
* [challenges](/lessons/dice-roll/challenges)
* [quiz](/lessons/dice-roll/quiz)
* [quiz answers](/lessons/dice-roll/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a die with If statements, On Shake, Variables, Assignment Operator, Pick Random and Show LEDs
## Documentation
```cards
input.onGesture(Gesture.Shake, () => {})
let x = 0
Math.random(3)
if (true) {}
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
```
## Objectives
* learn how to run code when the @boardname@ is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
* learn how to create a local variable as a place where you can store and retrieve data
* learn how the assignment operator is used to declare a new local variable
* learn how to declare a new local variable or update the value of a variable
* learn how to return a random number
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to show an image on the LED screen

View File

@ -1,169 +0,0 @@
# dice roll activity
Create a dice on the @boardname@
### ~avatar avatar
Welcome! This tutorial will help you create a dice. Let's get started!
### ~
Let's create a condition for when the @boardname@ is shaken.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
We need to show a random value from 1 to 6 on our dice. So let's make a local variable called **roll**.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6)
})
```
We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `show LEDs` to display the side of a dice that shows 6.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
});
```
Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the dice.
```blocks
input.onGesture(Gesture.Shake, ()=> {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
});
```
Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the dice.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
});
```
Let's also repeat these steps to show the 3, 2, and 1 on the dice. We are almost done with our dice!
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/dice-roll/challenges)!
### ~

View File

@ -1,183 +0,0 @@
# dice roll challenges
Create a dice on the @boardname@.
## Before we get started
Complete the following [guided tutorial](/lessons/dice-roll/activity), your code should look like this:
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(6);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### Challenge 1
Modify the line of code with `pick random` so that only number 1-4 can appear on the dice.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(4);
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### Challenge 2
Let's make a trick dice! Modify the line of code with `pick random` so that only numbers 3-6 can appear on the dice. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the @boardname@.
```blocks
input.onGesture(Gesture.Shake, () => {
let roll = Math.random(4) + 2;
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .`);
}
else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .`);
}
else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .`);
}
else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #`);
}
else if (roll == 1) {
basic.showLeds(`
. . . . .
. # . . .
. . . . .
. . . # .
. . . . .`);
}
else {
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .`);
}
});
```
### Challenge 3
Add a couple more conditions so that the @boardname@ randomly chooses a number between 1 and 8.

View File

@ -1,121 +0,0 @@
# dice roll quiz answers
Create a dice when the @boardname@ is shaken
These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
<br/>
```blocks
let roll = Math.random(6)
```
## 2. If the variable "roll" equals 5, write the code that will plot the image below
![](/static/mb/lessons/die-roll-0.png)
<br/>
```blocks
let roll = Math.random(6)
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .
`)
}
```
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-1.png)
<br />
```blocks
let roll = Math.random(6)
if (roll == 5) {
basic.showLeds(`
. # . # .
. . . . .
. # . # .
. . . . .
. # . # .
`)
} else if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .
`)
}
```
Note: students are only required to write the bottom half of this answer, starting with "else if".
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-2.png)
<br />
```blocks
let roll = Math.random(6)
if (roll == 4) {
basic.showLeds(`
. . . . .
. # . # .
. . # . .
. # . # .
. . . . .
`)
} else if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .
`)
}
```
Note: students are only required to write the bottom half of this answer, starting with "else if".
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
![](/static/mb/lessons/die-roll-3.png)
<br />
```blocks
let roll = Math.random(6)
if (roll == 3) {
basic.showLeds(`
. . . . .
. # . # .
. . . . .
. # . # .
. . . . .
`)
} else if (roll == 2) {
basic.showLeds(`
# . . . .
. . . . .
. . # . .
. . . . .
. . . . #
`)
}
```
Note: students are only required to write the bottom half of this answer, starting with "else if".

View File

@ -1,42 +0,0 @@
# dice roll quiz
Create a dice when the @boardname@ is shaken
## Name
## Directions
Use this activity document to guide your work in the [dice roll tutorial](/lessons/dice-roll/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
<br/>
## 2. If the variable "roll" equals 5, write the code that will plot the image below
![](/static/mb/lessons/die-roll-0.png)
<br/>
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-1.png)
<br />
<br/>
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
![](/static/mb/lessons/die-roll-2.png)
<br />
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
![](/static/mb/lessons/die-roll-3.png)
<br />

View File

@ -1,37 +0,0 @@
# digi yoyo lesson
Create a counter with a while loop.
## Topic
While Loop
## Quick Links
* [activity](/lessons/digi-yoyo/activity)
* [challenges](/lessons/digi-yoyo/challenges)
* [quiz](/lessons/digi-yoyo/quiz)
* [quiz answers](/lessons/digi-yoyo/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to creating a **while loop**, `while condition do` to repeat code while a condition is true. We will be learning how to create a digi yoyo app using a while loop, a variable, as well as basic commands, such as pause and show number.
## Documentation
```cards
let x = 0
basic.showNumber(0)
while (true) {}
basic.pause(20)
```
## Objectives
* learn how to create a local variables to store data and use it in your code
* learn how to set or change the value of a local variable
* learn how to repeat code while a condition is true
* learn how a relational comparison (<) of numbers will yield a Boolean
* learn how to pause your code for the specified number of milliseconds
* learn how to show a number on the LED screen

View File

@ -1,58 +0,0 @@
# digi yoyo activity
Create a counter with a while loop.
### ~avatar avatar
Welcome! This tutorial will teach how to create a counter with a while loop. Let's get started!
### ~
Create a variable that acts as a counter and set it to 0.
```blocks
let count = 0
```
Add a while loop that will loop over and over until the variable `count` equals 10.
```blocks
let count = 0
while (count < 10) {
}
```
Let's add a pause. Then show the value of the the count.
```blocks
let count = 0;
while (count < 10) {
basic.pause(100);
basic.showNumber(count)
}
```
Increase the value of count by one.
```blocks
let count = 0
while (count < 10) {
basic.pause(100)
basic.showNumber(count)
count = count + (count - 1)
}
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/digi-yoyo/challenges)!
### ~

View File

@ -1,73 +0,0 @@
# digi yoyo challenges
Coding challenges for the digi yoyo.
## Before we get started
Complete the following [guided tutorial](/lessons/digi-yoyo/activity), your code should look like this:
```blocks
let count = 0;
while (count < 10) {
basic.pause(100);
basic.showNumber(count);
count = count + 1;
basic.pause(20);
}
```
### Challenge 1
How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0.
```blocks
let count = 0;
while (count < 10) {
basic.pause(100);
basic.showNumber(count);
count = count + 1;
basic.pause(20);
}
while (count > 0) {
}
```
### Challenge 2
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!
```blocks
let count = 0;
while (count < 10) {
basic.pause(100);
basic.showNumber(count);
count = count + 1;
}
while (count > 0) {
basic.pause(100);
basic.showNumber(count);
}
```
* Run the code to see if it works as expected.
### Challenge 3
Now, we need `count` to decrease by one after the @boardname@ has displayed the value of `count`.
We can do this by adding this line:
```blocks
let count = 0;
count = count + (count - 1);
```

View File

@ -1,35 +0,0 @@
# digi yoyo quiz answers
Answers for digi yoyo quiz.
This is the answer key for the [digi yoyo quiz](/lessons/digi-yoyo/quiz).
## 1. Describe what a "while loop" does?
<br/>
A loop that repeats code while a condition is true.
## 2. Write the code that will create a **variable** called `count` and set the variable to 0.
![](/static/mb/lessons/counter-0.png)
<br/>
```blocks
let count = 0
```
## 3. Create a `while loop` that will loop until the **variable** `count` equals 4.
![](/static/mb/lessons/digi-yoyo-0.png)
<br/>
```blocks
let count = 0
while (count < 5) {
count = count + 1
}
```

View File

@ -1,28 +0,0 @@
# digi yoyo quiz
Create a counter with a while loop
## Name
## Directions
Use this activity document to guide your work in the [digi yoyo tutorial](/lessons/digi-yoyo/activity)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Describe what a "while loop" does?
<br/>
## 2. Write the code that will create a variable called count and set the variable to 0.
![](/static/mb/lessons/counter-0.png)
<br/>
## 3. Write the code for a while loop that will loop until the variable count equals 4.
![](/static/mb/lessons/digi-yoyo-0.png)
<br/>

View File

@ -1,39 +0,0 @@
# flashing heart blocks lesson
Learn how to create LED images with a global variable.
## Topic
Pause
## Quick links
* [activity](/lessons/flashing-heart/activity)
* [quiz](/lessons/flashing-heart/quiz)
* [quiz answers](/lessons/flashing-heart/quiz-answers)
* [challenges](/lessons/flashing-heart/challenges)
## Prior learning/place of lesson in scheme of work
Learn how to `show LEDs` by showing an image on the LED screen. We will be learning how to create a blinking app using a forever loop as well as simple commands, such as show LEDs, pause, and clear screen.
## Documentation
```cards
basic.forever(() => {})
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
basic.pause(100)
basic.clearScreen()
```
## Objectives
* learn how to repeat code in the background forever
* learn how to show LEDs on the LED screen
* learn how to pause your code for the specified number of milliseconds
* learn how to turn off all the LED lights on the LED screen

View File

@ -1,71 +0,0 @@
# flashing heart blocks activity
Control images with a variable.
### ~avatar avatar
In this activity, you will learn how to blink an image on the LED screen.
### ~
Let's start by adding code that plots a heart image on the screen using `show LEDs`. Once you are done coding, don't forget to run your code in the simulator or the @boardname@.
```blocks
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .`);
```
We want to leave the image on the screen for 0.5 seconds (500 milliseconds), then clear the screen. We can use `pause` to wait and `clear screen` to turn off the LEDs.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .
`)
basic.pause(500)
basic.clearScreen()
})
```
Finally, we can surround this code with a `forever` loop to repeat it and add a pause after `clear screen` to keep the screen off for a little while. Modify your code so that your code looks like this.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .
`)
basic.pause(500)
basic.clearScreen()
basic.pause(500)
})
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/flashing-heart/challenges)!
### ~

View File

@ -1,96 +0,0 @@
# flashing heart blocks challenges
Coding challenges for the flashing heart tutorial.
## Before we get started
Complete the [flashing heart](/lessons/flashing-heart/activity) activity and your code will look like this:
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .
`)
basic.pause(500)
basic.clearScreen()
basic.pause(500)
})
```
### Challenge 1
Let's plot a different image. Let's display a broken heart!
To do this, you need to add a block between the last line and the end loop. Add a `show LEDs` block and then add a `pause` of 500 milliseconds.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# # # # #
# # # # #
. # # # .
. . # . .
`)
basic.pause(500)
basic.clearScreen()
basic.pause(500)
basic.showLeds(`
. # . # .
# . # # #
# . . # #
. # # # .
. . # . .
`)
basic.pause(500)
})
```
* click *run main* to see if the code works as expected.
### Challenge 2
Now let's alternate flashing the heart and the broken heart. To do this, we need to add a `clear screen` block and then add a `pause` block of 500 milliseconds under the new code we added in Challenge 1.
```blocks
basic.forever(() => {
basic.showLeds(`
. # . # .
# . # # #
# . . # #
. # # # .
. . # . .
`)
basic.pause(500)
basic.clearScreen()
basic.pause(500)
basic.showLeds(`
. # . # .
# . # # #
# . . # #
. # # # .
. . # . .
`)
basic.pause(500)
basic.clearScreen()
basic.pause(500)
})
```
* click *run main* to see if the code works as expected.
### Challenge 3
You now have a heart and broken heart flashing! Now plot a new image to alternate in with the heart and broken heart.

View File

@ -1,24 +0,0 @@
# flashing heart blocks quiz answers
Learn how to create an image with a variable.
This is the answer key for the [flashing heart quiz](/lessons/flashing-heart/quiz).
## 1. Describe what pause does
Pause program execution for the specified number of milliseconds.
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
```blocks
basic.pause(1000)
```
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
```blocks
basic.pause(1500)
```

View File

@ -1,25 +0,0 @@
# flashing heart blocks quiz
Learn how to create a blinking image with a variable.
## Name
## Directions
Use this activity document to guide your work in the [flashing heart activity](/lessons/flashing-heart/activity).
Answer the questions while completing the activity. Pay attention to the dialogues!
## 1. Describe what `pause` does?
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)

View File

@ -1,30 +0,0 @@
# game counter lesson
Learn how to create a counter with with on button pressed.
## Topic
Game Library
## Quick Links
* [activity](/lessons/game-counter/activity)
* [challenges](/lessons/game-counter/challenges)
## Prior learning/place of lesson in scheme of work
Learn how to create game blocks to keep track of the current score. We will be learning how to create a game using the blocks called `add points to score`, `score` as well as simple commands such as on button pressed and show number.
## Documentation
```cards
game.addScore(1)
input.onButtonPressed(Button.A, () => {})
basic.showNumber(0)
```
## Objectives
* learn how arithmetic operators operate on numbers and return a number
* learn how to run code when an input button is pressed
* learn how to show a score on the LED screen

View File

@ -1,32 +0,0 @@
# game counter activity
Have you ever tried to create a game counter? The concept is fairly simply: increase the game `score` with `on button pressed` .
Let's start by adding `on button (A) pressed` will run each time the user presses A. Let's add a line of code that increments `score` by `1`.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1);
});
```
Let's add a `add points to score` block to keep track of the current count. Since the count will change with the `add points to score` blocks, add a game block `score` to display the count on screen.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1);
basic.showNumber(game.score())
});
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/game-counter/challenges)!
### ~

View File

@ -1,37 +0,0 @@
# game counter challenges
Coding challenges for the game counter.
## Before we get started
Complete the following [activity](/lessons/game-counter/activity) . Your code should look like this:
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1);
basic.showNumber(game.score())
});
```
### Challenge 1
Let's add the code to `score` when `B` is pressed. Add an event handler with `on button (B) pressed` then add the code to `score`.
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1);
basic.showNumber(game.score())
});
input.onButtonPressed(Button.B, () => {
game.addScore(-1);
basic.showNumber(game.score())
});
```
### Challenge 3
Now let's try to reset the counter when the @boardname@ is shaken. You will need to register an event handler with `on shake`.

View File

@ -1,31 +0,0 @@
# game of chance blocks lesson
create an answering machine on the @boardname@
## Topic
Game Library
## Quick Links
* [activity](/lessons/game-of-chance/activity)
* [challenges](/lessons/game-of-chance/challenges)
## Prior learning / place of lesson in scheme of work
Learn how to creating a message with a **game over** to write your message. We will be learning how to create a message using show string and on button pressed.
## Documentation
```cards
game.gameOver()
basic.showString("Hello!")
input.onButtonPressed(Button.A, () => {})
```
## Objectives
* learn how to use the game library
* learn how to show a string on the LED screen one character at a time
* learn how to use to register an event handler that will execute whenever an input button is pressed

View File

@ -1,16 +0,0 @@
# game of chance blocks activity
Learn to create an answering machine on the @boardname@
We will use `show string` to show text on the LED screen. *String* is a common name for *text* in programming languages. The function `show string` scrolls the text column by column at a *150* milliseconds interval. If you want to speed up or down the scrolling, simply change the *150*.
```blocks
basic.showString("SELECT A BUTTON")
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/lessons/game-of-chance/challenges)!
### ~

View File

@ -1,48 +0,0 @@
# game of chance challenges
Coding challenges for the answering machine tutorial.
## Before we get started
Complete the [game of chance](/lessons/game-of-chance/activity) activity and your code will look like this:
```blocks
basic.showString("SELECT A BUTTON")
```
### Challenge 1
Now we need to to play the game of chance by responding to the message. We want to respond `YOU WIN` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YOU WIN`.
```blocks
basic.showString("SELECT A BUTTON")
input.onButtonPressed(Button.A, () => {
basic.showString("YOU WIN")
})
```
* `Run` the code to see if it works as expected.
### Challenge 2
What if @boardname@'s answer to the question is GAME OVER? Let's have `GAME OVER` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the `GAME OVER`.
```blocks
basic.showString("SELECT A BUTTON")
input.onButtonPressed(Button.A, () => {
basic.showString("YOU WIN")
})
input.onButtonPressed(Button.B, () => {
game.gameOver()
})
```
* `Run` the code to see if it works as expected.
### Challenge 3
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `TRY AGAIN`.

View File

@ -1,46 +0,0 @@
# glowing pendulum blocks lesson
construct a pendulum that glows using acceleration.
## Topic
Acceleration
## Quick Links
* [activity](/lessons/glowing-pendulum/activity)
* [tutorial](/lessons/glowing-pendulum/tutorial)
* [challenges](/lessons/glowing-pendulum/challenges)
* [quiz](/lessons/glowing-pendulum/quiz)
* [quiz answers](/lessons/glowing-pendulum/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to get the acceleration **acceleration**, `acceleration` value (g-force), in one of three specified dimensions. We will be learning how to get the acceleration using forever loop, a local variable, acceleration, the math library, as well as simple commands, such as led set brightness and led plot all.
## Documentation
```cards
basic.forever(() => {})
let x = 0
input.acceleration(Dimension.X)
Math.abs(0)
led.setBrightness(255)
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
```
## Objectives
* learn how to repeat code in the background forever
* learn how create a local variable to store data, so that you can use it in your code
* learn how to get the acceleration value (g-force), in one of three specified dimensions
* learn how to return the absolute value
* learn how to sets the brightness of the LED screen
* learn how to turn on all the LED lights on the LED screen

View File

@ -1,108 +0,0 @@
# glowing pendulum block activity
Construct a pendulum that glows using acceleration.
Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
Turn on all the LEDs.
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
```
Create a **forever** loop that will constantly display the appropriate brightness on the LED display.
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
})
```
Now let's measure the acceleration on the `y` axis and store that value in a variable. The `acceleration(y)` function will provide the value.
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
});
```
Since the @boardname@ will be swinging back and forth, the acceleration will only be positive half of the time. Thus, to always get a positive value, we want to take the absolute value of the acceleration.
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration)
});
```
The function `acceleration(y)` returns a number between 0 and 1024. We want to use this value for the brightness of the @boardname@, but the `set brightness()` only accepts a value between 0 and 256. Thus, we need to divide the acceleration by 4 to ensure we will be in the appropriate range.
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
});
```
Now let's use our acceleration value to set the brightness on the @boardname@.
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
});
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/lessons/glowing-pendulum/challenges)!
### ~

View File

@ -1,36 +0,0 @@
# glowing pendulum blocks challenges
Coding challenges for the glowing pendulum tutorial.
## Before we get started
Complete the following [glowing pendulum activity](/lessons/glowing-pendulum/activity) and your code should look like this:
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
});
```
### Challenge 1
![](/static/mb/lessons/glowing-pendulum-0.jpg)
Hold the @boardname@ in your hand in a dark room. Move the @boardname@ like a pendulum and produce a slow image that captures the pattern of the @boardname@ LEDs.
### Challenge 2
Replace "y" in `acceleration(y)` with "x" or "z". Changing the axis will cause the @boardname@ to measure the force in a different direction. What differences in the resulting pattern does this replacement make?

View File

@ -1,46 +0,0 @@
# glowing pendulum quiz answers
construct a pendulum that glows using acceleration.
## Name
## Directions
Use this activity document to guide your work in the [glowing pendulum activity](/lessons/glowing-pendulum/activity)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Why are you creating a 'forever' loop?
<br/>
We are creating a forever loop to constantly display the appropriate brightness on the LED display.
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
<br/>
```blocks
let acceleration = input.acceleration("y")
```
## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'.
<br/>
```blocks
let acceleration = input.acceleration(Dimension.X)
let accelerationAbsolute = Math.abs(acceleration)
```
## 4. Write the code to use the acceleration value from question 3 to set the brightness on the @boardname@.
<br/>
```blocks
let accelerationX = input.acceleration(Dimension.X)
let accelerationAbsolute = Math.abs(accelerationX)
let accelerationDivided = accelerationX / 4
led.setBrightness(accelerationX)
```

View File

@ -1,27 +0,0 @@
# glowing pendulum quiz
construct a pendulum that glows using acceleration.
## Name
## Directions
Use this activity document to guide your work in the [glowing pendulum tutorial](/lessons/glowing-pendulum/activity)
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Why are you creating a 'forever' loop?
<br/>
## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'.
<br/>
## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'.
<br/>
## 4. Write the code to include acceleration value question 3 to set the brightness on the @boardname@.

View File

@ -1,29 +0,0 @@
# glowing pendulum block tutorial
The glowing pendulum changes the screen brightness based on the acceleration measured on the @boardname@.
### Rebuild the game!
The blocks have been shuffled! Put them back together so that...
* all LEDs are turned on
* the @boardname@ repeats code **forever** that
* reads the acceleration along the ``y`` axis,
* calculate the absolute value of the acceleration
* scales down the acceleration value by a factor of `4`
* uses the scaled value to set the screen **brightness**
```blocks
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
acceleration = Math.abs(acceleration);
acceleration = acceleration / 4;
led.setBrightness(acceleration)
});
```

View File

@ -1,82 +0,0 @@
# blocks - rendering graphics
An introduction to graphics for the Block Editor.
## Before we get started
Ensure you have completed the 'Hello, world!' and Loop tutorials and tested them on a simulator or on @boardname@.
```blocks
basic.showString("HI!");
```
The @boardname@ has a grid of 25 LEDs, so we can use these to display images.
Weve already experimented with the `show string` block that displays a string (some text) that we program it to. However we can use more blocks from the **Images** drawer to render or display images in different ways.
### Pixel Art
We can draw little images from the LEDs by ticking boxes. Drag a `show image` block from the **Images** drawer and connect in a `create image` block. You can customize this image by clicking boxes to tick whether the LED will turn on or off. For example, if we were creating a music player we may want to the show the `play` block:
![](/static/mb/blocks/lessons/graphics-0.png)
### Plotting points
We can also code our bug to plot a point by giving an x (horizontal) and y (vertical) coordinates, from 0 to 4. Click the **LED** drawer and drag a `plot` block. Try changing the coordinates and see the effect this has on the @boardname@.
We can also unplot a point (turn the LED off again) using the `unplot` block. So we could create a flashing LED program, using the `pause` block to create a delay.
```blocks
basic.forever(() => {
led.plot(2,2)
basic.pause(100)
led.unplot(2,2)
basic.pause(100)
})
```
We can also use the `basic.clearScreen` block to turn off all LEDs.
## Tip
The pause block is in milliseconds, so setting it to 1000 will have a pause of a single second.
### Devising algorithms for shapes
An algorithm is a set of steps to follow to solve a problem. We can begin to draw shapes on the @boardname@ using an algorithm.
For example, we could draw a straight line with this code:
```blocks
for(let i = 0; i <=4; i++) {
led.plot(i, 0);
basic.pause(200)
}
```
Our algorithm is: increase **i** by 1 **from 0** to **4**, and **plot** the point **x=i**, **y=0**. The pause block allows this line to be animated (drawn frame by frame).
Try devising an algorithm for a diagonal line using the code above and the variable **i**.
```sim
basic.forever(() => {
for(let i = 0; i <=4; i++) {
led.plot(i, i);
basic.pause(200)
}
basic.clearScreen();
})
```
### Animations
Animations are changes happening at a certain rate. For example, we could add the `pause` block from the **Basic** drawer with our square algorithm this will slowly draw a square (as an animation).
We could create more complex animations, for example we could make our @boardname@ display an explosion or fireworks.
### Image variables
We can create image variables so we can easily display an image at a later point. For example:
![](/static/mb/blocks/lessons/graphics-4.png)
This uses the blocks from the **Variable** drawer, and the **create image** block from the **Image** drawer. This means our image can be displayed without having to replicate the `create image` block each time.

View File

@ -1,38 +0,0 @@
# guess the number lesson
Learn to create a random number with input from button A.
## Topic
Math - Pick Random
## Quick links
* [activity](/lessons/guess-the-number/activity)
* [tutorial](/lessons/guess-the-number/tutorial)
* [challenges](/lessons/guess-the-number/challenges)
* [quiz](/lessons/guess-the-number/quiz)
* [quiz answers](/lessons/guess-the-number/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to create numbers randomly by using the input of the @boardname@. We will be learning how to create random numbers with input using a local variable as well as simple commands, such as pick number and show number.
## Documentation
```cards
input.onButtonPressed(Button.A, () => {})
let x = 0
basic.showNumber(0)
Math.random(3)
basic.clearScreen()
```
## Objectives
* learn how to run code when an input button is pressed
* learn how a variable is a place where you can store data
* learn how to set the value of a local variable
* learn how to returns a random number
* learn how to show a number on the LED screen, one digit at a time (scrolling left to right)
* learn how to turn off all the LED lights on the LED screen

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