Migrate docs from the other repo

This commit is contained in:
Michal Moskal 2016-03-25 16:47:20 -07:00
parent 38d2cf06d2
commit a08eb53f92
895 changed files with 36888 additions and 0 deletions

124
docs/device.md Normal file
View File

@ -0,0 +1,124 @@
# Hardware
All the bits and pieces that make up your micro:bit
![](/static/mb/device-0.png)
### Lights
### What are the red lights on the front?
The red lights are [LEDs](/microbit/device/screen) (light emitting diodes) and form a 5 x 5 grid. They can be set to on/off and the brightness can be controlled.
### What is the yellow light on the back of the micro:bit?
It is the status LED. It flashes yellow when the system wants to tell the user that something has happened.
### Buttons
### What are the buttons for?
Buttons A and B are a form of input. They detect when the button is being pressed. When you press one of the buttons, it completes an electrical circuit. The micro:bit can detect either of its two buttons being pressed and un-pressed and be programmed to act on that or send the information to another device.
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.
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
### Why is there a compass on the micro:bit?
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
### Why is there an accelerometer on the micro:bit?
There is a 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
### What are the rings labelled 0, 1, 2 on the bottom edge of the micro:bit?
These are labels for the input/output pins P0, P1, P2, which you can attach external sensors to such as thermometers or moisture detectors. The pins can be a form of input or output. You can read more about large and small pins [here](/microbit/device/pins).
### How do I connect the micro:bit to my computer?
It can be connected to your computer or device with a micro USB. Data can be sent and received between the micro:bit and the computer so programs can be downloaded from Windows and Macs onto the micro:bit via this USB data connection. You can read more information on how to run scripts on your micro:bit [here](/microbit/device/usb), and about the error messages you might get [here](/microbit/device/error-codes).
### Batteries
### How do I power my 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.
### 3V GND
### What are the rings labelled 3V and GND?
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.
### What is a Bluetooth Low Energy Antenna?
You will see this labelled BLE ANNTENA on the back of your micro:bit. It is for a messaging service, built for the Internet of Things 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.
### What is Bluetooth Low Energy?
Bluetooth wireless technology was developed as an alternative to data cables and allowed wireless communication between devices such as PCs, smartphones and tablets. Bluetooth® Smart or Bluetooth Low Energy is a power-friendly version of Bluetooth wireless technology.
### What is the Internet of Things?
The Internet of Things (IoT) was first talked about more than 15 years ago, when it was speculated that objects and people would be able to connect wirelessly over the internet. Objects can be detected and controlled remotely, allowing greater integration between the physical and computer based world. It will let you to remotely control your alarm system, thermostat or lights in your home. It has many applications in different fields including manufacturing, health and fitness, consumer electronics and the home.
### Technical Information
The micro:bit has been designed to be a bare-board micro controller for use by children aged 11-12. The device has been through extensive safety and compliance testing to the following standards:
### Safety
IEC 60950-1:2005 (Second Edition) + Am 1:2009 + Am 2:2013
### EMC
EN 55032: 2012
EN 55024: 2010
EN 55022:2010
EN 301 489-1 V1.9.2 (2011-09)
EN 301 489-17 V2.2.1 (2012-09)
### Radio Spectrum
ETSI EN 300 328 V1.9.1 (2015-02)
EN 62479:2010
### Chemical
Restriction of Hazardous Substances (RoHS) 2011/65/EU Annex II article 4(1)
EN71-3:2013 + A1:2014 - Migration of certain elements.
Analysis of the 163 substances of very high concern (SVHC) on the Candidate List for authorization, concerning Regulation (EC) No. 1907/2006 as published on the European Chemicals Agency (ECHA) website.
![](/static/mb/device-1.jpg)
The micro:bit device features Bluetooth Low Energy radio. The radio on the device operates in the following frequencies:
Frequency Range: 2402MHz to 2480MHz
Bluetooth Version: V4.0 Bluetooth Low Energy
### Declaration of Conformity
The document can be downloaded by clicking here for the [Declaration of Conformity](https://microbit0.blob.core.windows.net/pub/hkeghjes/declaration-of-conformity.pdf)

21
docs/device/contents.md Normal file
View File

@ -0,0 +1,21 @@
# micro:bit - the device
The micro:bit device #docs
The micro:bit is a very capable device with many components:
* [the USB connector](/microbit/device/usb)
* [the LED screen](/microbit/device/screen)
* [the buttons]
* [the accelerometer]
* [the compass]
* [the pins](/microbit/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](/microbit/device/reactive)
Sometimes, your micro:bit may display an error code. For more information, see:
* [the error codes](/microbit/device/error-codes)

View File

@ -0,0 +1,26 @@
# crocodile clips
The on pin pressed accessories.
Register an [event handler](/microbit/reference/event-handler) that will execute whenever the user attaches one side of the crocodile clip to the `GND` pin, then connects and disconnects the unattached side of the crocodile clip to pin `0`, `1`, or `2`.
### 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
![](/static/mb/crocodile-clips-0.png)
### Connecting Crocodile Clips
![](/static/mb/crocodile-clips-1.jpg)
![](/static/mb/crocodile-clips-2.jpg)
### Lessons
[love meter](/microbit/lessons/love-meter)
### See also
[micro:bit pins](/microbit/device/pins), [pin is pressed](/microbit/reference/input/pin-is-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [analog write pin](/microbit/reference/pins/analog-write-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin)

View File

@ -0,0 +1,17 @@
# Error codes
The micro:bit error codes #docs
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
![](/static/mb/device/error-codes-0.png)
### See also
[Run scripts on your micro:bit](/microbit/device/usb)

63
docs/device/pins.md Normal file
View File

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

147
docs/device/reactive.md Normal file
View File

@ -0,0 +1,147 @@
# The micro:bit - a reactive system
The micro:bit is a reactive system. #docs
### 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](/microbit/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](/microbit/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.
```
export function countButtonPresses() {
input.onButtonPressed("A", () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
count = 0
}
```
The program above contains three statements that execute in order from top to bottom. The first statement
```
input.onButtonPressed("A", () => {
count = count + 1
})
```
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. The second statement
```
basic.forever(() => {
basic.showNumber(count, 150)
})
```
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
```
count = 0
```
initializes the global variable `count` to zero. 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 `forever` statement to see an example of cooperative scheduling:
![](/static/mb/device/reactive-2.png)
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:
```
export function countButtonPressesWithReset() {
input.onButtonPressed("A", () => {
count = count + 1
})
basic.forever(() => {
basic.showNumber(count, 150)
})
count = 0
input.onButtonPressed("B", () => {
count = 0
})
}
```

60
docs/device/screen.md Normal file
View File

@ -0,0 +1,60 @@
# LED screen
The micro:bit LED screen
![](/static/mb/device/screen-0.png)
The micro:bit LED screen consists of 25 red LED lights arranged in a 5X5 grid (5 LEDs across by 5 LEDs down).
### Which LED?
You use ``x , y`` coordinates to specify a particular LED in the grid; where ``x`` is the horizontal position 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.
### 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](/microbit/led/plot) and [unplot](/microbit/led/unplot) to turn a LED on or off
### Is a LED on/off?
Use the [point](/microbit/led/point) function to find out if a LED is on or off.
### Display images, strings and numbers
Instead of turning individual LEDs on or off, as above, you can display an [image](/microbit/reference/image/image) directly to the screen or show text/numbers on screen using the [show number](/microbit/reference/basic/show-number)/[show string](/microbit/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
```
basic.showString("d", 150)
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:
```
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.

137
docs/device/usb.md Normal file
View File

@ -0,0 +1,137 @@
# Run Scripts on your micro:bit
How to compile, transfer, and run a script on your micro:bit. #docs #USB #compile #transfer
While you're writing and testing your Block Editor or Touch Develop scripts, you'll mostly be running scripts in your browser by clicking the `Run` button (see [run code in your browser](/microbit/js/simulator) for info about this).
Once your masterpiece is complete, you can compile your script and run it on your micro:bit.
## 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 of later, or a Mac running OS X 10.6 or later
* access to the Internet
## 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.
Windows
![](/static/mb/device/usb-0.jpg)
Mac (picture bvabdbco)
WARN: unknown picture: bvabdbco:5x3
### ~hide
If your computer doesn't recognise your micro:bit, please see [troubleshooting USB problems](/microbit/diagnosing-usb).
### ~
## Step 2: Compile your script
Next, compile your script:
1. Sign in to Touch Develop on your computer.
2. Open your script (find the script in **My Scripts** and click `Edit`).
3. Click `compile`. Your script is converted into a hex file that you can transfer and run on your micro:bit.
4. When prompted, choose to save the compiled file on your computer (or anywhere other than the micro:bit). Depending on which browser you are using, the download will adopt the download behaviour of that particular browser.
### Windows
** Chrome**
Your .hex file appears as a download at the bottom of the browser. Open up your windows file explorer. Your micro:bit appears as a drive called MICROBIT.
**Right click** on the download and select **show in folder**. Drag and drop the hex file from the download folder onto the MICROBIT drive.
Alternatively, you can drag and drop the downloaded hex file from the bottom of the browser onto the file explorer and onto the MICROBIT drive.
![](/static/mb/device/usb-1.jpg)
**Firefox**
A dialogue box will appear, asking whether you would like to open or save your hex file. Select **Save**, then **OK** and the file will appear in your downloads in the top right of your browser. Select the **blue arrow**, select the relevant file and drag and drop it onto your Windows Explorer and onto your MICROBIT drive.
![](/static/mb/device/usb-2.jpg)
![](/static/mb/device/usb-3.jpg)
**IE10**
Click on compile. You will see a message “Do you want to save this .hex file.” Select **Save**.
### Mac
** Safari**
When you select **compile** in Safari on Mac, your file will be downloaded to your downloads folder. Go to your downloads folder and open the file. In Safari the file will appear as unknown.txt rather than a named .hex file. Drag and drop it onto your MICROBIT drive.
![](/static/mb/device/usb-4.jpg)
**Firefox**
A dialogue box will appear, asking whether you would like to open or save your hex file. Select **Save** and **OK** and the file will then appear in your downloads in the top right of your browser. 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-5.jpg)
![](/static/mb/device/usb-6.jpg)
**Chrome**
When you select **compile** in Chrome, the file will be downloaded to the bottom of the browser in .hex format. 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-7.jpg)
## Step 3: Transfer the file to your micro:bit
1. The file will transfer onto your micro:bit.
2. If you're using Windows, you can use **Send to** as described below.
3. The LED on the back of your micro:bit flashes during the transfer (which should only take a few seconds).
4. 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-8.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 script will still run if the micro:bit is powered by battery.
## Troubleshooting
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-9.jpg)
**Mac**
![](/static/mb/device/usb-10.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.
### See also
[Run code in a browser](/microbit/js/simulator)

7
docs/docs.md Normal file
View File

@ -0,0 +1,7 @@
# Documentation
Welcome to the documentation.
* Browse the [reference](/microbit/reference)
* Learn more abou the [device](/microbit/device)
* Get started with [lessons](/microbit/lessons)

48
docs/hourofcode/notes.md Normal file
View File

@ -0,0 +1,48 @@
# Hour of Code notes
learn how to run an Hour Of Code with the BBC micro:bit. #docs
The BBC micro:bit can be used to run an Hour Of Code™ event for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school.
## Preparation
1) Computers
Each participant has **a computer connected to a BBC micro:bit via micro-USB**.
2) Internet
Ensure that each computer has access to **internet**.
3) Accounts
Create a classroom in https://www.microbit.co.uk and pre-populate the classroom with student accounts. **Print the student passwords** and cut out each password.
4) Print the activity challenges (1 copy per participant):
* [hour of code](/microbit/js/hourofcode/challenges)
4) (optional) Raffle tickets and prizes
Reward students with raffle tickets to keep them engaged. Finishing a tutorial or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice).
5) (optional) Music
Bring more energy in the room by playing music.
## Timeline
* ``00:00`` student sign in using **printed passwords** (see step 3)
* ``10:00`` [hour of code tutorial](/microbit/js/hourofcode)
* ``40:00`` raffle and demoes
* ``50:00`` that's it!
## Follow up
After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start:
* [more challenges](/microbit/js/lessons) are available for BBC micro:bit
* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within BBC micro:bit
_The Hour of Code™ is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming._

71
docs/lessons.md Normal file
View File

@ -0,0 +1,71 @@
# Lessons
Overview of lessons for the BBC micro:bit.
### @short Lessons
### ~column
## Beginner
* [Beautiful Image](/microbit/lessons/beautiful-image), show a beautiful image with show LEDs
* [Lucky 7](/microbit/lessons/lucky-7), show a number on the LED screen with show number
* [Answering Machine](/microbit/lessons/answering-machine), show a text message with show string
* [Game of Chance](/microbit/lessons/game-of-chance), show a text message with game over
* [Smiley,](/microbit/lessons/smiley) smiley and frowney faces that transition on button pressed
* [Magic Logo,](/microbit/lessons/magic-logo) show an image on logo up
* [Snowflake Fall](/microbit/lessons/snowflake-fall), repeat a series of images with forever
* [Screen Wipe](/microbit/lessons/screen-wipe), turn off the LEDs with clear screen
* [Flashing Heart](/microbit/lessons/flashing-heart), display images with a pause
* [Blink](/microbit/lessons/blink), turn an LED on and off with plot
* [Night Light](/microbit/lessons/night-light), dim the LEDs with set brightness
* [Game Counter](/microbit/lessons/game-counter), displays the player's score with score and add points to score
* [Happy Birthday](/microbit/lessons/happy-birthday), create a popular song
### ~
### ~column
## Intermediate
* [Magic 8](/microbit/lessons/magic-8), a fortune teller game with the BBC micro:bit
* [Guess the Number](/microbit/lessons/guess-the-number), guess a random number with pick number
* [Counter](/microbit/lessons/counter), display a number with a variable
* [Love Meter](/microbit/lessons/love-meter), create a love meter with on pin pressed
* [Rock Paper Scissors](/microbit/lessons/rock-paper-scissors), create the classic game of rock paper scissors with if statement
* [Truth or Dare](/microbit/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement
* [Spinner](/microbit/lessons/spinner), spin the arrow with multiple if statements
* [Die Roll](/microbit/lessons/die-roll), spin with more if statements
* [Looper](/microbit/lessons/looper), display a series of numbers with a for loop index
* [Strobe Light](/microbit/lessons/strobe-light), develop shapes with a nested for loops
* [Temperature](/microbit/lessons/temperature), get the ambient temperature (degree Celsius °C)
* [Digi Yoyo](/microbit/lessons/digi-yoyo), create a counter with a while loop
* [Rotation Animation](/microbit/lessons/rotation-animation), control an animation with a boolean variable
* [Compass](/microbit/lessons/compass), displays the direction the BBC micro:bit is pointing with compass
* [Zoomer](/microbit/lessons/zoomer), measure the force with acceleration
* [Glowing Pendulum](/microbit/lessons/glowing-pendulum), construct a pendulum that glows using acceleration
* [Classic Beatbox](/microbit/lessons/classic-beatbox), make a beatbox music player with variables
* [Light Beatbox](/microbit/lessons/light-beatbox), make a beatbox music player with light level
### ~
### ~column
## Maker
* [The Watch](/microbit/lessons/the-watch), design and create The Watch
* [Hack your Headphones](/microbit/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones
* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits
* [Telegraph](/microbit/lessons/telegraph), play the telegraph game between two BBC micro:bits
* [Ornament Chain](/microbit/lessons/ornament-chain), play the ornament chain game between two BBC micro:bits
## Advanced
* [Hero](/microbit/lessons/hero), reconstruct the classic arcade game pac man with the BBC micro:bit
### ~
### @section full
The lessons promote computational thinking and computer science literacy[ read more...](/microbit/lessons/teach)

View File

@ -0,0 +1,80 @@
# answering machine blocks lesson
create an answering machine on the BBC micro:bit #docs
### @video td/videos/answering-machine-0
## Topic
Show String
## Quick Links
* [activity](/microbit/lessons/answering-machine/activity)
* [quiz](/microbit/lessons/answering-machine/quiz)
* [quiz answers](/microbit/lessons/answering-machine/quiz-answers)
* [challenges](/microbit/lessons/answering-machine/challenges)
## Class
Year 7
## 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
* **show string** : [read more...](/microbit/reference/basic/show-string)
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
## Objectives
* learn how to show a string on the LED screen one character at a time
* learn how to use to register an event handler that will execute whenever an input button is pressed
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
* Evaluates the appropriatness of digital devices, internet services and application software to achieve given goals (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/answering-machine/activity)
* [quiz](/microbit/lessons/answering-machine/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/answering-machine/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/answering-machine/challenges)

View File

@ -0,0 +1,24 @@
# answering machine blocks activity
Learn to create an answering machine on the micro:bit
### ~avatar avatar
### @video td/videos/answering-machine-0
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](/microbit/lessons/answering-machine/challenges)!
### ~

View File

@ -0,0 +1,51 @@
# answering machine blocks challenges
Coding challenges for the answering machine tutorial.
## Before we get started
Complete the [answering machine](/microbit/lessons/answering-machine/activity) activity and your code will look like this:
```blocks
basic.showString("ASK ME A QUESTION")
```
### Challenge 1
### @video td/videos/answering-machine-1
Now we need to reply after someone asks micro:bit 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
### @video td/videos/answering-machine-2
What if micro:bit'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

@ -0,0 +1,30 @@
# answering machine blocks quiz answers
Create an answering machine on the micro:bit. #LED #screen #show #math #docs #input
This is the answer key for the [answering machine quiz](/microbit/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
![](/static/mb/blocks/lessons/answering-machine-3.png)
![](/static/mb/lessons/answering-machine-0.png)
## 3. Draw which LED is ON after running this code
![](/static/mb/blocks/lessons/answering-machine-4.png)
![](/static/mb/lessons/answering-machine-1.png)
<br/>
## 4. If the rectangle below represents the micro:bit, write the code to display the letter "Z".
![](/static/mb/lessons/answering-machine-2.png)
![](/static/mb/blocks/lessons/answering-machine-5.png)

View File

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

View File

@ -0,0 +1,25 @@
# banana keyboard blocks lesson
display beautiful images on the BBC micro:bit #var #pause #docs
## Topic
Music
## Quick Links
* [activity](/microbit/lessons/banana-keyboard/activity)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, earphones (or speakers), as well as crocodile clips (or spring clips). The connect fruit using pins P1 and GND.
## Objectives
* learn how to setup the BBC micro:bit with earphones to play music
* learn how to setup the BBC micro:bit with fruit be the musical instrument

View File

@ -0,0 +1,83 @@
# banana keyboard activity
build a banana keyboard
# micro:bit banana keyboard
![](/static/mb/lessons/banana-keyboard-0.png)
In this project, you will build your own music player micro:bit banana keyboard from household fruit. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Bananas
* Orange
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/banana-keyboard-2.png)
![](/static/mb/lessons/banana-keyboard-3.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/lessons/banana-keyboard-4.png)
Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack.
### Step 4
![](/static/mb/lessons/banana-keyboard-5.png)
![](/static/mb/lessons/banana-keyboard-6.png)
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto tip of the headphone jack.
### Step 5
![](/static/mb/lessons/banana-keyboard-7.png)
Using the 3rd crocodile clip, connect the end of the crocodile clip onto the 1st crocodile clip already clipped onto GND.
### Step 6
![](/static/mb/lessons/banana-keyboard-8.png)
![](/static/mb/lessons/banana-keyboard-9.png)
Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto the orange.
### Step 7
![](/static/mb/lessons/banana-keyboard-10.png)
Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 1 on the micro:bit.
### Step 8
![](/static/mb/lessons/banana-keyboard-11.png)
Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto the banana.
### Step 9
![](/static/mb/lessons/banana-keyboard-12.png)
Your banana keyboard is ready!
### Step 10
Connect your micro:bit to your computer using your USB cable and run the [banana keyboard](/microbit/lhpkbr) script on it. Tap your banana instrument to play sound against... the fruit!

View File

@ -0,0 +1,65 @@
# banana keyboard blocks challenges
control images with variables.
## Before we get started
Control images with variables.
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
Have you ever tried to making beat box sounds? Let's try making a beatbox with code!
We will register an event handler on the fruit that will execute when two things occur: first, the alligator clip attaches to GND and the other side of the alligator clip is inserted into a banana. 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
}
})
```
* click *run* to see if the code works as expected.
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. You will need to include a second banana to a alligator (spring) clip in the same procedure as the first activity.
```blocks
let sound = music.noteFrequency(Note.A);
input.onPinPressed(TouchPin.P1, () => {
for (let i = 0; i < 4; i++) {
sound = sound + 25
}
})
input.onPinPressed(TouchPin.P2, () => {
for (let i = 0; i < 4; i++) {
sound = sound - 25
}
})
```
* click *run* to see if the code works as expected.

62
docs/lessons/beatbox.md Normal file
View File

@ -0,0 +1,62 @@
# beatbox blocks lesson
display beautiful images on the BBC micro:bit #var #pause #docs
## Topic
Music
## Quick Links
* [activity](/microbit/lessons/beatbox/activity)
* [challenges](/microbit/lessons/beatbox/challenges)
## Class
Year 7
## 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 BBC micro:bit
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/beatbox/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/beatbox/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/beatbox/challenges)

View File

@ -0,0 +1,72 @@
# beautiful image lesson
display beautiful images on the BBC micro:bit #var #pause #docs
### @video td/videos/beautiful-image-0
## Topic
Show LEDs
## Quick Links
* [activity](/microbit/lessons/beautiful-image/activity)
* [challenges](/microbit/lessons/beautiful-image/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to **show LEDs**, to show an image on the BBC micro:bit's LED screen. We will be learning how to Show LEDs using simple commands such as Show LEDs and pause.
## Documentation
* **show LEDs** : [read more...](/microbit/reference/basic/show-leds)
* **pause** : [read more...](/microbit/reference/basic/pause)
## Objectives
* learn how to display an image on the micro:bit's LED screen
* learn how to pause your code for the specified number of milliseconds
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Represents solutions using a structured notation (AL) (AB)
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Selects the appropriate data types(AL) (AB
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/beautiful-image/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/beautiful-image/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/beautiful-image/challenges)

View File

@ -0,0 +1,32 @@
# beautiful image blocks activity
Generate and show a beautiful image. #docs #microbit
### ~avatar avatar
### @video td/videos/beautiful-image-0
Let's learn how to show an image on the LED screen.
### ~
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under the *Block Editor*.
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](/microbit/lessons/beautiful-image/challenges)!
### ~

View File

@ -0,0 +1,47 @@
# beautiful image blocks challenges
Coding challenges for the beautiful image tutorial.
## Before we get started
Complete the [beautiful image](/microbit/lessons/beautiful-image/activity) activity and your code will look like this:
```blocks
basic.showLeds(`
# # # # #
# # . # #
# . # . #
# # . # #
# # # # #
`)
```
### Challenge 1
### @video td/videos/beautiful-image-1-2
Now show an new image that will display on the micro:bit.
```blocks
basic.showLeds(`
# # # # #
# # . # #
# . # . #
# # . # #
# # # # #
`)
basic.showLeds(`
# . # . #
. # # # .
. . # . .
. # # # .
# . # . #
`)
```
* *Run* your code to see if it works as expected.
### Challenge 2
Nice job! Why don't we create a third image that will show after the other two? Remember to add a pause before you create and show the image.

92
docs/lessons/blink.md Normal file
View File

@ -0,0 +1,92 @@
# blink blocks lesson
Learn how to create a blinking LED. #LED #screen #plot #docs #lesson
### @video td/videos/blink-0
## Topic
Plot
## Quick links
* [activity](/microbit/lessons/blink/activity)
* [quiz](/microbit/lessons/blink/quiz)
* [quiz answers](/microbit/lessons/blink/quiz-answers)
* [challenges](/microbit/lessons/blink/challenges)
## Class
Year 7
## Prior learning / place of lesson in scheme of work
Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, unplot and pause.
## What the teacher needs to know / QuickStart Computing Glossary
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem
**Loop:** A block of code repeated automatically under the programs control. The blink program introduces Forever. The forever loop repeats code in the background forever.
**Command:** An instruction for the computer to execute, written in a particular programming language.
## Documentation
* **plot**: [read more...](/microbit/reference/led/plot)
* **unplot**: [read more...](/microbit/reference/led/unplot)
* **pause**: [read more...](/microbit/reference/basic/pause)
* **forever**: [read more...](/microbit/reference/basic/forever)
## Resources
* Activity: [activity](/microbit/lessons/blink/activity)
* Activity: [quiz](/microbit/lessons/blink/quiz)
* Extended Activity: [challenges](/microbit/lessons/blink/challenges)
## Objectives
* learn how to turn on LED lights on the LED screen
* learn how to turn off LED lights on the LED screen
* learn how to pause program execution for the specified number of milliseconds
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Understands that iteration is the repetition of a process such as a loop. (AL)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals. (AL)
#### Data & Data Representation
* Understands the difference between data and information. (AB)
* Defines data types: real numbers and Boolean. (AB)
#### Information Technology
* Collects, organises and presents data and information in digital content. (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/blink/activity)
* [quiz](/microbit/lessons/blink/quiz)
* [quiz answers](/microbit/lessons/blink/quiz-answers)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/blink/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/blink/challenges)

View File

@ -0,0 +1,56 @@
# blink blocks activity
Turn an LED on and off with forever
### ~avatar avatar
### @video td/videos/blink-0
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
### ~
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](/microbit/lessons/blink/challenges)!
### ~

View File

@ -0,0 +1,85 @@
# blink blocks challenges
Coding challenges for the blink tutorial
## Before we get started
Complete the [blink](/microbit/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
### @video td/videos/blink-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
### @video td/videos/blink-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
### @video td/videos/blink-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

@ -0,0 +1,40 @@
# blink blocks quiz answers
Learn how to create a blinking LED script. #LED #screen #plot #docs
This is the answer key for the [blink quiz](/microbit/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
![](/static/mb/blocks/lessons/blink-6.png)
![](/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
![](/static/mb/blocks/lessons/blink-7.png)
![](/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
![](/static/mb/blocks/lessons/blink-8.png)
![](/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

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

View File

@ -0,0 +1,50 @@
# blocks - if statements
An introduction to conditions for the Block Editor. #docs
## Introduction to conditions
In the introduction to code, we made the BBC micro:bit automatically shows the message hello, world!:
![](/static/mb/blocks/lessons/blocks-conditions-0.png)
This statement, or code, will happen as soon as the BBC micro:bit 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 BBC Micro:bit will wait for the user to press a button before showing the image.
### Write the code
Click the **if** category and drag an `if/do` block. Drag the`show string` block we wrote previously into the `do` section of the block. Next click the **input** tab and drag a `button pressed` block, connect it to the open jigsaw of the `if` block. This is our criteria: `if A button is pressed`. We can change which button (button A or B) by clicking the arrow next to A and changing the value. This means our BBC micro:bit is waiting for button A (the left button) to be pressed. Finally go to the **basic** tab and drag a `forever` block, and attach all our code inside. We add this block to ensure the BBC micro:bit is always waiting to show us this message, not just once. Your code should look like this:
![](/static/mb/blocks/lessons/blocks-conditions-1.png)
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 BBC Micro:bit 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 BBC micro:bit, 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:
![](/static/mb/blocks/lessons/blocks-conditions-2.png)
So, to recap: the `forever` block makes sure our code runs forever. The BBC micro:bit 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 BBC micro:bit to the computer then click **compile** to send the code onto the BBC micro:bit.
## What is a condition?
A condition is criteria that the user must meet for a certain function to be carried out.

81
docs/lessons/buzzer.md Normal file
View File

@ -0,0 +1,81 @@
# buzzer lesson
design a blinking image lesson #docs
## Topic
Ring
## Quick Links
* [activity](/microbit/lessons/buzzer/activity)
* [challenges](/microbit/lessons/buzzer/challenges)
## Class
Year 7
## Prior learning / place of lesson in scheme of work
Learn how to **ring** the buzzer to turn on the sound. We will be learning basic comments such as ring and clear screen.
## Documentation
* **ring** : [read more...](/microbit/reference/music/ring)
* **clear screen** : [read more...](/microbit/reference/basic/clear-screen)
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
## Objectives
* learn how to ring the BBC micro:bit
* learn how to clear the screen
* learn how to run code when an input button is pressed
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Recognises that different algorithms exist for the same problem (AL) (GE)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Understands the difference between data and information(AB)
#### Hardware & Processing
* Understands the difference between hardware and application software, and their roles within a computer system (AB)
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/buzzer/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/buzzer/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/buzzer/challenges)

View File

@ -0,0 +1,88 @@
# blocks - challenges
Extra stuff for the Block Editor - an introduction to GPIO #docs
## Before we get started
This section details challenges for the BBC micro:bit. Ensure you have completed all other sections of the Microsoft Block Editor tutorials before attempting these challenges!
## Quiz Challenge [1]
Using if statements, try to add more statements to create a simple quiz. The user will be told if the question is right or not, and will have two options (button A and button B).
Here is some sample code for a simple quiz:
![](/static/mb/blocks/lessons-0.png)
## Timer Challenge [2]
Create a timer that runs out after a certain amount of time (using the *count* loop). For an extra challenge, let the user input the amount of seconds they want the timer to run for using variables and the buttons as input. The solution is below.
![](/static/mb/blocks/lessons-1.png)
## Graphics Challenges [3]
Using the knowledge you have learnt from the [rendering graphics](/microbit/lessons/graphics) section, try creating an algorithm to draw these shapes. Before you write the code try to figure out how the BBC micro:bit will be thinking to plot these points. For example, with our diagonal line “count up from 0 to 4 by 1, and plot points x=i and y=i”.
* Another diagonal line
* A square going around the board
* A filled square
* A square which unplots itself after
* A filled square which then unplots itself
The solutions are below.
### Square [3.1]
![](/static/mb/blocks/lessons-2.png)
### Filled square [3.2]
![](/static/mb/blocks/lessons-3.png)
### Vanishing square [3.3]
Use the same code and algorithm for the square solution, only use the unplot block to make this LED turn off again. You could also reverse the algorithm.
### Vanishing filled square [3.4]
Use the same code and algorithm for the filled square solution, only use the `unplot` block to make this LED turn off again. You could also reverse the algorithm.
## Animation Challenge [4]
Use your new knowledge of animations and algorithms to program your BBC micro:bit to act human: for example, you could make your BBC micro:bit smile and wink. Remember you can display images with the `show image` and `create image` blocks. Sample code is below.
![](/static/mb/blocks/lessons-4.png)
## Electronic Dice Challenge [5]
Using the code in the Random Numbers tutorial in Section 6, or your own algorithm, create an electronic dice that displays the values appropriate for a dice (so 1 shows a single LED on in the center, two shows two LEDs on at each corner, etc.). You may want to declare image variables to do this, then check what it is equal to using an if statement. Sample code is below.
![](/static/mb/blocks/lessons-4.png)
## Calculator Challenge [6]
Using your knowledge of loops, counters and math, create a calculator.
The calculator should:
* Count the amount of times the user presses the left button before pressing the right button (this is the first value, or valueOne)
* Count the amount of times the user presses the left button before the right button again (this is the second value, or valueTwo)
* Scroll through operations (+,-, x and divide) until the user presses the right button to make a choice
* Perform the calculation
* Show the entire calculation, for example: 5 + 10 = 15
Sample code is below.
![](/static/mb/blocks/lessons-5.png)
## Smart watch Challenge [8]
Create a smart watch using the BBC micro:bit. Create a menu where the user presses one button to cycle through options and another button to choose this option. Add applications to this smart watch:
* Calculators
* Games
* Random number generators
And any other applications you can think of.

58
docs/lessons/charting.md Normal file
View File

@ -0,0 +1,58 @@
# charting lesson
measure the acceleration on the micro:bit in the "z" direction #acceleration #var #docs #if #show
## Topic
Acceleration
## Quick Links
* [activity](/microbit/lessons/charting/activity)
## Class
Year 7
## 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
* **forever** : [read more...](/microbit/reference/basic/forever)
* **acceleration** : [read more...](/microbit/reference/input/acceleration)
* **plot bar graph** : [read more...](/microbit/reference/led/plot-bar-graph)
* **on data received** : [read more...](/microbit/reference/radio/on-data-received)
* **send number** : [read more...](/microbit/reference/radio/send-number)
* **receive number** : [read more...](/microbit/reference/radio/receive-number)
## 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 micro:bits connected via radio
* learn how to read the next radio packet as a number data packet
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Represents solutions using a structured notation (AL) (AB)
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/charting/activity)

View File

@ -0,0 +1,53 @@
# charting activity
Measure the acceleration on the micro:bit in the "z" direction.
### ~avatar avatar
To create a new script, go to the [Create Code](/microbit/create-code) page and tap `New Project` under `Block Editor`.
### ~
Welcome! This activity will teach how to use the 1st micro:bit to chart the second micro:bit's acceleration in the "x" direction. 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 micro:bits 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.onDataReceived(() => {
})
```
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 micro:bit, we must implement `receive number` to constantly display a vertical bar graph based on the value. Remember, the value will equal to the micro:bit's acceleration in the "x" direction.
```blocks
basic.forever(() => {
radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
led.plotBarGraph(radio.receiveNumber(), 1023)
})
```
* Connect the first micro:bit to your computer using your USB cable and run the charting script on it.
* Connect the second micro:bit to your computer using your USB cable and run the charting script on it.
* The first person and second person take turns tilting the micro:bit in the "x" direction while the other player charts the data on the micro:bit!

View File

@ -0,0 +1,62 @@
# classic beatbox
display beautiful images on the BBC micro:bit #var #pause #docs
## Topic
Music
## Quick Links
* [activity](/microbit/lessons/classic-beatbox/activity)
* [challenges](/microbit/lessons/classic-beatbox/challenges)
## Class
Year 7
## 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 BBC micro:bit
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/classic-beatbox/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/classic-beatbox/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/classic-beatbox/challenges)

View File

@ -0,0 +1,56 @@
# beatbox activity
Control images with variables.
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
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](/microbit/lessons/classic-beatbox/challenges)!
### ~

View File

@ -0,0 +1,48 @@
# beatbox challenges
Create sounds with variables.
## Before we get started
Complete the [beatbox](/microbit/lessons/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.

97
docs/lessons/compass.md Normal file
View File

@ -0,0 +1,97 @@
# compass lesson
create a die on the BBC micro:bit #button #pressed #math #random #var #string #if #docs
### @video td/videos/compass-0
## Topic
If (Conditionals)
## Quick Links
* [activity](/microbit/lessons/compass/activity)
* [challenges](/microbit/lessons/compass/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a compass with If statements, Forever, Variables, Assignment Operator, Comparison Operator, Show String, and Show LEDs
## Documentation
* **Compass Heading** : [read more...](/microbit/reference/input/compass-heading)
* **Forever** : [read more...](/microbit/reference/basic/forever)
* **Variables** : [read more...](/microbit/reference/variables/var)
* **Assignment Operator** : [read more...](/microbit/reference/variables/assign)
* **If** : [read more...](/microbit/reference/logic/if)
* **Comparison Operator** : [read more...](/microbit/reference/types/number)
* **Show String** : [read more...](/microbit/reference/basic/show-string)
* **Show LEDs** : [read more...](/microbit/reference/basic/show-leds)
## Objectives
* learn how to run code when the BBC micro:bit is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
* learn how to create a local variable as a place where you can store and retrieve data
* learn how the assignment operator is used to declare a new local variable
* learn how to declare a new local variable or update the value of a variable
* learn how to return a random number
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to show an image on the LED screen
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Understands the difference between data and information(AB)
* Uses filters or can perform single criteria searches for information.(AL)
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
* Defines data types: real numbers and Boolean (AB)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Makes judgements about digital content when evaluating and repurposing it for a given audience (EV) (GE)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/compass/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/compass/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/compass/challenges)

View File

@ -0,0 +1,102 @@
# compass activity
Display the direction that the micro:bit is facing using the compass
### ~avatar avatar
Welcome! This guided tutorial will show you how to program a script that displays the direction the micro:bit 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 micro:bit 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 micro:bit.
```blocks
let degrees = 0;
basic.forever(() => {
degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
});
```
If `degrees` is less than 135, the micro:bit is mostly pointing East. Display `E` on the micro:bit.
```blocks
let degrees = null;
basic.forever(() => {
degrees = input.compassHeading();
if (degrees < 45) {
basic.showString("N");
}
else if (degrees < 135) {
basic.showString("E");
}
});
```
If `degrees` is less than 225, the micro:bit is mostly pointing South. Display `S` on the micro:bit.
```blocks
let degrees = null;
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");
}
});
```
If none of these conditions returned true, then the micro:bit must be pointing West. Display `W` on the micro:bit.
```blocks
let degrees = null;
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");
}
});
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/compass/challenges)!
### ~

View File

@ -0,0 +1,88 @@
# compass challenges
Display the direction that the micro:bit is facing using the compass
## Before we get started
Complete the following [guided tutorial](/microbit/lessons/compass/activity), your code should look like this:
```blocks
let degrees = null;
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 BBC micro:bit is pointing North, display a star to indicate the north star.
```blocks
let degrees = null;
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 = null;
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

@ -0,0 +1,56 @@
# compass quiz answers
Create an actual compass to show your direction: North, South, East, or West
## Name
## Directions
Use this activity document to guide your work in the [compass tutorial](/microbit/lessons/compass/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 micro:bit in degrees
<br/>
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
<br/>
```
let degrees = input.compassHeading()
```
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
<br />
```
if (degrees < 45) {
basic.showString("N", 150)
}
```
## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
<br />
```
if (degrees < 135) {
basic.showString("E", 150)
}
```
## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
<br />
```
if (degrees < 225) {
basic.showString("S", 150)
}
```

View File

@ -0,0 +1,32 @@
# compass quiz
Create an actual compass to show your direction: North, South, East, or West
## Name
## Directions
Use this activity document to guide your work in the [compass activity](/microbit/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?
<br/>
## 2. Write the code that stores the compass heading into a local variable called 'degrees'.
<br/>
## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit
<br />
## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit
<br />
## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit
<br />

75
docs/lessons/counter.md Normal file
View File

@ -0,0 +1,75 @@
# counter lesson
Learn how to create a counter with with on button pressed. #show #number #screen #number #math #docs
### @video td/videos/counter-0
## Topic
Variables
## Quick Links
* [activity](/microbit/lessons/counter/activity)
* [challenges](/microbit/lessons/counter/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using a variable as well as simple commands, such as on button pressed, and show number.
## Documentation
* **variable**: [read more...](/microbit/reference/variables/var)
* **arithmetic operators**: [read more...](/microbit/reference/types/number)
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
* **show number** : [read more...](/microbit/reference/basic/show-number)
## Objectives
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across all functions, and in nested code blocks
* learn how arithmetic operators operate on numbers and return a number
* learn how to run code when an input button is pressed
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Understands that iteration is the repetition of a process such as a loop. (AL)
* Represents solutions using a structured notation. (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals. (AL)
* Declares and assigns variables.(AB)
#### Data & Data Representation
* Understands the difference between data and information. (AB)
* Defines data types: real numbers and Boolean. (AB)
#### Information Technology
* Collects, organises and presents data and information in digital content. (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/counter/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/counter/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/counter/challenges)

View File

@ -0,0 +1,45 @@
# counter activity
Display a number with a variable.
### ~avatar avatar
### @video td/videos/counter-0
Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. Let's get started!
### ~
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](/microbit/lessons/counter/challenges)
### ~

View File

@ -0,0 +1,40 @@
# counter challenges
Coding challenges for the counter.
## Before we get started
Complete the following [guided tutorial](/microbit/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
### @video td/videos/counter-1-2
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 micro:bit is shaken. You will need to register an event handler with `on shake`.

View File

@ -0,0 +1,41 @@
# crocodile clip activity
Use the crocodile clips
# micro:bit crocodile clip
![](/static/mb/blocks/lessons/crocodile-clip-0.jpg)
In this project, you will build a circuit with the micro:bit from crocodile clips. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/crocodile-clips-2.jpg)
Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/blocks/lessons/crocodile-clip-0.jpg)
Disconnect the end of the crocodile clip from the 0 pin of the micro:bit.
Your circuit is complete!
### Step 10
Connect your micro:bit to your computer using your USB cable and run the [guess the number](/microbit/lhpkbr) script on it.

95
docs/lessons/die-roll.md Normal file
View File

@ -0,0 +1,95 @@
# die roll lesson
create a die on the BBC micro:bit #button #pressed #math #random #var #string #if #docs
### @video td/videos/die-roll-0
## Topic
If (Conditionals)
## Quick Links
* [activity](/microbit/lessons/die-roll/activity)
* [challenges](/microbit/lessons/die-roll/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a die with If statements, On Shake, Variables, Assignment Operator, Pick Random and Show LEDs
## Documentation
* **Variables** : [read more...](/microbit/reference/variables/var)
* **If** : [read more...](/microbit/blocks/if)
* **On Shake** : [read more...](/microbit/reference/on-gesture)
* **Assignment Operator** : [read more...](/microbit/reference/variables/assign)
* **Pick Random** : [read more...](/microbit/blocks/math)
* **Show LEDs** : [read more...](/microbit/reference/basic/show-leds)
## Objectives
* learn how to run code when the BBC micro:bit is shaken, when running code in the web browser, moving the mouse quickly simulates shaking
* learn how to create a local variable as a place where you can store and retrieve data
* learn how the assignment operator is used to declare a new local variable
* learn how to declare a new local variable or update the value of a variable
* learn how to return a random number
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to show an image on the LED screen
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Understands the difference between data and information(AB)
* Uses filters or can perform single criteria searches for information.(AL)
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
* Defines data types: real numbers and Boolean (AB)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Makes judgements about digital content when evaluating and repurposing it for a given audience (EV) (GE)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/die-roll/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/die-roll/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/die-roll/challenges)

View File

@ -0,0 +1,171 @@
# die roll activity
Create a die on the micro:bit
### ~avatar avatar
### @video td/videos/die-roll-0
Welcome! This tutorial will help you create a die. Let's get started!
### ~
Let's create a condition for when the micro:bit is shaken.
```blocks
input.onGesture(Gesture.Shake, () => {
})
```
We need to show a random value from 1 to 6 on our die. So let's make a local variable called **roll**.
```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 die 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 die.
```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 die.
```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 die. We are almost done with our die!
```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](/microbit/lessons/die-roll/challenges)!
### ~

View File

@ -0,0 +1,183 @@
# die roll challenges
Create a die on the micro:bit.
## Before we get started
Complete the following [guided tutorial](/microbit/lessons/die-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 die.
```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 die! Modify the line of code with `pick random` so that only numbers 3-6 can appear on the die. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit.
```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 BBC micro:bit randomly chooses a number between 1 and 8.

88
docs/lessons/digi-yoyo.md Normal file
View File

@ -0,0 +1,88 @@
# digi yoyo lesson
create a counter with a while loop #while #loop #counter #docs
### @video td/videos/digi-yoyo-0
## Topic
While Loop
## Quick Links
* [activity](/microbit/lessons/digi-yoyo/activity)
* [challenges](/microbit/lessons/digi-yoyo/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to creating a **while loop**, `while condition do` to repeat code while a condition is true. We will be learning how to create a digi yoyo app using a while loop, a variable, as well as basic commands, such as pause and show number.
## Documentation
* **variables** : [read more...](/microbit/reference/variables/var)
* **assignment operator** : [read more...](/microbit/reference/variables/assign)
* **while loop** : [read more...](/microbit/reference/loops/while)
* **relational operator ** : [read more...](/microbit/reference/types/number)
* **pause** : [read more...](/microbit/reference/basic/pause)
* **show number** : [read more...](/microbit/reference/basic/show-number)
## Objectives
* learn how to create a local variables to store data and use it in your code
* learn how to set or change the value of a local variable
* learn how to repeat code while a condition is true
* learn how a relational comparison (<) of numbers will yield a Boolean
* learn how to pause your code for the specified number of milliseconds
* learn how to show a number on the LED screen
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL)
* Recognises that different algorithms exist for the same problem (AL) (GE)
* Represents solutions using a structured notation (AL) (AB)
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Uses filters or can perform single criteria searches for information.(AL)
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/digi-yoyo/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/digi-yoyo/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/digi-yoyo/challenges)

View File

@ -0,0 +1,61 @@
# digi yoyo activity
Create a counter with a while loop.
### ~avatar avatar
### @video td/videos/digi-yoyo-0
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.
![](/static/mb/blocks/lessons/digi-yoyo-1.jpg)
```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 + 1
}
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/digi-yoyo/challenges)!
### ~

View File

@ -0,0 +1,73 @@
# digi yoyo challenges
Coding challenges for the digi yoyo.
## Before we get started
Complete the following [guided tutorial](/microbit/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
### @video td/videos/digi-yoyo-1-2
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!
```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 micro:bit has displayed the value of `count`.
We can do this by adding this line:
```blocks
let count = count + (count - 1);
```

View File

@ -0,0 +1,78 @@
# flashing heart blocks lesson
Learn how to create LED images with a global variable. #LED #screen #plot #docs
### @video td/videos/flashing-heart-0
## Topic
Pause
## Quick links
* [activity](/microbit/lessons/flashing-heart/activity)
* [quiz](/microbit/lessons/flashing-heart/quiz)
* [quiz answers](/microbit/lessons/flashing-heart/quiz-answers)
* [challenges](/microbit/lessons/flashing-heart/challenges)
## Class
Year 7
## 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
* **forever**: [read more...](/microbit/reference/basic/forever)
* **show LEDs** : [read more...](/microbit/reference/basic/show-leds)
* **pause**: [read more...](/microbit/reference/basic/pause)
* **clear screen**: [read more...](/microbit/reference/basic/clear-screen)
## Objectives
* learn how to repeat code in the background forever
* learn how to 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
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Understands that iteration is the repetition of a process such as a loop. (AL)
* Represents solutions using a structured notation. (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals. (AL)
* Declares and assigns variables.(AB)
#### Data & Data Representation
* Understands the difference between data and information. (AB)
* Defines data types: real numbers and Boolean. (AB)
#### Information Technology
* Collects, organises and presents data and information in digital content. (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Exercise
* time: 20 min.
* [activity](/microbit/lessons/flashing-heart/activity)
* [quiz](/microbit/lessons/flashing-heart/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/flashing-heart/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges)

View File

@ -0,0 +1,75 @@
# flashing heart blocks activity
Control images with a variable.
### ~avatar avatar
### @video td/videos/flashing-heart-0
In this activity, you will learn how to blink an image on the LED screen.
### ~
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
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 micro:bit.
```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](/microbit/lessons/flashing-heart/challenges)!
### ~

View File

@ -0,0 +1,100 @@
# flashing heart blocks challenges
Coding challenges for the flashing heart tutorial.
## Before we get started
Complete the [flashing heart](/microbit/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
### @video td/videos/flashing-heart-1
Let's plot a different image. Let's display a broken heart!
To do this, you need to add a 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
### @video td/videos/flashing-heart-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

@ -0,0 +1,22 @@
# flashing heart blocks quiz answers
Learn how to create an image with a variable.
This is the answer key for the [flashing heart quiz](/microbit/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)
<br/>
![](/static/mb/blocks/lessons/flashing-heart-5.jpg)
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
![](/static/mb/blocks/lessons/flashing-heart-6.jpg)
<br/>

View File

@ -0,0 +1,30 @@
# 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](/microbit/lessons/flashing-heart/activity).
Answer the questions while completing the activity. Pay attention to the dialogues!
## 1. Describe what `pause` does?
<br/>
<br/>
## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds)
<br/>
<br/>
## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds)
<br/>
<br/>

View File

@ -0,0 +1,73 @@
# game counter lesson
Learn how to create a counter with with on button pressed. #show #number #screen #number #math #docs
### @video td/videos/counter-0
## Topic
Game Library
## Quick Links
* [activity](/microbit/lessons/game-counter/activity)
* [challenges](/microbit/lessons/game-counter/challenges)
## Class
Year 7
## 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
* **game library**: [read more...](/microbit/js/game-library)
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
* **show number** : [read more...](/microbit/reference/basic/show-number)
## 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
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Understands that iteration is the repetition of a process such as a loop. (AL)
* Represents solutions using a structured notation. (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals. (AL)
* Declares and assigns variables.(AB)
#### Data & Data Representation
* Understands the difference between data and information. (AB)
* Defines data types: real numbers and Boolean. (AB)
#### Information Technology
* Collects, organises and presents data and information in digital content. (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/game-counter/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/game-counter/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/game-counter/challenges)

View File

@ -0,0 +1,42 @@
# game counter activity
Turn an LED on and off with forever loop
### ~avatar avatar
### @video td/videos/counter-0
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
### ~
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](/microbit/lessons/game-counter/challenges)!
### ~

View File

@ -0,0 +1,39 @@
# game counter challenges
Coding challenges for the game counter.
## Before we get started
Complete the following [activity](/microbit/lessons/game-counter/activity) . Your code should look like this:
```blocks
input.onButtonPressed(Button.A, () => {
game.addScore(1);
basic.showNumber(game.score())
});
```
### Challenge 1
### @video td/videos/counter-1-2
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 micro:bit is shaken. You will need to register an event handler with `on shake`.

View File

@ -0,0 +1,77 @@
# game of chance blocks lesson
create an answering machine on the BBC micro:bit #docs
## Topic
Game Library
## Quick Links
* [activity](/microbit/lessons/game-of-chance/activity)
* [challenges](/microbit/lessons/game-of-chance/challenges)
## Class
Year 7
## 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
* **game library** : [read more...](/microbit/js/game-library)
* **show string** : [read more...](/microbit/reference/basic/show-string)
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
## 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
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
* Evaluates the appropriatness of digital devices, internet services and application software to achieve given goals (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/game-of-chance/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/game-of-chance/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/game-of-chance/challenges)

View File

@ -0,0 +1,16 @@
# game of chance blocks activity
Learn to create an answering machine on the micro:bit
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](/microbit/lessons/game-of-chance/challenges)!
### ~

View File

@ -0,0 +1,48 @@
# game of chance challenges
Coding challenges for the answering machine tutorial.
## Before we get started
Complete the [game of chance](/microbit/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 micro:bit'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

@ -0,0 +1,85 @@
# glowing pendulum blocks lesson
construct a pendulum that glows using acceleration #var #acceleration #abs #brightness #plot #docs
## Topic
Acceleration
## Quick Links
* [activity](/microbit/lessons/glowing-pendulum/activity)
* [challenges](/microbit/lessons/glowing-pendulum/challenges)
## Class
Year 7
## 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
* **forever** : [read more...](/microbit/reference/basic/forever)
* **local variable** : [read more...](/microbit/reference/variables/var)
* **acceleration** : [read more...](/microbit/reference/input/acceleration)
* **absolute value** : [read more...](/microbit/js/math)
* **set brightness** : [read more...](/microbit/reference/led/set-brightness)
* **show LEDs** : [read more...](/microbit/reference/basic/show-leds)
## 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
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Understands the difference between data and information(AB)
* Uses filters or can perform single criteria searches for information.(AL)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/glowing-pendulum/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/glowing-pendulum/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/glowing-pendulum/challenges)

View File

@ -0,0 +1,57 @@
# glowing pendulum block activity
Construct a pendulum that glows using acceleration.
To create a new script, go to the [Create Code](/microbit/create-code) page and tap `New Project` under `Block Editor`.
Welcome! This activity will teach how to construct a pendulum that glows using acceleration. Let's get started!
Create a **forever** loop that will constantly display the appropriate brightness on the LED display.
```blocks
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.
![](/static/mb/blocks/lessons/glowing-pendulum-1.png)
```blocks
basic.forever(() => {
let acceleration = input.acceleration(Dimension.Y);
});
```
Since the micro:bit 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.
![](/static/mb/blocks/lessons/glowing-pendulum-2.png)
```blocks
let acceleration = 0;
basic.forever(() => {
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 micro:bit, 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.
![](/static/mb/blocks/lessons/glowing-pendulum-3.png)
Now let's use our acceleration value to set the brightness on the micro:bit.
![](/static/mb/blocks/lessons/glowing-pendulum-4.png)
Let's show what the brightness of the micro:bit is by turning all the LEDs on!
![](/static/mb/blocks/lessons/glowing-pendulum-5.png)
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/glowing-pendulum/challenges)!
### ~

View File

@ -0,0 +1,20 @@
# glowing pendulum blocks challenges
Coding challenges for the glowing pendulum tutorial.
## Before we get started
Complete the following [glowing pendulum activity](/microbit/lessons/glowing-pendulum/activity) and your code should look like this:
![](/static/mb/blocks/lessons/glowing-pendulum-5.png)
**Challenge 1**
![](/static/mb/lessons/glowing-pendulum-0.jpg)
Hold the micro:bit in your hand in a dark room. Move the micro:bit like a pendulum and produce a slow image that captures the pattern of the micro:bit LEDs.
**Challenge 2**
Replace "y" in `acceleration(y)` with "x" or "z". Changing the axis will cause the micro:bit to measure the force in a different direction. What differences in the resulting pattern does this replacement make?

View File

@ -0,0 +1,97 @@
# glowing sword blocks lesson
make a glowing sword #image #docs
### @video td/videos/glowing-sword-0
## Topic
Fade Out
## Quick Links
* [activity](/microbit/lessons/glowing-sword/activity)
* [quiz](/microbit/lessons/glowing-sword/quiz)
* [quiz answers](/microbit/lessons/glowing-sword/quiz-answers)
* [challenges](/microbit/lessons/glowing-sword/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to manipulate an image through **fade out**, `fade out` to gradually decrease the LED screen brightness until the LED lights are turned off. We will be learning how to fade an image using simple commands, such as image create image, image show image, LED fade out, basic pause, and fade in.
## What the teacher needs to know/QuickStart Computing Glossary
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
* Computational thinking: Thinking about systems or problems in a way that allows computer systems to be used to model or solve these.
* Hardware: The physical systems and components of digital devices; see also software.
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
* Sequence: To place program instructions in order, with each executed one after the other.
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
## Documentation
* **create image** : [read more...](/microbit/reference/images/create-image)
* **show image** : [read more...](/microbit/reference/images/show-image)
* **fade out** : [read more...](/microbit/reference/led/fade-out)
* **pause** : [read more...](/microbit/reference/basic/pause)
* **fade in** : [read more...](/microbit/reference/led/fade-in)
## Resources
* Activity: [activity](/microbit/lessons/glowing-sword/activity)
* Activity: [quiz](/microbit/lessons/glowing-sword/quiz)
* Extended Activity: [challenges](/microbit/lessons/glowing-sword/challenges)
## Objectives
* learn how to plot an image
* learn how to gradually decrease the LED screen brightness until the LED lights are turned off
* pause your code for the specified number of milliseconds
* learn how to gradually increase the LED screen brightness until the LED lights are turned on
## Links to the National Curriculum Programmes of Study for Computing
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/glowing-sword/activity)
* [quiz](/microbit/lessons/lucky-7/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/glowing-sword/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/glowing-sword/challenges)
## Intended follow on
Publish script to the classroom.

64
docs/lessons/graphics.md Normal file
View File

@ -0,0 +1,64 @@
# blocks - rendering graphics
An introduction to graphics for the Block Editor. #docs
## Before we get started
Ensure you have completed the 'Hello, world!' and Loop tutorials and tested them on a simulator or on BBC micro:bit.
![](/static/mb/blocks/lessons/blocks-conditions-0.png)
The BBC micro:bit 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 BBC micro:bit.
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.
![](/static/mb/blocks/lessons/graphics-1.png)
We can also use the `clear screen` 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 BBC micro:bit using an algorithm. For example, we could draw a straight line with this code:
![](/static/mb/blocks/lessons/graphics-2.png)
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**. Your code should look like this; as our variable increases, so does the location that the BBC micro:bit is plotting at:
![](/static/mb/blocks/lessons/graphics-3.png)
We can create more complex algorithms for more complex shapes, too. See the [challenges](/microbit/lessons/challenges) section for additional graphical challenges and solutions.
### Animations
Animations are changes happening at a certain rate. For example, we could add the `delay` 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 BBC micro:bit display an explosion or fireworks.
See the [challenges](/microbit/lessons/challenges) section for some animation tasks.
### 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

@ -0,0 +1,79 @@
# guess the number lesson
Learn to create a random number with input from button A. #input #screen #math #docs
### @video td/videos/guess-the-number-0
## Topic
Math - Pick Random
## Quick links
* [activity](/microbit/lessons/guess-the-number/activity)
* [challenges](/microbit/lessons/guess-the-number/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to create numbers randomly by using the input of the BBC micro:bit. 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
* **on button pressed**: [read more...](/microbit/reference/input/on-button-pressed)
* **local variable **: [read more...](/microbit/reference/variables/var)
* **assignment operator**: [read more...](/microbit/reference/variables/assign)
* **show number**: [read more...](/microbit/reference/basic/show-number)
* **pick number**: [read more...](/microbit/blocks/math)
* **clear screen**: [read more...](/microbit/reference/basic/clear-screen)
## 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
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Understands that iteration is the repetition of a process such as a loop. (AL)
* Represents solutions using a structured notation. (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals. (AL)
* Declares and assigns variables.(AB)
#### Data & Data Representation
* Understands the difference between data and information. (AB)
* Defines data types: real numbers and Boolean. (AB)
#### Information Technology
* Collects, organises and presents data and information in digital content. (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/guess-the-number/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/guess-the-number/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/guess-the-number/challenges)

View File

@ -0,0 +1,48 @@
# guess the number activity
Guess the number with math random.
### ~avatar avatar
### @video td/videos/guess-the-number-0
Welcome! This tutorial will help you create a guess the number game! Let's get started!
### ~
Add an event handler when button `A` is pressed.
```blocks
input.onButtonPressed(Button.A, () => {
})
```
Create a local variable of type number `x` and set it to a random number using `pick random`. `pick random` 9 generates a random number between `0` and `09`.
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.random(9)
})
```
Show the random number on the screen.
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.random(9)
basic.showNumber(x)
})
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/guess-the-number/challenges)!
### ~

View File

@ -0,0 +1,35 @@
# guess the number challenges
Coding challenges for the guess the number tutorial.
## Before we get started
Complete the following [guided tutorial](/microbit/lessons/guess-the-number/activity), and your code should look like this:
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.random(9)
basic.showNumber(x)
})
```
### Challenge 1
### @video td/videos/guess-the-number-2
When button `B` is pressed, we want to clear the screen. This will make it so users can play your game over and over again! Add an event handler to handle this case.
```blocks
input.onButtonPressed(Button.A, () => {
let x = Math.random(9)
basic.showNumber(x)
})
input.onButtonPressed(Button.B, () => {
basic.clearScreen()
})
```
### Challenge 2
Show an animation when you clear the screen! Choose what animation makes most sense to you. Be creative!

View File

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

View File

@ -0,0 +1,56 @@
# hack your headphones activity
Hack your headphones
# micro:bit music
![](/static/mb/lessons/hack-your-headphones-0.png)
In this project, you will build your own music player micro:bit from headphones. Project duration: 15 minutes.
## Materials
* micro:bit, battery holder and 2 AAA batteries
* Headphones
* Crocodile clips
## Steps
### Step 1
![](/static/mb/lessons/banana-keyboard-1.png)
Using the 1st crocodile clip, connect the end of the crocodile clip onto GND pin on the micro:bit.
### Step 2
![](/static/mb/lessons/banana-keyboard-2.png)
![](/static/mb/lessons/banana-keyboard-3.png)
Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 0 pin on the micro:bit.
### Step 3
![](/static/mb/lessons/banana-keyboard-4.png)
Using the 1st crocodile clip, connect the second end of the crocodile clip onto based of the headphone jack. The base of your headphone jack is considered the ground so it is connected to the GND of the micro:bit.
### Step 4
![](/static/mb/lessons/banana-keyboard-5.png)
![](/static/mb/lessons/hack-your-headphones-1.png)
Using the 2nd crocodile clip, connect the second end of the crocodile clip onto the tip of the headphone jack. The tip of your headphone jack feeds into the right speaker on the headphone. You connect from the micro:bit pin 0 to the tip of the right side of your headphone. Use the tip of the headphone jack to play sounds.
### Step 5
![](/static/mb/lessons/hack-your-headphones-0.png)
You hacked your headphones!
### Step 6
Connect your micro:bit to your computer using your USB cable and program [light beatbox](/microbit/lessons/light-beatbox/activity) music on it. Press the reset button to restart your music player!

View File

@ -0,0 +1,75 @@
# happy birthday blocks lesson
display beautiful images on the BBC micro:bit #var #pause #docs
## Topic
Music
## Quick Links
* [activity](/microbit/lessons/happy-birthday/activity)
* [challenges](/microbit/lessons/happy-birthday/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, earphones (or speakers), as well as crocodile clips (or spring clips). We will be learning how to code musical notes using simple commands such as play, keys, and notes.
## What the teacher needs to know / QuickStart Computing Glossary
* Hardware: The physical systems and components of digital devices; see also software.
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
## Resources
* Activity: [activity](/microbit/lessons/happy-birthday/activity)
* Extended Activity: [challenges](/microbit/lessons/happy-birthday/challenges)
## Objectives
* learn how to code music on the BBC micro:bit
* learn how to setup the BBC micro:bit as a music player
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/happy-birthday/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/happy-birthday/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/happy-birthday/challenges)

View File

@ -0,0 +1,58 @@
# happy birthday blocks activity
Play sounds with music blocks.
To create a new script, go to the [Create Code](/microbit/create-code) page and tap `New Project` under `Block Editor`.
Have you ever tried to play a song on an instrument? Let's try coding the song "Happy Birthday" on the micro:bit !
Let's start by adding the code in the music drawer that includes a single musical chord (or pitched sound) with the `play` block. Then insert the chord "C". Once you are done coding, don't forget to run your code in the simulator or the micro:bit.
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
```
* click run to see if the code works as expected.
We want to continue to adding musical chords with the `play` block. So insert the appropriate chord blocks: `D`, `F`, `G` to complete the first part of the song. Modify your code so that your code looks like this.
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
basic.pause(100);
```
* click run to see if the code works as expected.
We want to continue to adding musical chords with the `play` block. Then insert the appropriate chords: `B`, `C`, `D`, `E` , `F` to complete the second part of the song. Modify your code so that your code looks like this.
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
basic.pause(100);
```
* click run to see if the code works as expected.
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/microbit/lessons/happy-birthday/challenges)!
### ~

View File

@ -0,0 +1,106 @@
# happy birthday blocks challenges
Coding challenges for finishing the song, happy birthday.
## Before we get started
Complete the [happy birthday](/microbit/lessons/happy-birthday/activity) activity and your code will look like this:
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
basic.pause(100);
```
### ~
### Challenge 1
Let's code the third part of Happy Birthday!
To do this, you need to add blocks after the last line of the `play` blocks. We want to continue to adding musical chords with the `play` block. Then insert the appropriate chord blocks `G`, `E`, `C`, `B`, `A` to complete the third part of the song. Modify your code so that your code looks like this.
``` blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
basic.pause(100);
```
* click *run * to see if the code works as expected.
### Challenge 2
Finally, we continue to adding the appropriate `play` block and fit the following chords blocks `F`, `E`, `C`, `D` to complete the third part of the song. Modify your code so that your code looks like this.
```blocks
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.C), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.E), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.D), music.beat(BeatFraction.Quater));
basic.pause(100);
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.A), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.B), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.G), music.beat(BeatFraction.Quater));
music.playTone(music.noteFrequency(Note.F), music.beat(BeatFraction.Quater));
```
* click *run * to see if the code works as expected.
### Challenge 3
You now have a the ability to create music on the micro:bit. Try to code another favourite song.

7
docs/lessons/hero.md Normal file
View File

@ -0,0 +1,7 @@
# hero
make a game to test hand-eye coordination #docs #functions #var
Make a game to test hand-eye coordination
* [activity](/microbit/lessons/hero/activity)

View File

@ -0,0 +1,74 @@
# hero
A classic game, Hero, in which you must capture the food and flee away from the ghost!
### ~avatar avatar
This tutorial will teach you how to create a hero game to capture food while dodging the ghost; the game was inspired by the classic arcade game Pac Man.
### ~
First we need to create a function create sprite at the x, y coordinates and that set the variable called hero on the micro:bit the first time we play.
![](/static/mb/blocks/lessons/hero-0.png)
Let's set up where we want our ghost will be. Create starting positions of the hero, ghost, and food in each individual quadrant. We will ensure that the ghost, food, and hero is set apart. Divide the micro:bit into 4 quadrants. We don't want hero to be too close to the ghost so let's make the ghost starting positions in the 3 other quadrants. Hero is in the one quadrant. To do this, we need to keep track of the middle point in each quadrant. Create sprite at the x, y coordinates for the hero, food, and ghost.
![](/static/mb/blocks/lessons/hero-1.png)
Create a function called change blink that will plot a blinking point so the player can tell between a ghost and hero.
![](/static/mb/blocks/lessons/hero-2.png)
We want to identify the food so the player moves towards the food. We need to set the `brightness` of the `variable` food to 8. The brightness of the LED screen is expressed as a number between 0 and 255.
![](/static/mb/blocks/lessons/hero-3.png)
We want to include a block from the Loops drawer called `While`. Then set the `While` loop to `true`. This code will be important for repeating code of the game logic of the game. The game will continue to run using `While` loop while the Boolean condition is true. Finally, include a `pause` of 400 milliseconds before the logic of the game begins.
![](/static/mb/blocks/lessons/hero-4.png)
Let's create a function that will take care of keep the ghost pursuing the hero. We will need to a conditional statement that checks the position of the ghost and hero. The first condition will check if the horizontal coordinates of the ghost is less than the horizontal coordinates of the hero. We create a function from the Game drawer that will check the coordinates of the hero and the ghost. Finally, change the x-direction of the ghost by 1.
Then create another function that will take care of keep the ghost pursuing the hero. We will need to a conditional statement that checks the position of the ghost and hero. The second condition will check if the horizontal coordinates of the ghost is greater than the x-direction of hero. We create a function from the Game drawer that will check the x-direction of hero and ghost. Finally, change the x-direction of the ghost by -1.
![](/static/mb/blocks/lessons/hero-5.png)
Let's create the third function and forth function that continues the same logic in the y-direction of pacman and ghost. We create a function from the Game drawer that will check the y-direction of pacman and ghost. Finally, change the y-direction of the ghost to continue following pacman.
![](/static/mb/blocks/lessons/hero-6.png)
Let's enable pacman to move in the x-direction and move in the y-direction with acceleration using the micor:bit sensor
![](/static/mb/blocks/lessons/hero-7.png)
**Do not disconnect the blocks for the conditional statements. We are focusing on this section of the code and are not showing the entire code**
Let's setup the logic for the food. If hero is `touching` "food", increase the score of the game by 1 and `set` ``x`` -direction of food randomly randomly from 0 to 4 and `set` ``y``-direction of food randomly from 0 to 4.
![](/static/mb/blocks/lessons/hero-8.jpg)
**Do not disconnect the blocks from the conditional statements. We are focusing on this section of the code and are not showing the entire code**
Let's setup the logic for the food and the ghost to be in different quadrants.
![](/static/mb/blocks/lessons/hero-9.jpg)
**Do not disconnect the blocks for the conditional statements. We are focusing on this section of the code and are not showing the entire code**
The game over component is now upon the game. If the hero is `touching` the ghost, let's display `game over`
![](/static/mb/blocks/lessons/hero-10.jpg)
**Do not disconnect the conditional statements blocks from the remaining blocks. We are focusing on this section of the code and are not showing the entire code**
The game can also use the buttons. Let's create a `while` loop for button A is pressed. If button A is pressed, the micro:bit will display the word Hero. Let's use a `while` loop for button B is pressed. If button B is pressed, the micro:bit will display image of the hero.
![](/static/mb/blocks/lessons/hero-11.jpg)
### ~avatar avatar
You can review the final code for [hero](/microbit/numraj)
### ~

View File

@ -0,0 +1,39 @@
# light beatbox
display beautiful images on the BBC micro:bit #var #pause #docs
## Topic
Music
## Quick Links
* [activity](/microbit/lessons/light-beatbox/activity)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to make a light beatbox music player using the light sensor. We will be learning how to code musical notes using light level, a local variable, conditionals, on button pressed as well as simple commands such as ring tone and rest.
## Objectives
* learn how to control the light sensor on the BBC micro:bit
* learn how to code music on the BBC micro:bit
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation

View File

@ -0,0 +1,36 @@
# light beatbox activity
Control sound with the light level.
### ~avatar avatar
Have you ever tried to making beat box sounds based on the light level? Let's try making a beatbox with code!
### ~
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
Let's start by adding a variable where you can store data. Then rename the variable to "light". Then set the value of the variable to the block `light level` from the Input drawer. This will gets the `light level` from 0 (dark) to 255 (bright). The light is measured by using various LEDs from the screen. Modify your code so that your code looks like this.
![](/static/mb/blocks/lessons/light-beatbox-0.png)
We want to play music on button pressed in order to register an event handler that will execute whenever when you run a script and click on button pressed on the simulator. We must start by opening the Input drawer and adding `on button pressed` A. Then add a block `rest` to plays nothing for a `1/16` beat. Modify your code so that your code looks like this.
![](/static/mb/blocks/lessons/light-beatbox-1.png)
We click on the Logic drawer then insert a `if do` that will conditionally run code depending on whether the Boolean condition is true or false. Click on the Logic drawer. Then we want to add additional conditional statements by clicking on the gear to the left of the `if`. Add 05 `else if` and 01 `else` inside the `if do` block structure. Modify your code so that your code looks like this
![](/static/mb/blocks/lessons/light-beatbox-2.png)
We click on the Logic drawer then insert a `less than` sign into the first `if` conditional that will conditionally run code depending on whether the Boolean condition is true or false. Then insert the variable `light` into the first part of the inequality. The variable "light" will appear in the Variables drawer. Finally, we insert 25. If the `light level` is `less than` 25, play `ring tone` ``C``. Continue this logic to continue with these conditional statements. If the `light level` is `less than` 50, play `ring tone` ``D``. If the `light level` is `less than` 100, play `ring tone` ``E``. If the `light level` is `less than` 150, play `ring tone` ``F`` If the `light level` is `less than` 180, play `ring tone` ``G``. If none of these conditions are true, `ring tone` ``A``.
![](/static/mb/blocks/lessons/light-beatbox-3.png)
* click *compile* and run your code on the micro:bit.
### ~avatar avatar
Excellent, you're ready to continue by connecting your headphones with these [challenges](/microbit/lessons/hack-your-headphones/activity)!
### ~

77
docs/lessons/looper.md Normal file
View File

@ -0,0 +1,77 @@
# looper blocks lesson
Learn to control blinking LEDs. #LED #screen #for #docs
### @video td/videos/looper-0
## Topic
For Loop
## Quick links
* [activity](/microbit/lessons/looper/activity)
* [challenges](/microbit/lessons/looper/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to control a blinking LED. We will be learning how to create a blinking app using the for loop as well as simple commands, such as plot and pause.
## Documentation
* **for**: [read more...](/microbit/reference/loops/for)
* **show number**: [read more...](/microbit/reference/basic/show-number)
* **pause**: [read more...](/microbit/reference/basic/pause)
* **arithmetic operators**: [read more...](/microbit/reference/types/number)
## Objectives
* learn how to repeat code a fixed number of times
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)
* learn how to pause program execution for the specified number of milliseconds
* learn how to arithmetic operators operate on numbers and return a number
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses logical reasoning to predict outputs, showing an awareness of inputs. (AL)
* Understands that iteration is the repetition of a process such as a loop. (AL)
* Represents solutions using a structured notation. (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals. (AL)
* Uses a variable and relational operators within a loop to govern termination. (AL) (GE)
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
#### Data & Data Representation
* Understands the difference between data and information. (AB)
* Defines data types: real numbers and Boolean. (AB)
#### Information Technology
* Collects, organises and presents data and information in digital content. (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 10 min.
* [activity](/microbit/lessons/looper/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/looper/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/looper/challenges)

View File

@ -0,0 +1,44 @@
# looper blocks activity
Display a series of numbers with a for loop.
### ~avatar avatar
### @video td/videos/looper-0
### ~
Welcome! This activity will teach how to display a series of numbers for a for loop. Let's get started!
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `5` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 5`.
```blocks
for (let i = 0; i < 6; i++) {
}
```
We will show the number of times the loop has been executed. It will go from zero to five times.
```blocks
for (let i = 0; i < 6; i++) {
basic.showNumber(i)
}
```
The for loop while cycle through to six immediately unless we pause for a little bit in between each loop.
```blocks
for (let i = 0; i < 6; i++) {
basic.showNumber(i)
basic.pause(2000)
}
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/looper/challenges)!
### ~

View File

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

59
docs/lessons/loops.md Normal file
View File

@ -0,0 +1,59 @@
# blocks - loops
An introduction to Loops for the Block Editor. #docs
We may want to handle the users input multiple times or remain waiting for their input for a long time. We use loops to make sure that our code runs multiple times. These can be found in the **Loops** drawer.
### Forever loops
In the Variables tutorial we utilised a forever loop to create a counter:
![](/static/mb/blocks/lessons/blocks-conditions-2.png)
This allows our BBC micro:bit to wait for the user to do something forever, for example wait for the user to press the correct button as the example above shows. If you were creating a quiz, you may want to loop forever until the user presses the correct button or answers the question.
### Repeat Loops
Repeat loops allow code to happen a certain amount of times. You may want to create a quiz that only gives the user a few tries to get the correct answer, for example. The number can be changed to facilitate your code.
![](/static/mb/blocks/lessons/loops-0.png)
The code above will scroll the message, “Hello world” three times.
### While & Until loops
The repeat while loop allows you to continue looping some code until a condition is met. The empty socket next to the while loop allows you to connect some Logic and construct a statement.
![](/static/mb/blocks/lessons/loops-1.png)
The code above will scroll the message, “Press it!”, while the user hasnt pressed the button.
* Drag a `set item` block from the **Variables** drawer. Click the **down arrow** and click **New Variable**, and type "pressed". Drag a `0` block from **Maths** to set the variable **pressed** to 0.
* Drag a `repeat while` block from the **Loops** drawer and attach an `=` block from the **Logic** drawer. Drag `item` from the **Variables** drawer and click the **down arrow**, select pressed. Drag a `0` block from Maths and connect it to the other side of the equals. This will carry out the code until pressed does not equal 0.
* Add a `show string` block from the **Basic** drawer and change the message to "Press it!"
* Add an `if` block from the **Logic** drawer, connect a `button pressed` block from the **Input** drawer, and add text from the **Basic** drawer. Change this to A to show we are waiting for button A.
* Inside the do part of the if statement, add a `set` block from the Variables drawer, click the **down arrow** to change it to **pressed** and drag a `1` from the Maths drawer
* Lastly underneath the while loop, add another `show string` block and fill in the gaps.
Test the code above on actual hardware or on the simulator window.
We can also change the code in subtle ways to have a completely different effect:
![](/static/mb/blocks/lessons/loops-2.png)
This time we have to press the button three times to leave the while loop.
## Tip
You can press the arrow next to a word in a block to change it. For example, you can change Math functions or change a Logic statement.
### Count or for loops
A count loop allows you to loop a certain amount of times and to change a variable as you do so. For example, we can create a simple counting program:
![](/static/mb/blocks/lessons/loops-3.png)
The count loop will repeat a certain amount of times whilst changing a variable. You can click the arrow next to **i** to replace it with any of your own variables. So this program will display numbers 1 to 10.
This loop allows you to repeat code for the amount of times you want to without worrying about manually changing variables. You could use this for a counting program or a timer.

117
docs/lessons/love-meter.md Normal file
View File

@ -0,0 +1,117 @@
# love meter blocks lesson
create a love meter with the BBC micro:bit #pin #pressed #string #if #var #pause #show #docs
### @video td/videos/love-meter-0
## Topic
On Pin Pressed
## Quick Links
* [activity](/microbit/lessons/love-meter/activity)
* [quiz](/microbit/lessons/love-meter/quiz)
* [quiz answers](/microbit/lessons/love-meter/quiz-answers)
* [challenges](/microbit/lessons/love-meter/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to use the **pin pressed**, `on pin pressed` to run code when the user holds the GND pin with one hand, and presses pin 0 with the other hand, thus completing a circuit. We will be learning how to create a love meter using input on pin pressed, a local variable, math random, If (conditional) as well as simple commands, such as show number, pause, and show string.
## What the teacher needs to know/QuickStart Computing Glossary
* Hardware: The physical systems and components of digital devices; see also software.
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the users name.
## Documentation
* **on pin pressed** : [read more...](/microbit/reference/input/on-pin-pressed)
* **local variable** : [read more...](/microbit/reference/variables/var)
* **Boolean** : [read more...](/microbit/reference/types/boolean)
* **math random** : [read more...](/microbit/js/math)
* **show number** : [read more...](/microbit/reference/basic/show-number)
* **pause** : [read more...](/microbit/reference/basic/pause)
* **If** : [read more...](/microbit/reference/logic/if)
* **show string** : [read more...](/microbit/reference/basic/show-string)
## Resources
* Activity: [activity](/microbit/lessons/love-meter/activity)
* Activity: [quiz](/microbit/lessons/love-meter/quiz)
* Extended Activity: [challenges](/microbit/lessons/love-meter/challenges)
## Objectives
* learn how to run code when the user holds the GND pin in one hand, and presses pin 0 with the other hand, thus completing a circuit; when you run a script with this function in a web browser, click pin 0 on the simulator
* learn how to a create a variable for a place where you can store and retrieve data
* learn how Boolean operators take Boolean inputs and evaluates to a Boolean output
* learn how to return a random number
* learn how to show a number on the LED screen
* learn how to pause your code for the specified number of milliseconds
* learn how to conditionally run code depending on whether a condition is true or not
* learn how to show a string on the LED screen one character at a time (scrolling from left to right)
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
* Uses diagrams to express solutions.(AB)
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Understands the difference between data and information(AB)
* Uses filters or can perform single criteria searches for information.(AL)
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
* Defines data types: real numbers and Boolean (AB)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Makes judgements about digital content when evaluating and repurposing it for a given audience (EV) (GE)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/love-meter/activity)
* [quiz](/microbit/lessons/love-meter/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/love-meter/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/love-meter/challenges)

View File

@ -0,0 +1,51 @@
# love meter blocks activity
Create a love meter with the micro:bit
### ~avatar avatar
### @video td/videos/love-meter-0
Welcome! This activity will help you create a love meter with the micro:bit. Let's get started!
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under *Block Editor*.
### ~
Begin by registering an event with `on pin pressed` *P0* to know when someone is holding pin *P0* and pin *Gnd*.
```blocks
input.onPinPressed(TouchPin.P0, () => {
})
```
We are going to create a meter that displays a random number from *0* to *10*. We use *10* as `random number up to` returns a number between *0* and *n*.
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.random(10)
})
```
Finally, let's show that number on the micro:bit. You are registering an event handler that will execute on the BBC micro:bit whenever the user holds the GND pin with one hand, and presses pin 0 with the other hand, thus completing a circuit
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.random(10)
basic.showNumber(x)
})
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/love-meter/challenges)
### ~

View File

@ -0,0 +1,71 @@
# love meter blocks challenges
Create a love meter with the micro:bit
## Before we get started
You should work on these challenges after the following the [love meter activity](/microbit/lessons/love-meter/activity)
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.random(10)
basic.showNumber(x)
})
```
### Challenge 1
Add a pause of 3000 milliseconds (3 seconds) after showing the number so that the number won't immediately disappear in the next challenge.
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.random(10)
basic.showNumber(x)
basic.pause(3000)
})
```
### Challenge 2
If the rating **x** is between *0* and *3* (strictly less than *4*), display the text "HORRIBLE!".
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.random(10)
basic.showNumber(x)
basic.pause(3000)
if (x < 4) {
basic.showString("HORRIBLE")
}
})
```
### Challenge 3
### @video td/videos/love-meter-3
**If** the rating is between 4 and 7, display the text "MEDIOCRE!" **else** display the text "MATCHED!"
```blocks
input.onPinPressed(TouchPin.P0, () => {
let x = Math.random(10)
basic.showNumber(x)
basic.pause(3000)
if (x < 4) {
basic.showString("HORRIBLE")
} else if (x < 8) {
basic.showString("MEDIOCRE")
} else {
basic.showString("MATCHED")
}
})
```
### Challenge 4
Use `show LEDs` to display images instead of text for each case.

View File

@ -0,0 +1,40 @@
# love meter blocks quiz answers
The answers to the love meter quiz.
This is the answer key for the [love meter quiz](/microbit/lessons/love-meter/quiz).
## 1. What does `on pin pressed(P0)` do?
<br/>
It's a method that runs code when the user holds the GND pin with a finger of one hand and presses pin P0, completing a circuit.
## 2. Write the code.
Create a condition for `on pin pressed (P0)`.
![](/static/mb/blocks/lessons/love-meter-0.jpg)
## 3. What does this line of code doing?
![](/static/mb/blocks/lessons/love-meter-6.png)
<br/>
It stores random number between 0 and 9 then stores that number in a variable.
## 4. Why do you have to add 1 to variable x?
![](/static/mb/blocks/lessons/love-meter-7.png)
<br/>
You have to add 1 if you want to generate a random number between 1 and 10 .
## 5. Why do you have to hold ground (GND) to make this work on the micro:bit?
<br/>
You have told GND to complete the circuit.

View File

@ -0,0 +1,36 @@
# love meter blocks quiz
Learn how to make a love meter that you can try with someone.
## Name
## Directions
Use this activity document to guide your work in the [love meter activity](/microbit/lessons/love-meter/activity).
Answer the questions below while completing the activity. Pay attention to the dialogues!
## 1. Describe what `on pin pressed` does?
<br/>
## 2. Create a condition for on pin pressed (P0).
<br/>
## 3. Describe what this line of code does?
![](/static/mb/blocks/lessons/love-meter-6.png)
<br/>
## 4. Describe what adding 1 to variable x does?
![](/static/mb/blocks/lessons/love-meter-7.png)
<br/>
## 5. Describe why you must hold ground (GND) before pressing (P0) to run a program using `on pin pressed(P0)` on the micro:bit
<br/>

93
docs/lessons/lucky-7.md Normal file
View File

@ -0,0 +1,93 @@
# lucky 7 blocks lesson
show a number on the LED screen #show #number #docs
### @video td/videos/lucky-7-0
## Topic
Show Number
## Quick Links
* [activity](/microbit/lessons/lucky-7/activity)
* [quiz](/microbit/lessons/lucky-7/quiz)
* [quiz answers](/microbit/lessons/lucky-7/quiz-answers)
* [challenges](/microbit/lessons/lucky-7/challenges)
## Class
Year 7
## Prior learning / place of lesson in scheme of work
Learn how to display a number, `show number` to generate numbers. We will be learning how to create numbers using show number as well as simple commands, such as pause.
## What the teacher needs to know / QuickStart Computing Glossary
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
## Documentation
* **show number** : [read more...](/microbit/reference/basic/show-number)
* **pause** : [read more...](/microbit/reference/basic/pause)
## Resources
* Activity: [activity](/microbit/lessons/lucky-7/activity)
* Activity: [quiz](/microbit/lessons/lucky-7/quiz)
* Extended Activity: [challenges](/microbit/lessons/lucky-7/challenges)
## Objectives
* learn how to show a number on the LED screen, one digit at a time
* learn how to pause program execution for the specified number of milliseconds
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB)
* Understands that iteration is the repetition of a process such as a loop (AL)
* Recognises that different algorithms exist for the same problem (AL) (GE)
* Represents solutions using a structured notation (AL) (AB)
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Defines data types: real numbers and Boolean (AB)
#### Hardware & Processing
* Understands the difference between hardware and application software, and their roles within a computer system (AB)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/lucky-7/activity)
* [quiz](/microbit/lessons/lucky-7/quiz)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/lucky-7/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/lucky-7/challenges)

View File

@ -0,0 +1,26 @@
# lucky 7 blocks activity
Show a number on the LED screen.
### ~avatar avatar
### @video td/videos/lucky-7-0
Let's learn how to show the lucky number 7 on the LED screen.
### ~
To create a new script, go to the [Create Code](https://www.microbit.co.uk/create-code) page and tap `New Project` under **Block Editor**.
We will use `show number` to display a number on the screen. The argument (`7`) is the number to display.
```blocks
basic.showNumber(7)
```
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/microbit/lessons/lucky-7/challenges)!
### ~

View File

@ -0,0 +1,39 @@
# lucky 7 blocks challenges
Coding challenges for lucky 7.
## Before we get started
Complete the [lucky 7 activity](/microbit/lessons/lucky-7/activity) and your code will look like this:
```blocks
basic.showNumber(7)
```
### Challenge 1
But we also should pause before showing another number. Let's add a pause of 500 milliseconds.
```blocks
basic.showNumber(7)
basic.pause(500)
```
### Challenge 2
### @video td/videos/lucky-7-1-2
What about other multiples of 7? Let's display the next multiple of 7 on the screen!
```blocks
basic.showNumber(7)
basic.pause(500)
basic.showNumber(14)
```
* Run the code to see if it works as expected.
### Challenge 3
Keep displaying multiples of 7 such as 21 and 28, but don't forget to add pauses between the numbers!

View File

@ -0,0 +1,32 @@
# lucky 7 blocks quiz answers
Show a number on the micro:bit.
This is the answer key for the [lucky 7 quiz](/microbit/lessons/lucky-7/quiz).
## 1. Describe what `show number` does?
Answers may vary. This will show a number on the LED screen, one digit at a time (scrolling from left to right).
## 2. Draw every LED that is ON after running this code
![](/static/mb/blocks/lessons/lucky-7-3.png)
<br/>
![](/static/mb/lessons/lucky-7-0.png)
## 3. Draw every LED that is ON after running this code
![](/static/mb/blocks/lessons/lucky-7-4.png)
![](/static/mb/lessons/lucky-7-1.png)
## 4. Write the code that will be used to display the number 3 on the micro:bit.
![](/static/mb/lessons/lucky-7-2.png)
![](/static/mb/blocks/lessons/lucky-7-5.png)
<br/>

View File

@ -0,0 +1,40 @@
# lucky 7 blocks quiz
Show a number on the micro:bit
## Name
## Directions
Use this activity document to guide your work in the [lucky 7 activity](/microbit/lessons/lucky-7/activity).
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Describe what "show number" does?
<br/>
## 2. Draw every LED that is ON after running this code
![](/static/mb/blocks/lessons/lucky-7-3.png)
![](/static/mb/empty-microbit.png)
<br/>
## 3. Draw every LED that is ON after running this code
![](/static/mb/blocks/lessons/lucky-7-4.png)
![](/static/mb/lessons/answering-machine-4.png)
<br/>
## 4. Write the code that will be used to display the number 3 on the micro:bit.
![](/static/mb/lessons/lucky-7-3.png)
<br/>
<br/>

95
docs/lessons/magic-8.md Normal file
View File

@ -0,0 +1,95 @@
# magic 8 lesson
a fortune teller game with the BBC micro:bit #string #shake #clear-screen #if #string #number #var #docs
## Topic
If (Conditionals)
## Quick Links
* [activity](/microbit/lessons/magic-8/activity)
* [challenges](/microbit/lessons/magic-8/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to creating **conditionals**, `if condition do` to conditionally run code depending on whether a condition is true or not. We will be learning how to create a fortune telling app using local variable and conditionals (If), input on shake as well as simple commands, such as show string, show number, and clear screen.
## Documentation
* **show string** : [read more...](/microbit/reference/basic/show-string)
* **show number** : [read more...](/microbit/reference/basic/show-number)
* **on shake** : [read more...](/microbit/reference/input/on-gesture)
* **clear screen** : [read more...](/microbit/reference/basic/clear-screen)
* **variable** : [read more...](/microbit/reference/variables/var)
* **pick number** : [read more...](/microbit/blocks/math)
* **if** : [read more...](/microbit/reference/logic/if)
## Objectives
* learn how to show a string on the LED screen
* learn how to show a number on the LED screen
* learn how to learn how to turn off all the LED lights on the LED screen
* learn how to use the input on shake
* learn how to learn how to create a local variable to store data so that you can use it later in your code
* learn how to learn how to return a random number
* learn how to learn how to conditionally run code depending on whether a condition is true or not
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
* Uses diagrams to express solutions.(AB)
* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL)
* Represents solutions using a structured notation (AL) (AB)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Declares and assigns variables(AB)
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
* Selects the appropriate data types(AL) (AB
#### Data & Data Representation
* Understands the difference between data and information(AB)
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
* Defines data types: real numbers and Boolean (AB)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/magic-8/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/magic-8/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/magic-8/challenges)

View File

@ -0,0 +1,128 @@
# magic 8 activity
A fortune teller game on the micro:bit
Welcome! This tutorial will help you create a magic 8 ball on the micro:bit. Let's get started!
Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer true or false questions.
```blocks
basic.showString("ASK A QUESTION")
```
Display the number 8.
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
```
Create a condition for when the micro:bit is shaken. Then use the block `clear screen` to clear the 8 from the display.
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
});
```
Create a variable of type number called **randomNumber**. Set **randomNumber** to a random number with a limit of 2. Remember the random function in the math library, picks a random number from 0 to the limit, but not including the limit unless it is 0.
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(2)
});
```
Create an if statement for the condition `if randomNumber = 2`. If **randomNumber** is 2, display the string 'Yes'
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen();
let randomNumber = Math.random(2);
if (randomNumber == 2) {
basic.showString("YES");
}
});
```
Create an if statement for the condition `if randomNumber = 1`. If randomNumber is 1, display the string 'No'
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(2)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
}
})
```
If **randomNumber** is not 2 or 1, it must be 0. This is the else condition. If **randomNumber** is 0, display the string 'I don't know'
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(2)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
} else {
basic.showString("I DON'T KNOW")
}
})
```
Display the number 8 so users know they can ask the magic 8 ball another question!
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(2)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
} else {
basic.showString("I DON'T KNOW")
}
basic.showNumber(8)
})
```
### ~avatar avatar
Excellent, you're ready to continue with the [challenges](/microbit/lessons/magic-8/challenges)!
### ~

View File

@ -0,0 +1,105 @@
# magic 8 challenges
Coding challenges for the magic 8 tutorial
## Before we get started
Complete the following [guided tutorial](/microbit/lessons/magic-8/activity), and your code should look like this:
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(2)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
} else {
basic.showString("I DON'T KNOW")
}
basic.showNumber(8)
})
```
**Challenge 1**
Now let's increase the number of responses the magic 8 ball can give. How about 5 responses instead? Let's change the limit of `pick random` to 4.
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(4)
if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
} else {
basic.showString("I DON'T KNOW")
}
basic.showNumber(8)
})
```
**Challenge 2**
Now have the magic 8 ball respond "Try again" if **randomNumber** is 3.
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(4)
if (randomNumber == 3) {
basic.showString("TRY AGAIN")
} else if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
} else {
basic.showString("I DON'T KNOW")
}
basic.showNumber(8)
})
```
**Challenge 3**
Now what about if **randomNumber** is 4? Let's have the magic 8 ball respond "Definitely!".
```blocks
basic.showString("ASK A QUESTION")
basic.showNumber(8)
input.onGesture(Gesture.Shake, () => {
basic.clearScreen()
let randomNumber = Math.random(4)
if (randomNumber == 4) {
basic.showString("DEFINATELY")
} else if (randomNumber == 3) {
basic.showString("TRY AGAIN")
} else if (randomNumber == 2) {
basic.showString("YES")
} else if (randomNumber == 1) {
basic.showString("NO")
}
else {
basic.showString("I DON'T KNOW")
}
basic.showNumber(8)
})
```
**Challenge 4**
Add 3 more responses so your magic 8 ball has 8 possible responses. Be creative!

View File

@ -0,0 +1,75 @@
# magic logo lesson
show an image that points up when the logo is up #logo #point #docs
### @video td/videos/magic-logo-0
## Topic
On Logo Up
## Quick Links
* [activity](/microbit/lessons/magic-logo/activity)
* [challenges](/microbit/lessons/magic-logo/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to plot image **on logo up**, `on logo up` to run code when the micro:bit screen is facing up and vertically orientated. We will be learning how to plot an image with the logo up, basic show LEDs, and logo down.
## Documentation
* **on logo up** : [read more...](/microbit/functions/on-logo-up)
* **show leds** : [read more...](/microbit/reference/basic/show-leds)
* **on logo down** : [read more...](/microbit/functions/on-logo-down)
## Objectives
* learn how to display an image on the micro:bit's LED screen
* learn how to run code when the micro:bit screen is facing down and vertically orientated
* learn how to run code when the micro:bit screen is facing up and vertically orientated
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Represents solutions using a structured notation (AL) (AB)
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
#### Hardware & Processing
* Knows that computers collect data from various input devices, including sensors and application software (AB)
#### Communication Networks
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Recognises the audience when designing and creating digital content (EV)
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/magic-logo/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/magic-logo/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/magic-logo/challenges)

View File

@ -0,0 +1,43 @@
# magic logo activity
Show an image that points up when the logo is up.
### ~avatar avatar
### @video td/videos/magic-logo-0
Welcome! This tutorial will help you display an arrow pointing toward the logo! Let's get started.
### ~
Using the **accelerometer** sensor, the micro:bit can detect when the **logo** is oriented **up**. We call that the **logo up** event. We will use `on logo up` to register an event handler that will run when the **logo up** event happens.
```blocks
input.onLogoUp(() => {
})
```
When the micro:bit goes logo up, the code nested under the `on logo up` function will run. Let's add a line of code to show LEDs in there.
```blocks
input.onLogoUp(() => {
basic.showAnimation(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
})
```
Run your code and try to turn around the micro:bit to see the **logo up** event in action!
### ~avatar boothing
Excellent, you're ready to continue with the [challenges](/microbit/lessons/magic-logo/challenges)!
### ~

View File

@ -0,0 +1,60 @@
# magic logo challenges
Coding challenges for magic logo.
## Before we get started
Complete the [magic logo](/microbit/lessons/magic-logo/activity) activity and your code will look like this:
```blocks
input.onLogoUp(() => {
basic.showAnimation(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
})
```
### Challenge 1
How about when the logo is down? We should display an arrow pointing downward!
### @video td/videos/magic-logo-1-2
```blocks
input.onLogoUp(() => {
basic.showAnimation(`
. . # . .
. # # # .
# # # # #
. . # . .
. . # . .
`)
})
input.onLogoDown(() => {
basic.showAnimation(`
. . # . .
. . # . .
# # # # #
. # # # .
. . # . .
`)
})
```
### Challenge 2
Use the `on screen up` event to show a spinning arrow when the screen is turned up.
### Challenge 3
Display another animation using the `on screen up` event.

View File

@ -0,0 +1,71 @@
# night light lesson
change the brightness of the BBC micro:bit #brightness #plot #docs
### @video td/videos/night-light-0
## Topic
Set Brightness
## Quick Links
* [activity](/microbit/lessons/night-light/activity)
* [challenges](/microbit/lessons/night-light/challenges)
## Class
Year 7
## Prior learning/place of lesson in scheme of work
Learn how to **set brightness** of an image `set brightness` to set the brightness of the LED screen. We will be learning how to set the brightness of the LED screen using LED show LEDs, on button pressed and set brightness.
## Documentation
* **set brightness** : [read more...](/microbit/reference/led/set-brightness)
* **show LEDs** : [read more...](/microbit/reference/basic/show-leds)
* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed)
## Objectives
* learn how to set the brightness of the LED screen
* learn how to run code when an input button is pressed
* learn how to turn on all LEDs
## Progression Pathways / Computational Thinking Framework
#### Algorithms
* Uses diagrams to express solutions.(AB)
* Recognises that different algorithms exist for the same problem (AL) (GE)
* Represents solutions using a structured notation (AL) (AB)
* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE)
#### Programming & Development
* Creates programs that implement algorithms to achieve given goals (AL)
* Selects the appropriate data types(AL) (AB
#### Information Technology
* Collects, organizes, and presents data and information in digital content (AB)
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
* Recognises ethical issues surrounding the application of information technology beyond school.
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
## Activity
* time: 20 min.
* [activity](/microbit/lessons/night-light/activity)
## Extended Activity
* time: 20 min.
* [challenges](/microbit/lessons/night-light/challenges)
## Homework
* Extended Activity: [challenges](/microbit/lessons/night-light/challenges)

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