diff --git a/docs/device.md b/docs/device.md new file mode 100644 index 00000000..7f4c1801 --- /dev/null +++ b/docs/device.md @@ -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 you’re 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 Earth’s 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:bit’s 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 doesn’t need another power source. When your micro:bit isn’t 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) + diff --git a/docs/device/contents.md b/docs/device/contents.md new file mode 100644 index 00000000..e1fd0f66 --- /dev/null +++ b/docs/device/contents.md @@ -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) diff --git a/docs/device/crocodile-clips.md b/docs/device/crocodile-clips.md new file mode 100644 index 00000000..631273d6 --- /dev/null +++ b/docs/device/crocodile-clips.md @@ -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) + diff --git a/docs/device/error-codes.md b/docs/device/error-codes.md new file mode 100644 index 00000000..564b9a53 --- /dev/null +++ b/docs/device/error-codes.md @@ -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) + diff --git a/docs/device/pins.md b/docs/device/pins.md new file mode 100644 index 00000000..e95bb5fd --- /dev/null +++ b/docs/device/pins.md @@ -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 can’t 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. + diff --git a/docs/device/reactive.md b/docs/device/reactive.md new file mode 100644 index 00000000..7b28fd30 --- /dev/null +++ b/docs/device/reactive.md @@ -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 Google’s 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, that’s 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, it’s frustrating if you press a button to make a character jump, but it doesn’t 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. + +Let’s 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. + +Let’s 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. + +Let’s think about three sequences of instructions: + +* Sequence S1 contains the instructions (let’s 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 we’ll 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:bit’s *scheduler* provides the capability to concurrently execute different code sequences, relieving us of a lot of low-level programming. In fact, scheduling is so useful that it is a part of every *operating system*! + +The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses. + +``` +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! That’s 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 hadn’t 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 Alice’s subprogram (and remembering where it stopped) and starting/resuming execution of Bob’s 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 don’t 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. + +Let’s 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 subprogram’s 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 + +Let’s go back to the `count button presses` function and revisit its execution based on what we have learned about the micro:bit scheduler. As detailed before, the function executes three steps to: (1) set up the event handler for each press of button A; (2) queue the forever loop to the run queue; (3) initialize the global variable `count` to zero. + +The function then ends execution and control passes back to the scheduler. Let’s assume the user has not pressed any buttons . The scheduler finds the `forever` loop in the run queue and passes control to it. The loop first calls `basic -> show number(0,150)`. In the diagram below, we use “Show 0” to refer to the execution of this function: + +![](/static/mb/device/reactive-3.png) + +While "Show 0" (the blue sequence) is running, periodic interrupts by the scheduler (every 6 milliseconds) poll for button presses and queue an event handler for each press of button A. Let’s say that one button press takes place during this time, as shown above. This will cause an event handler (labelled “inc”) to be queued for later execution by the scheduler. Once the "Show 0" has completed, the loop then calls `basic -> pause(20)` to put the forever loop to sleep for 20 milliseconds and give the scheduler an opportunity to run any newly queued event handler. Control passes to the “inc” event handler which will increment the global variable `count` from 0 to 1 and then complete, returning control to the scheduler. At some point, the `forever` loop moves from the sleep queue to the run queue; the `forever` loop then will resume and call `basic -> show number(1,150)`. + +### 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 + }) +} +``` + diff --git a/docs/device/screen.md b/docs/device/screen.md new file mode 100644 index 00000000..3d088d2c --- /dev/null +++ b/docs/device/screen.md @@ -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. + diff --git a/docs/device/usb.md b/docs/device/usb.md new file mode 100644 index 00000000..a34ef2ce --- /dev/null +++ b/docs/device/usb.md @@ -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 can’t 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 won’t 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) + diff --git a/docs/docs.md b/docs/docs.md new file mode 100644 index 00000000..63ae2cce --- /dev/null +++ b/docs/docs.md @@ -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) diff --git a/docs/hourofcode/notes.md b/docs/hourofcode/notes.md new file mode 100644 index 00000000..1326ef06 --- /dev/null +++ b/docs/hourofcode/notes.md @@ -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._ + diff --git a/docs/lessons.md b/docs/lessons.md new file mode 100644 index 00000000..0aa418d3 --- /dev/null +++ b/docs/lessons.md @@ -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) + diff --git a/docs/lessons/answering-machine.md b/docs/lessons/answering-machine.md new file mode 100644 index 00000000..e9563426 --- /dev/null +++ b/docs/lessons/answering-machine.md @@ -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) + diff --git a/docs/lessons/answering-machine/activity.md b/docs/lessons/answering-machine/activity.md new file mode 100644 index 00000000..2fad9620 --- /dev/null +++ b/docs/lessons/answering-machine/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/answering-machine/challenges.md b/docs/lessons/answering-machine/challenges.md new file mode 100644 index 00000000..8956c74c --- /dev/null +++ b/docs/lessons/answering-machine/challenges.md @@ -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`. + diff --git a/docs/lessons/answering-machine/quiz-answers.md b/docs/lessons/answering-machine/quiz-answers.md new file mode 100644 index 00000000..e59ac680 --- /dev/null +++ b/docs/lessons/answering-machine/quiz-answers.md @@ -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) + +
+ +## 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) + diff --git a/docs/lessons/answering-machine/quiz.md b/docs/lessons/answering-machine/quiz.md new file mode 100644 index 00000000..ab145514 --- /dev/null +++ b/docs/lessons/answering-machine/quiz.md @@ -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? + +
+ +
+ +## 2. Draw which LED is ON after running this code + +![](/static/mb/blocks/lessons/answering-machine-3.png) + +![](/static/mb/empty-microbit.png) + +
+ +## 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) + +
+ +## 4. If the rectangle below represents the micro:bit, write the code to display the letter "Z". + +![](/static/mb/lessons/answering-machine-5.png) + +
+ diff --git a/docs/lessons/banana-keyboard.md b/docs/lessons/banana-keyboard.md new file mode 100644 index 00000000..8cb81bab --- /dev/null +++ b/docs/lessons/banana-keyboard.md @@ -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 + diff --git a/docs/lessons/banana-keyboard/activity.md b/docs/lessons/banana-keyboard/activity.md new file mode 100644 index 00000000..d59cb0b5 --- /dev/null +++ b/docs/lessons/banana-keyboard/activity.md @@ -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! + diff --git a/docs/lessons/banana-keyboard/challenges.md b/docs/lessons/banana-keyboard/challenges.md new file mode 100644 index 00000000..3589d4b6 --- /dev/null +++ b/docs/lessons/banana-keyboard/challenges.md @@ -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. + + + diff --git a/docs/lessons/beatbox.md b/docs/lessons/beatbox.md new file mode 100644 index 00000000..fa493e47 --- /dev/null +++ b/docs/lessons/beatbox.md @@ -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) + diff --git a/docs/lessons/beautiful-image.md b/docs/lessons/beautiful-image.md new file mode 100644 index 00000000..d2c2694e --- /dev/null +++ b/docs/lessons/beautiful-image.md @@ -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) + diff --git a/docs/lessons/beautiful-image/activity.md b/docs/lessons/beautiful-image/activity.md new file mode 100644 index 00000000..32cb1a76 --- /dev/null +++ b/docs/lessons/beautiful-image/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/beautiful-image/challenges.md b/docs/lessons/beautiful-image/challenges.md new file mode 100644 index 00000000..2c0de484 --- /dev/null +++ b/docs/lessons/beautiful-image/challenges.md @@ -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. + diff --git a/docs/lessons/blink.md b/docs/lessons/blink.md new file mode 100644 index 00000000..af2914c1 --- /dev/null +++ b/docs/lessons/blink.md @@ -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 program’s control. The blink program introduces Forever. The forever loop repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language. + +## Documentation + +* **plot**: [read more...](/microbit/reference/led/plot) +* **unplot**: [read more...](/microbit/reference/led/unplot) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **forever**: [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [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) + diff --git a/docs/lessons/blink/activity.md b/docs/lessons/blink/activity.md new file mode 100644 index 00000000..a13cee4b --- /dev/null +++ b/docs/lessons/blink/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/blink/challenges.md b/docs/lessons/blink/challenges.md new file mode 100644 index 00000000..d25259bc --- /dev/null +++ b/docs/lessons/blink/challenges.md @@ -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`! + diff --git a/docs/lessons/blink/quiz-answers.md b/docs/lessons/blink/quiz-answers.md new file mode 100644 index 00000000..b10b9f9b --- /dev/null +++ b/docs/lessons/blink/quiz-answers.md @@ -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) + diff --git a/docs/lessons/blink/quiz.md b/docs/lessons/blink/quiz.md new file mode 100644 index 00000000..3081d163 --- /dev/null +++ b/docs/lessons/blink/quiz.md @@ -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? + +
+ +## 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) + diff --git a/docs/lessons/blocks-conditions.md b/docs/lessons/blocks-conditions.md new file mode 100644 index 00000000..6b01609a --- /dev/null +++ b/docs/lessons/blocks-conditions.md @@ -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. + diff --git a/docs/lessons/buzzer.md b/docs/lessons/buzzer.md new file mode 100644 index 00000000..d019c4f3 --- /dev/null +++ b/docs/lessons/buzzer.md @@ -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) + diff --git a/docs/lessons/challenges.md b/docs/lessons/challenges.md new file mode 100644 index 00000000..77b43e72 --- /dev/null +++ b/docs/lessons/challenges.md @@ -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. + diff --git a/docs/lessons/charting.md b/docs/lessons/charting.md new file mode 100644 index 00000000..8c013da7 --- /dev/null +++ b/docs/lessons/charting.md @@ -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) + diff --git a/docs/lessons/charting/activity.md b/docs/lessons/charting/activity.md new file mode 100644 index 00000000..96d3a4b8 --- /dev/null +++ b/docs/lessons/charting/activity.md @@ -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! diff --git a/docs/lessons/classic-beatbox.md b/docs/lessons/classic-beatbox.md new file mode 100644 index 00000000..245242f1 --- /dev/null +++ b/docs/lessons/classic-beatbox.md @@ -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) + diff --git a/docs/lessons/classic-beatbox/activity.md b/docs/lessons/classic-beatbox/activity.md new file mode 100644 index 00000000..300a3f6d --- /dev/null +++ b/docs/lessons/classic-beatbox/activity.md @@ -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)! + +### ~ \ No newline at end of file diff --git a/docs/lessons/classic-beatbox/challenges.md b/docs/lessons/classic-beatbox/challenges.md new file mode 100644 index 00000000..2a7380bb --- /dev/null +++ b/docs/lessons/classic-beatbox/challenges.md @@ -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. + diff --git a/docs/lessons/compass.md b/docs/lessons/compass.md new file mode 100644 index 00000000..471ac8fe --- /dev/null +++ b/docs/lessons/compass.md @@ -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) + diff --git a/docs/lessons/compass/activity.md b/docs/lessons/compass/activity.md new file mode 100644 index 00000000..943ef8f6 --- /dev/null +++ b/docs/lessons/compass/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/compass/challenges.md b/docs/lessons/compass/challenges.md new file mode 100644 index 00000000..b61fc71b --- /dev/null +++ b/docs/lessons/compass/challenges.md @@ -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. + diff --git a/docs/lessons/compass/quiz-answers.md b/docs/lessons/compass/quiz-answers.md new file mode 100644 index 00000000..e7afef16 --- /dev/null +++ b/docs/lessons/compass/quiz-answers.md @@ -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 + +
+ +## 2. Write the code that stores the compass heading into a local variable called 'degrees'. + +
+ +``` +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 + +
+ +``` +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 + +
+ +``` +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 + +
+ +``` +if (degrees < 225) { + basic.showString("S", 150) +} +``` + diff --git a/docs/lessons/compass/quiz.md b/docs/lessons/compass/quiz.md new file mode 100644 index 00000000..8217cdab --- /dev/null +++ b/docs/lessons/compass/quiz.md @@ -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? + +
+ +## 2. Write the code that stores the compass heading into a local variable called 'degrees'. + +
+ +## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the micro:bit + +
+ +## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the micro:bit + +
+ +## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the micro:bit + +
+ diff --git a/docs/lessons/counter.md b/docs/lessons/counter.md new file mode 100644 index 00000000..e1985271 --- /dev/null +++ b/docs/lessons/counter.md @@ -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) + diff --git a/docs/lessons/counter/activity.md b/docs/lessons/counter/activity.md new file mode 100644 index 00000000..2667b33e --- /dev/null +++ b/docs/lessons/counter/activity.md @@ -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) + +### ~ + diff --git a/docs/lessons/counter/challenges.md b/docs/lessons/counter/challenges.md new file mode 100644 index 00000000..29bd79b9 --- /dev/null +++ b/docs/lessons/counter/challenges.md @@ -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`. + diff --git a/docs/lessons/crocodile-clip/activity.md b/docs/lessons/crocodile-clip/activity.md new file mode 100644 index 00000000..f547d156 --- /dev/null +++ b/docs/lessons/crocodile-clip/activity.md @@ -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. + diff --git a/docs/lessons/die-roll.md b/docs/lessons/die-roll.md new file mode 100644 index 00000000..b739a4d8 --- /dev/null +++ b/docs/lessons/die-roll.md @@ -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) + diff --git a/docs/lessons/die-roll/activity.md b/docs/lessons/die-roll/activity.md new file mode 100644 index 00000000..2a9c380d --- /dev/null +++ b/docs/lessons/die-roll/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/die-roll/challenges.md b/docs/lessons/die-roll/challenges.md new file mode 100644 index 00000000..4b1dc900 --- /dev/null +++ b/docs/lessons/die-roll/challenges.md @@ -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. + diff --git a/docs/lessons/digi-yoyo.md b/docs/lessons/digi-yoyo.md new file mode 100644 index 00000000..d6bda133 --- /dev/null +++ b/docs/lessons/digi-yoyo.md @@ -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) + diff --git a/docs/lessons/digi-yoyo/activity.md b/docs/lessons/digi-yoyo/activity.md new file mode 100644 index 00000000..bd6bfa71 --- /dev/null +++ b/docs/lessons/digi-yoyo/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/digi-yoyo/challenges.md b/docs/lessons/digi-yoyo/challenges.md new file mode 100644 index 00000000..42b1afaa --- /dev/null +++ b/docs/lessons/digi-yoyo/challenges.md @@ -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); +``` diff --git a/docs/lessons/flashing-heart.md b/docs/lessons/flashing-heart.md new file mode 100644 index 00000000..3c6ae07d --- /dev/null +++ b/docs/lessons/flashing-heart.md @@ -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) + diff --git a/docs/lessons/flashing-heart/activity.md b/docs/lessons/flashing-heart/activity.md new file mode 100644 index 00000000..ab7cdc69 --- /dev/null +++ b/docs/lessons/flashing-heart/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/flashing-heart/challenges.md b/docs/lessons/flashing-heart/challenges.md new file mode 100644 index 00000000..3119823e --- /dev/null +++ b/docs/lessons/flashing-heart/challenges.md @@ -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. + diff --git a/docs/lessons/flashing-heart/quiz-answers.md b/docs/lessons/flashing-heart/quiz-answers.md new file mode 100644 index 00000000..da284d64 --- /dev/null +++ b/docs/lessons/flashing-heart/quiz-answers.md @@ -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) + +
+ +![](/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) + +
+ diff --git a/docs/lessons/flashing-heart/quiz.md b/docs/lessons/flashing-heart/quiz.md new file mode 100644 index 00000000..fe502c44 --- /dev/null +++ b/docs/lessons/flashing-heart/quiz.md @@ -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? + +
+ +
+ +## 2. Write the code that leaves an image on the screen for 1 second (1000 milliseconds) + +
+ +
+ +## 3. Write the code that leaves an image on the screen for 1.5 seconds (1500 milliseconds) + +
+ +
+ diff --git a/docs/lessons/game-counter.md b/docs/lessons/game-counter.md new file mode 100644 index 00000000..2a1040d0 --- /dev/null +++ b/docs/lessons/game-counter.md @@ -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) + diff --git a/docs/lessons/game-counter/activity.md b/docs/lessons/game-counter/activity.md new file mode 100644 index 00000000..e4a542da --- /dev/null +++ b/docs/lessons/game-counter/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/game-counter/challenges.md b/docs/lessons/game-counter/challenges.md new file mode 100644 index 00000000..2bb689e2 --- /dev/null +++ b/docs/lessons/game-counter/challenges.md @@ -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`. + diff --git a/docs/lessons/game-of-chance.md b/docs/lessons/game-of-chance.md new file mode 100644 index 00000000..0229bb95 --- /dev/null +++ b/docs/lessons/game-of-chance.md @@ -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) + diff --git a/docs/lessons/game-of-chance/activity.md b/docs/lessons/game-of-chance/activity.md new file mode 100644 index 00000000..bb35e056 --- /dev/null +++ b/docs/lessons/game-of-chance/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/game-of-chance/challenges.md b/docs/lessons/game-of-chance/challenges.md new file mode 100644 index 00000000..7840075c --- /dev/null +++ b/docs/lessons/game-of-chance/challenges.md @@ -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`. + diff --git a/docs/lessons/glowing-pendulum.md b/docs/lessons/glowing-pendulum.md new file mode 100644 index 00000000..69783902 --- /dev/null +++ b/docs/lessons/glowing-pendulum.md @@ -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) + diff --git a/docs/lessons/glowing-pendulum/activity.md b/docs/lessons/glowing-pendulum/activity.md new file mode 100644 index 00000000..097cca37 --- /dev/null +++ b/docs/lessons/glowing-pendulum/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/glowing-pendulum/challenges.md b/docs/lessons/glowing-pendulum/challenges.md new file mode 100644 index 00000000..e582e559 --- /dev/null +++ b/docs/lessons/glowing-pendulum/challenges.md @@ -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? + diff --git a/docs/lessons/glowing-sword.md b/docs/lessons/glowing-sword.md new file mode 100644 index 00000000..34101bcb --- /dev/null +++ b/docs/lessons/glowing-sword.md @@ -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. + diff --git a/docs/lessons/graphics.md b/docs/lessons/graphics.md new file mode 100644 index 00000000..a61ae480 --- /dev/null +++ b/docs/lessons/graphics.md @@ -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. + +We’ve 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. + diff --git a/docs/lessons/guess-the-number.md b/docs/lessons/guess-the-number.md new file mode 100644 index 00000000..994a4fb1 --- /dev/null +++ b/docs/lessons/guess-the-number.md @@ -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) + diff --git a/docs/lessons/guess-the-number/activity.md b/docs/lessons/guess-the-number/activity.md new file mode 100644 index 00000000..12fbe368 --- /dev/null +++ b/docs/lessons/guess-the-number/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/guess-the-number/challenges.md b/docs/lessons/guess-the-number/challenges.md new file mode 100644 index 00000000..c713757c --- /dev/null +++ b/docs/lessons/guess-the-number/challenges.md @@ -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! + diff --git a/docs/lessons/hack-your-headphones.md b/docs/lessons/hack-your-headphones.md new file mode 100644 index 00000000..90297fdf --- /dev/null +++ b/docs/lessons/hack-your-headphones.md @@ -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 + diff --git a/docs/lessons/hack-your-headphones/activity.md b/docs/lessons/hack-your-headphones/activity.md new file mode 100644 index 00000000..d8d6752d --- /dev/null +++ b/docs/lessons/hack-your-headphones/activity.md @@ -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! + diff --git a/docs/lessons/happy-birthday.md b/docs/lessons/happy-birthday.md new file mode 100644 index 00000000..5e253c18 --- /dev/null +++ b/docs/lessons/happy-birthday.md @@ -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) + diff --git a/docs/lessons/happy-birthday/activity.md b/docs/lessons/happy-birthday/activity.md new file mode 100644 index 00000000..b65ca17c --- /dev/null +++ b/docs/lessons/happy-birthday/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/happy-birthday/challenges.md b/docs/lessons/happy-birthday/challenges.md new file mode 100644 index 00000000..ec919ad3 --- /dev/null +++ b/docs/lessons/happy-birthday/challenges.md @@ -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. + diff --git a/docs/lessons/hero.md b/docs/lessons/hero.md new file mode 100644 index 00000000..d8708fc6 --- /dev/null +++ b/docs/lessons/hero.md @@ -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) diff --git a/docs/lessons/hero/activity.md b/docs/lessons/hero/activity.md new file mode 100644 index 00000000..ac14483f --- /dev/null +++ b/docs/lessons/hero/activity.md @@ -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) + +### ~ + diff --git a/docs/lessons/light-beatbox.md b/docs/lessons/light-beatbox.md new file mode 100644 index 00000000..9427a39e --- /dev/null +++ b/docs/lessons/light-beatbox.md @@ -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 + diff --git a/docs/lessons/light-beatbox/activity.md b/docs/lessons/light-beatbox/activity.md new file mode 100644 index 00000000..d2a6ef7e --- /dev/null +++ b/docs/lessons/light-beatbox/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/looper.md b/docs/lessons/looper.md new file mode 100644 index 00000000..93cc47ec --- /dev/null +++ b/docs/lessons/looper.md @@ -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) + diff --git a/docs/lessons/looper/activity.md b/docs/lessons/looper/activity.md new file mode 100644 index 00000000..1d4f85bc --- /dev/null +++ b/docs/lessons/looper/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/looper/challenges.md b/docs/lessons/looper/challenges.md new file mode 100644 index 00000000..88bb8a97 --- /dev/null +++ b/docs/lessons/looper/challenges.md @@ -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`! + diff --git a/docs/lessons/loops.md b/docs/lessons/loops.md new file mode 100644 index 00000000..8a112281 --- /dev/null +++ b/docs/lessons/loops.md @@ -0,0 +1,59 @@ +# blocks - loops + +An introduction to Loops for the Block Editor. #docs + +We may want to handle the user’s 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 hasn’t 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. + diff --git a/docs/lessons/love-meter.md b/docs/lessons/love-meter.md new file mode 100644 index 00000000..a8aeb510 --- /dev/null +++ b/docs/lessons/love-meter.md @@ -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 user’s 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) + diff --git a/docs/lessons/love-meter/activity.md b/docs/lessons/love-meter/activity.md new file mode 100644 index 00000000..91ccf1ae --- /dev/null +++ b/docs/lessons/love-meter/activity.md @@ -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) + +### ~ + diff --git a/docs/lessons/love-meter/challenges.md b/docs/lessons/love-meter/challenges.md new file mode 100644 index 00000000..5a41b1a1 --- /dev/null +++ b/docs/lessons/love-meter/challenges.md @@ -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. + diff --git a/docs/lessons/love-meter/quiz-answers.md b/docs/lessons/love-meter/quiz-answers.md new file mode 100644 index 00000000..ce7e033d --- /dev/null +++ b/docs/lessons/love-meter/quiz-answers.md @@ -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? + +
+ +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) + +
+ +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) + +
+ +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? + +
+ +You have told GND to complete the circuit. + diff --git a/docs/lessons/love-meter/quiz.md b/docs/lessons/love-meter/quiz.md new file mode 100644 index 00000000..744d1edd --- /dev/null +++ b/docs/lessons/love-meter/quiz.md @@ -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? + +
+ +## 2. Create a condition for on pin pressed (P0). + +
+ +## 3. Describe what this line of code does? + +![](/static/mb/blocks/lessons/love-meter-6.png) + +
+ +## 4. Describe what adding 1 to variable x does? + +![](/static/mb/blocks/lessons/love-meter-7.png) + +
+ +## 5. Describe why you must hold ground (GND) before pressing (P0) to run a program using `on pin pressed(P0)` on the micro:bit + +
+ diff --git a/docs/lessons/lucky-7.md b/docs/lessons/lucky-7.md new file mode 100644 index 00000000..43f3fd47 --- /dev/null +++ b/docs/lessons/lucky-7.md @@ -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) + diff --git a/docs/lessons/lucky-7/activity.md b/docs/lessons/lucky-7/activity.md new file mode 100644 index 00000000..69b65931 --- /dev/null +++ b/docs/lessons/lucky-7/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/lucky-7/challenges.md b/docs/lessons/lucky-7/challenges.md new file mode 100644 index 00000000..dd955586 --- /dev/null +++ b/docs/lessons/lucky-7/challenges.md @@ -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! + diff --git a/docs/lessons/lucky-7/quiz-answers.md b/docs/lessons/lucky-7/quiz-answers.md new file mode 100644 index 00000000..ea9ea24c --- /dev/null +++ b/docs/lessons/lucky-7/quiz-answers.md @@ -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) + +
+ +![](/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) + +
+ diff --git a/docs/lessons/lucky-7/quiz.md b/docs/lessons/lucky-7/quiz.md new file mode 100644 index 00000000..22a451d2 --- /dev/null +++ b/docs/lessons/lucky-7/quiz.md @@ -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? + +
+ +## 2. Draw every LED that is ON after running this code + +![](/static/mb/blocks/lessons/lucky-7-3.png) + +![](/static/mb/empty-microbit.png) + +
+ +## 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) + +
+ +## 4. Write the code that will be used to display the number 3 on the micro:bit. + +![](/static/mb/lessons/lucky-7-3.png) + +
+ +
+ diff --git a/docs/lessons/magic-8.md b/docs/lessons/magic-8.md new file mode 100644 index 00000000..cefd4512 --- /dev/null +++ b/docs/lessons/magic-8.md @@ -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) + diff --git a/docs/lessons/magic-8/activity.md b/docs/lessons/magic-8/activity.md new file mode 100644 index 00000000..696f26ea --- /dev/null +++ b/docs/lessons/magic-8/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/magic-8/challenges.md b/docs/lessons/magic-8/challenges.md new file mode 100644 index 00000000..d3f053af --- /dev/null +++ b/docs/lessons/magic-8/challenges.md @@ -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! + diff --git a/docs/lessons/magic-logo.md b/docs/lessons/magic-logo.md new file mode 100644 index 00000000..1529ad99 --- /dev/null +++ b/docs/lessons/magic-logo.md @@ -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) + diff --git a/docs/lessons/magic-logo/activity.md b/docs/lessons/magic-logo/activity.md new file mode 100644 index 00000000..96f0f6ec --- /dev/null +++ b/docs/lessons/magic-logo/activity.md @@ -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)! + +### ~ + diff --git a/docs/lessons/magic-logo/challenges.md b/docs/lessons/magic-logo/challenges.md new file mode 100644 index 00000000..864ac13a --- /dev/null +++ b/docs/lessons/magic-logo/challenges.md @@ -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. + diff --git a/docs/lessons/night-light.md b/docs/lessons/night-light.md new file mode 100644 index 00000000..08b07ca7 --- /dev/null +++ b/docs/lessons/night-light.md @@ -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) + diff --git a/docs/lessons/night-light/activity.md b/docs/lessons/night-light/activity.md new file mode 100644 index 00000000..d9915c7f --- /dev/null +++ b/docs/lessons/night-light/activity.md @@ -0,0 +1,67 @@ +# night light activity + +Change the brightness of the micro:bit. + +### ~avatar avatar + +### @video td/videos/night-light-0 + +Welcome! This tutorial will teach you how to change the brightness of the micro:bit. Let's get started! + +### ~ + +The brightness of the LED screen can be changed by using the `set brightness` function. This function takes a number between ``0`` (off) and ``255`` (full brightness). + +Let's build a little app that dims the screen when pressing button ``A``. + +Add the code `show LEDs` and select all LEDs to turn on all the LEDs. Don't hesitate to run your code to see what happens. + +```blocks +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +``` + +The screen starts with a 50% brightness value by default (128). Add a new line of code to set the full brightness (255) using `set brightness`. + +```blocks +led.setBrightness(255) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +``` + +Add a new event handler for `on button pressed(A)` and add the code to set the brightness to `64`. + + +```blocks +led.setBrightness(255) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + led.setBrightness(64) +}) + +``` + + + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/night-light/challenges)! + +### ~ + diff --git a/docs/lessons/night-light/challenges.md b/docs/lessons/night-light/challenges.md new file mode 100644 index 00000000..8658f4e5 --- /dev/null +++ b/docs/lessons/night-light/challenges.md @@ -0,0 +1,53 @@ +# night light challenges + +Coding challenges for night light. + +## Before we get started + +Complete the following [guided tutorial](/microbit/lessons/night-light/activity), your code should look like this: + + +```blocks +led.setBrightness(255) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + led.setBrightness(64) +}) + +``` +### Challenge 1 + +### @video td/videos/night-light-2 + +What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add an event handler with `on button pressed(B)` add `set brightness(0)` to turn off the LEDs. + + +```blocks +led.setBrightness(255) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + led.setBrightness(64) +}) +input.onButtonPressed(Button.B, () => { + led.setBrightness(0) +}) +``` + + +**Challenge 3** + +Add an event handler with `on shake` to change the LED brightness back to a `255`. + +* `Run main` your script to see the LEDs change brightness. diff --git a/docs/lessons/ornament-chain/activity.md b/docs/lessons/ornament-chain/activity.md new file mode 100644 index 00000000..a67d78fd --- /dev/null +++ b/docs/lessons/ornament-chain/activity.md @@ -0,0 +1,80 @@ +# ornament chain activity + +Build a telgraph + +# micro:bit Ornament Chain + +![](/static/mb/lessons/ornament-chain-0.jpg) + +![](/static/mb/lessons/ornament-chain-1.jpg) + +In this project, you will build your ornament chain between micro:bits. 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/lessons/ornament-chain-2.png) + +Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the micro:bit. + +### Step 3 + +![](/static/mb/lessons/ornament-chain-3.png) + +Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the micro:bit. + +### Step 4 + +![](/static/mb/lessons/ornament-chain-4.png) + +Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the micro:bit. + +### Step 5 + +![](/static/mb/lessons/ornament-chain-5.png) + +Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd micro:bit. + +### Step 6 + +![](/static/mb/lessons/ornament-chain-6.png) + +Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd micro:bit. + +### Step 7 + +![](/static/mb/lessons/ornament-chain-7.png) + +Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd micro:bit. + +### Step 8 + +![](/static/mb/lessons/ornament-chain-8.png) + +Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd micro:bit + +### Step 9 + +![](/static/mb/lessons/ornament-chain-0.jpg) + +![](/static/mb/lessons/ornament-chain-1.jpg) + +Your ornament chain is ready! + +### Step 10 + +* Connect the first micro:bit to your computer using your USB cable and run the [ornament chain](/microbit/fcicvk) script on it. +* Connect the second micro:bit to your computer using your USB cable and run the [ornament chain](/microbit/fcicvk) script on it. +* The first person and second person take turns pressing button A to start the ornament chain game! diff --git a/docs/lessons/pogo.md b/docs/lessons/pogo.md new file mode 100644 index 00000000..f5dd2149 --- /dev/null +++ b/docs/lessons/pogo.md @@ -0,0 +1,60 @@ +# pogo lesson + +create a game that relies on precise instincts and timing reflexes #if # #function #data #forever #var #button #if #assignment #pause #string #number #docs + +## Topic + +Running Time + +## Quick Links + +* [activity](/microbit/lessons/pogo/activity) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use running time. We will be learning how to create a pogo game using variables, forever loop, conditionals, on button pressed, as well as simple commands, such as show LEDs and clear screen. + +## Documentation + +* **variable** : [read more...](/microbit/reference/variables/var) +* **arithmetic operator** : [read more...](/microbit/reference/types/number) +* **forever** : [read more...](/microbit/reference/basic/forever) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **if** : [read more...](/microbit/reference/logic/if) +* **clear screen** : [read more...](/microbit/reference/basic/clear-screen) +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) + +## Objectives + +* learn how to create a function as a unit of code that performs a specific task and returns a result +* learn how arithmetic operators operate on numbers and return a number +* learn how to repeat code in the background forever +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to run code when an input button is pressed +* learn how to pause your code for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + diff --git a/docs/lessons/pogo/activity.md b/docs/lessons/pogo/activity.md new file mode 100644 index 00000000..81c2ac68 --- /dev/null +++ b/docs/lessons/pogo/activity.md @@ -0,0 +1,36 @@ +# pogo activity + +Construct a counter that uses 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. 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/pogo-0.jpg) + +Since the micro:bit will be swinging up and down, we need to store the variable called jumps. We will set the variable called jumps to 0 to store the number 0. + +![](/static/mb/blocks/lessons/pogo-1.jpg) + +The function `acceleration(y)` gets the acceleration value (milli g-force), in the `y` dimension. If the `acceleration(y)`is greater than 2000 milli g-force, we will change jumps by 1. + +If the `acceleration(y)`is greater than 2000 milli g-force, we will display the image with `show LEDs` to display a smiley face on the LEDs and `clear screen` to to turn off all the LED lights on the LED screen. + +![](/static/mb/blocks/lessons/pogo-2.jpg) + +Now let's register an event handler that will execute whenever an input button (A) is pressed during program execution. + +![](/static/mb/blocks/lessons/pogo-3.jpg) + +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)! + +### ~ + diff --git a/docs/lessons/rock-paper-scissors.md b/docs/lessons/rock-paper-scissors.md new file mode 100644 index 00000000..e26d5147 --- /dev/null +++ b/docs/lessons/rock-paper-scissors.md @@ -0,0 +1,56 @@ +# rock paper scissors lesson + +a game against the BBC micro:bit #var #image #button #string #number #docs + +### @video td/videos/rock-paper-scissors-0 + +## Topic + +Local Variables + +## Quick Links + +* [activity](/microbit/lessons/rock-paper-scissors/activity) +* [challenges](/microbit/lessons/rock-paper-scissors/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a **local variable**, `var t :=time` where you can store data, so that you can use it in your code. We will be learning how to create a classic rock paper scissors game using global variables, input on shake, local variables, math random as well as simple commands such as create image, show image, show string, and show number. + +## Documentation + +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **pick random** : [read more...](/microbit/blocks/math) + +## Objectives + +* learn how to create a condition so the micro:bit will run code when it is shaken +* learn how to create a local variable for a place where you can store data +* learn how to create an image to show on the micro:bit's LED screen +* learn how to show an image on the micro:bit's LED screen + +## 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) +* Declares and assigns variables(AB) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Defines data types: real numbers and Boolean (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + diff --git a/docs/lessons/rock-paper-scissors/activity.md b/docs/lessons/rock-paper-scissors/activity.md new file mode 100644 index 00000000..07e2d1b7 --- /dev/null +++ b/docs/lessons/rock-paper-scissors/activity.md @@ -0,0 +1,123 @@ +# rock paper scissors activity + +A classic game against the micro:bit. + +### ~avatar avatar + +### @video td/videos/rock-paper-scissors-0 + +Welcome! This tutorial will help you create a game of rock paper scissors 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 **Touch Develop**. + +We want the micro:bit to choose rock, paper, or scissors when it is shaken. Let's begin by creating an on shake condition so the micro:bit will run code when it is shaken. + + +```blocks + +input.onGesture(Gesture.Shake, () => { + +}) + +``` + +Next, create a variable and store pick random number from 0 to 2. On shake, a number will be randomly picked from 0-2. We will randomly display an image based on the random number returned. + + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(3) +}) + +``` + +The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is equal to 2. We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function. + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(3) + if (img == 2) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } +}) + + +``` + +The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is equal to 1. We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function. + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(3) + if (img == 2) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } else if (img == 1) { + basic.showLeds(` + . . . . . + . # # # . + . # # # . + . # # # . + . . . . . + `) + } +}) +``` + +The micro:bit will look like it's showing 1 frame of the image by displaying the whole image when pick random is not equal to 2 and not equal to 1. We can help the micro:bit randomly decide which image to use by pick random. The micro:bit will randomly pick the image to display with show LEDs and the pick random function. + + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(3) + if (img == 2) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } else if (img == 1) { + basic.showLeds(` + . . . . . + . # # # . + . # # # . + . # # # . + . . . . . + `) + } else { + basic.showLeds(` + . . . # # + # # . # . + . . # . . + # # . # . + . . . # # + `) + } +}) + +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/rock-paper-scissors/challenges)! + +### ~ + diff --git a/docs/lessons/rock-paper-scissors/challenges.md b/docs/lessons/rock-paper-scissors/challenges.md new file mode 100644 index 00000000..95e572e6 --- /dev/null +++ b/docs/lessons/rock-paper-scissors/challenges.md @@ -0,0 +1,133 @@ +# rock paper scissors challenges + +Coding challenges for rock paper scissors. + +## Before we get started + +Complete the following [guided activity](/microbit/lessons/rock-paper-scissors/activity) , your code should look like this: + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(3) + if (img == 2) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } else if (img == 1) { + basic.showLeds(` + . . . . . + . # # # . + . # # # . + . # # # . + . . . . . + `) + } else { + basic.showLeds(` + . . . # # + # # . # . + . . # . . + # # . # . + . . . # # + `) + } +}) + +``` + +### Challenge 1 + +When the A button is pressed, increment the score by 1. You can select Game drawer then add change score by 1. + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(2) + if (img == 2) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } else if (img == 1) { + basic.showLeds(` + . . . . . + . # # # . + . # # # . + . # # # . + . . . . . + `) + } else { + basic.showLeds(` + . . . # # + # # . # . + . . # . . + # # . # . + . . . # # + `) + } +}) +input.onButtonPressed(Button.A, () => { + game.addScore(1) +}) + +``` + +* Click *run* to execute your code in the simulator + +### Challenge 2 + +After incrementing the score, display the total number of wins you have. + + +```blocks +input.onGesture(Gesture.Shake, () => { + let img = Math.random(2) + if (img == 2) { + basic.showLeds(` + # # # # # + # . . . # + # . . . # + # . . . # + # # # # # + `) + + } else if (img == 1) { + basic.showLeds(` + . . . . . + . # # # . + . # # # . + . # # # . + . . . . . + `) + } else { + basic.showLeds(` + . . . # # + # # . # . + . . # . . + # # . # . + . . . # # + `) + } +}) +input.onButtonPressed(Button.A, () => { + game.addScore(1) + basic.showString("WINS:") + basic.showNumber(game.score()) +}) + +``` + +* Run and compile the code to see if it works as expected. + +### Challenge 3 + +You have successfully tracked and displayed the number of wins on the micro:bit! However, what about losses? Use the Game drawer to change score by -1 when button `B` is pressed. + +* Run and compile the code to see if it works as expected. diff --git a/docs/lessons/rotation-animation.md b/docs/lessons/rotation-animation.md new file mode 100644 index 00000000..65a1f86c --- /dev/null +++ b/docs/lessons/rotation-animation.md @@ -0,0 +1,79 @@ +# rotation animation block lesson + +Learn how to create images with a global variable and while loop. #LED #screen #plot #docs + +## Topic + +While Loop + +## Quick links + +* [activity](/microbit/lessons/rotation-animation/activity) +* [challenges](/microbit/lessons/rotation-animation/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create images that look like a rotating animation by using a while loop. We will be learning how to create a rotating animation using a global variable, while loop as well as simple commands, such as on button pressed and show animation. + +## Documentation + +* **variable**: [read more...](/microbit/reference/variables/var) +* **assignment operator**: [read more...](/microbit/reference/variables/assign) +* **while**: [read more...](/microbit/js/while) +* **Boolean condition (for the while loop)** : [read more...](/microbit/reference/types/boolean) +* **on button pressed**: [read more...](/microbit/reference/input/on-button-pressed) +* **show LEDs**: [read more...](/microbit/reference/basic/show-leds) +* **pause**: [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to create a global variable for a place where you can store data, accessible across functions, and in nested code blocks +* learn how to set or change the value of a global variable +* learn how to repeat code while a condition is true +* learn how to declare a global boolean variable to determine which code will execute next +* learn how to run code when an input button is pressed +* learn how to show a series of image frames on the LED screen +* learn how to pause your code 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) +* 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/rotation-animation/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/rotation-animation/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/rotation-animation/challenges) + diff --git a/docs/lessons/rotation-animation/activity.md b/docs/lessons/rotation-animation/activity.md new file mode 100644 index 00000000..96bd2e45 --- /dev/null +++ b/docs/lessons/rotation-animation/activity.md @@ -0,0 +1,69 @@ +# rotation animation block activity + +Rotate images with a while loop. + +### ~avatar avatar + +Welcome! This tutorial will teach how to rotate images with a **while loop**. Let's get started! + +### ~ + +Let's start by creating a global variable called `rotating` and initialize it to true. This well indicate when the animation should be displaying. + +```blocks +let rotating = true; +``` + +Now we need a while loop that will be executed only if the variable rotating is true. + +```blocks +let rotating = true; +while (rotating) { + basic.pause(20) + +} +``` + +Let's create and show an animation of a diagonal line that rotates clockwise. We need a pause so that the battery does not burn out. + +```blocks +let rotating = true; +while (rotating) { + basic.pause(20) + basic.showLeds(` + # . . . . + . # . . . + . . # . . + . . . # . + . . . . # + `) + basic.showLeds(` + . . # . . + . . # . . + . . # . . + . . # . . + . . # . . + `) + basic.showLeds(` + . . . . # + . . . # . + . . # . . + . # . . . + # . . . . + `) + basic.showLeds(` + . . . . . + . . . . . + # # # # # + . . . . . + . . . . . + `) +} +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/rotation-animation/challenges)! + +### ~ + diff --git a/docs/lessons/rotation-animation/challenges.md b/docs/lessons/rotation-animation/challenges.md new file mode 100644 index 00000000..0090af9f --- /dev/null +++ b/docs/lessons/rotation-animation/challenges.md @@ -0,0 +1,146 @@ +# rotation animation block challenges + +Coding challenges for the rotation animation. + +## Before we get started + +Complete the following guided activity: + +* [activity](/microbit/lessons/rotation-animation/activity) + +At the end of the activity, your code should look like this: + + +```blocks +let rotating = true; +while (rotating) { + basic.pause(20) + basic.showLeds(` + # . . . . + . # . . . + . . # . . + . . . # . + . . . . # + `) + basic.showLeds(` + . . # . . + . . # . . + . . # . . + . . # . . + . . # . . + `) + basic.showLeds(` + . . . . # + . . . # . + . . # . . + . # . . . + # . . . . + `) + basic.showLeds(` + . . . . . + . . . . . + # # # # # + . . . . . + . . . . . + `) +} +``` + + +### Challenge 1 + +Now let's add to this by creating a condition for on button pressed `A` before the while loop. + +```blocks + +let rotating = true; +while (rotating) { + basic.pause(20) + basic.showLeds(` + # . . . . + . # . . . + . . # . . + . . . # . + . . . . # + `) + basic.showLeds(` + . . # . . + . . # . . + . . # . . + . . # . . + . . # . . + `) + basic.showLeds(` + . . . . # + . . . # . + . . # . . + . # . . . + # . . . . + `) + basic.showLeds(` + . . . . . + . . . . . + # # # # # + . . . . . + . . . . . + `) +} +input.onButtonPressed(Button.A, () => { + +}) + + +``` + +### Challenge 2 + +### @video td/videos/rotation-animation-1-and-2 + +Now that we have the on button pressed condition, let's make the animation stop rotating by setting the rotating global variable to false when button `A` is pressed. + +```blocks +let rotating = true; +while (rotating) { + basic.pause(20) + basic.showLeds(` + # . . . . + . # . . . + . . # . . + . . . # . + . . . . # + `) + basic.showLeds(` + . . # . . + . . # . . + . . # . . + . . # . . + . . # . . + `) + basic.showLeds(` + . . . . # + . . . # . + . . # . . + . # . . . + # . . . . + `) + basic.showLeds(` + . . . . . + . . . . . + # # # # # + . . . . . + . . . . . + `) +} +input.onButtonPressed(Button.A, () => { + let rotating = false; +}) + + +``` + +* Run the code to see the awesome rotation. + +### Challenge 3 + +Let's also make the image rotate the opposite way when button A is pressed! We can do this with another while loop that is only executed while `not rotating`. + diff --git a/docs/lessons/screen-wipe.md b/docs/lessons/screen-wipe.md new file mode 100644 index 00000000..e6b61e54 --- /dev/null +++ b/docs/lessons/screen-wipe.md @@ -0,0 +1,100 @@ +# screen wipe blocks lesson + +clear the screen by pressing button "A" #button #clear #docs + +### @video td/videos/screen-wipe-0 + +## Topic + +Clear Screen + +## Quick Links + +* [activity](/microbit/lessons/screen-wipe/activity) +* [quiz](/microbit/lessons/screen-wipe/quiz) +* [quiz answers](/microbit/lessons/screen-wipe/quiz-answers) +* [challenges](/microbit/lessons/screen-wipe/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to **clear screen**, `clear screen` to turn off all the LED lights on the LED screen. We will be learning how to clear all LED lights on the LED screen using clear screen, input on button pressed as well as simple commands, such as show animation. + +## What the teacher needs to know/QuickStart Computing Glossary + +* Algorithm: An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. +* 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. +* 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 LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **clear screen** : [read more...](/microbit/reference/basic/clear-screen) + +## Resources + +* Activity: [activity](/microbit/lessons/screen-wipe/activity) +* Activity: [quiz](/microbit/lessons/screen-wipe/quiz) +* Extended Activity: [challenges](/microbit/lessons/screen-wipe/challenges) + +## Objectives + +* learn how to show a series of images on the LED screen +* learn how to run code when an input button is pressed +* learn how to turn off 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) +* Shows an awareness of tasks best completed by humans or computers (EV) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (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) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Selects the appropriate data types(AL) (AB + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Recognises ethical issues surrounding the application of information technology beyond school. +* Designs criteria to critically evaluate the quality of solutions, uses the criteria to identify improvements and can make appropriate refinements to the solution (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/screen-wipe/activity) +* [quiz](/microbit/lessons/screen-wipe/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/screen-wipe/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/screen-wipe/challenges) + diff --git a/docs/lessons/screen-wipe/activity.md b/docs/lessons/screen-wipe/activity.md new file mode 100644 index 00000000..6f8ba91f --- /dev/null +++ b/docs/lessons/screen-wipe/activity.md @@ -0,0 +1,90 @@ +# screen wipe blocks activity + +Clear the screen by pressing buttons on the micro:bit + +### ~avatar avatar + +### @video td/videos/screen-wipe-0 + +This activity will teach how to clear the screen by pressing button A on the micro:bit. + +### ~ + +You can use the clear screen` function to turn off all the LED on the screen. Let's illustrate this concept with a small script where the user has to press the button A to turn off the screen. Let's start by adding the code to show an animation. + +```blocks +basic.showLeds(` + # # # # # + # # # # # + . . . . . + . . . . . + . . . . . + `) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + . . . . . + # # # # # + # # # # # + `) +``` + +We add another line of code that registers an *event handler* `on button pressed` *A* and calls `clear screen`. + +```blocks +basic.showLeds(` + # # # # # + # # # # # + . . . . . + . . . . . + . . . . . + `) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + . . . . . + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + basic.clearScreen() +}) + +``` + +*Run* the script in the simulator or on the micro:bit to see how this works! + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/screen-wipe/challenges)! + +### ~ + diff --git a/docs/lessons/screen-wipe/challenges.md b/docs/lessons/screen-wipe/challenges.md new file mode 100644 index 00000000..647ee579 --- /dev/null +++ b/docs/lessons/screen-wipe/challenges.md @@ -0,0 +1,162 @@ +# screen wipe blocks challenges + +Coding challenges for screen wipe. + +## Before we get started + +Complete the [screen wipe](/microbit/lessons/screen-wipe) activity and your code will look like this: + +```blocks +basic.showLeds(` + # # # # # + # # # # # + . . . . . + . . . . . + . . . . . + `) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + . . . . . + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + basic.clearScreen() +}) + +``` + +**Challenge 1** + +Create an event handler for Button B. + +```blocks +basic.showLeds(` + # # # # # + # # # # # + . . . . . + . . . . . + . . . . . + `) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + . . . . . + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + basic.clearScreen() +}) +input.onButtonPressed(Button.B, () => { + +}) + +``` + +**Challenge 2** + +### @video td/videos/screen-wipe-2 + +Replay the animation when the "B" button is pressed placing the `show LEDs` block on the canvas. + +```blocks +basic.showLeds(` + # # # # # + # # # # # + . . . . . + . . . . . + . . . . . + `) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + . . . . . + # # # # # + # # # # # + `) +input.onButtonPressed(Button.A, () => { + basic.clearScreen() +}) +input.onButtonPressed(Button.B, () => { + basic.showLeds(` + # # # # # + # # # # # + . . . . . + . . . . . + . . . . . + `) +basic.showLeds(` + # # # # # + # # # # # + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + # # # # # + # # # # # + . . . . . + `) +basic.showLeds(` + . . . . . + . . . . . + . . . . . + # # # # # + # # # # # + `) +}) + +``` + + +**Challenge 3** + +Show an animation that scrolls back up when you press button "B". + +* tap the *run* button to view your final product! diff --git a/docs/lessons/screen-wipe/quiz-answers.md b/docs/lessons/screen-wipe/quiz-answers.md new file mode 100644 index 00000000..f6000dab --- /dev/null +++ b/docs/lessons/screen-wipe/quiz-answers.md @@ -0,0 +1,24 @@ +# screen wipe quiz blocks answers + +Clear the screen by pressing the "A" button after an animation has been played + +This is the answer key for the [screen wipe quiz](/microbit/lessons/screen-wipe/quiz). + +## 1. What does the function "clear screen" do on the micro:bit? + +This function turns off all the LED lights on the LED screen. + +## 2. Write the line of code that displays this image. + +![](/static/mb/blocks/lessons/screen-wipe-4.png) + +![](/static/mb/blocks/lessons/screen-wipe-5.png) + +## 3. Write the condition that will detect on button A pressed + +![](/static/mb/blocks/lessons/screen-wipe-6.png) + +## 4. Write the code that will clear show LEDS from the screen after pressing button A + +![](/static/mb/blocks/lessons/screen-wipe-7.png) + diff --git a/docs/lessons/screen-wipe/quiz.md b/docs/lessons/screen-wipe/quiz.md new file mode 100644 index 00000000..ab4e9904 --- /dev/null +++ b/docs/lessons/screen-wipe/quiz.md @@ -0,0 +1,30 @@ +# screen wipe blocks quiz + +Clear the screen by pressing the "A" button after an animation has been played + +## Name + +## Directions + +Use this activity document to guide your work in the [screen wipe activity](/microbit/lessons/screen-wipe/activity) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what "clear screen" does? + +
+ +## 2. Write the code that clears an image from the screen + +![](/static/mb/blocks/lessons/screen-wipe-4.png) + +
+ +## 3. Write the condition that will detect on button A pressed + +
+ +## 4. Write the code that will clear show LEDS from the screen after pressing button A + +
+ diff --git a/docs/lessons/smiley.md b/docs/lessons/smiley.md new file mode 100644 index 00000000..0915151d --- /dev/null +++ b/docs/lessons/smiley.md @@ -0,0 +1,84 @@ +# smiley blocks lesson + +design a blinking image lesson #docs + +### @video td/videos/smiley-0 + +## Topic + +Show LEDs + +## Quick Links + +* [activity](/microbit/lessons/smiley/activity) +* [quiz](/microbit/lessons/smiley/quiz) +* [quiz answers](/microbit/lessons/smiley/quiz-answers) +* [challenges](/microbit/lessons/smiley/challenges) + +## Class + +Year 7 + +## Prior learning / place of lesson in scheme of work + +Learn how to **show LEDs** to turn on a LED light pattern on the LED screen. We will be learning basic comments such as show LEDs and pause. + +## Documentation + +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) + +## Objectives + +* learn how to show LEDs on the LED 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/smiley/activity) +* [quiz](/microbit/lessons/smiley/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/smiley/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/smiley/challenges) + diff --git a/docs/lessons/smiley/activity.md b/docs/lessons/smiley/activity.md new file mode 100644 index 00000000..2777881c --- /dev/null +++ b/docs/lessons/smiley/activity.md @@ -0,0 +1,37 @@ +# smiley blocks activity + +Learn to design a blinking image. + +### ~avatar avatar + +### @video td/videos/smiley-0 + +Welcome! This tutorial will help you make a smiley face blink. Let's get started! + +### ~ + +Create an animation with an image displaying a smiley face and the next image with no LEDs lit up. This will make it look like the smiley face is blinking as the display switches between images. + +```blocks +basic.showAnimation(` + . # . # . + . # . # . + . . . . . + # . . . # + . # # # . + `) +basic.showAnimation(` + . . . . . + . . . . . + . . . . . + . . . . . + . . . . . + `) +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/smiley/challenges)! + +### ~ + diff --git a/docs/lessons/smiley/challenges.md b/docs/lessons/smiley/challenges.md new file mode 100644 index 00000000..f875843f --- /dev/null +++ b/docs/lessons/smiley/challenges.md @@ -0,0 +1,93 @@ +# smiley blocks challenges + +Coding challenges for the smiley. + +## Before we get started + +Complete the [smiley activity](/microbit/lessons/smiley/activity) and your code will look like this: + + +```blocks +basic.showAnimation(` + . # . # . + . # . # . + . . . . . + # . . . # + . # # # . + `) +basic.showAnimation(` + . . . . . + . . . . . + . . . . . + . . . . . + . . . . . + `) +``` + + +### Challenge 1 + +What if we want to make the face to frown on button pressed A? + +Let's make add code that will run when button A is pressed! + + +```blocks +basic.showAnimation(` + . # . # . + . # . # . + . . . . . + # . . . # + . # # # . + `) +basic.showAnimation(` + . . . . . + . . . . . + . . . . . + . . . . . + . . . . . + `) +input.onButtonPressed(Button.A, () => { + +}) +``` + +### Challenge 2 + +### @video td/videos/smiley-2 + +Now, we want to show a frowny face when this button is pressed. Let's show the LEDs. + +```blocks +basic.showAnimation(` + . # . # . + . # . # . + . . . . . + # . . . # + . # # # . + `) +basic.showAnimation(` + . . . . . + . . . . . + . . . . . + . . . . . + . . . . . + `) +input.onButtonPressed(Button.A, () => { + basic.showAnimation(` + . # . # . + . # . # . + . . . . . + . # # # . + # . . . # + `) +}) + +``` + +* Run your code to see if it works as expected. + +### Challenge 3 + +When *button B* is pressed, let's change the sad face back to a happy face. To do this, begin by adding a condition for `on button pressed` *B*. Next, show LEDs as a smiley face inside the condition. + diff --git a/docs/lessons/smiley/quiz-answers.md b/docs/lessons/smiley/quiz-answers.md new file mode 100644 index 00000000..64211b3d --- /dev/null +++ b/docs/lessons/smiley/quiz-answers.md @@ -0,0 +1,28 @@ +# smiley blocks quiz answers + +This is the answer key for the [smiley quiz](/microbit/lessons/smiley/quiz). + +## 1. Describe what `show LEDs` does + +A function that will display an image on the LED screen + +## 2. Why is there an extra empty frame after the smiley face? + +![](/static/mb/lessons/smiley-0.png) + +
+ +The extra empty image with show LED creates a blinking smiley, allowing the micro:bit to alternate between showing the smiley and the empty screen. + +## 3. Draw the image created with this code + +![](/static/mb/blocks/lessons/smiley-3.png) + +![](/static/mb/blocks/lessons/smiley-4.png) + +## 4. Write the code to make this image + +![](/static/mb/blocks/lessons/smiley-5.png) + +![](/static/mb/blocks/lessons/smiley-6.png) + diff --git a/docs/lessons/smiley/quiz.md b/docs/lessons/smiley/quiz.md new file mode 100644 index 00000000..a1ce64d8 --- /dev/null +++ b/docs/lessons/smiley/quiz.md @@ -0,0 +1,36 @@ +# smiley blocks quiz + +Make a smiley face blink + +## Name + +## Directions + +Use the hints in the [Smiley](/microbit/lessons/smiley/activity) activity to answer this quiz! + +## 1. Describe what `show LEDs` does + +
+ +
+ +## 2. Why is there an extra empty frame after the smiley face? + +![](/static/mb/lessons/smiley-0.png) + +
+ +## 3. Draw the image created with this code + +![](/static/mb/blocks/lessons/smiley-3.png) + +![](/static/mb/empty-microbit.png) + +
+ +## 4. Draw the images created with this code + +![](/static/mb/blocks/lessons/smiley-5.png) + +![](/static/mb/lessons/looper-3.png) + diff --git a/docs/lessons/snowflake-fall.md b/docs/lessons/snowflake-fall.md new file mode 100644 index 00000000..061c0201 --- /dev/null +++ b/docs/lessons/snowflake-fall.md @@ -0,0 +1,90 @@ +# snowflake fall blocks lesson + +design a blinking rectangle animation #animation #loop #forever #docs + +### @video td/videos/snowflake-fall-0 + +## Topic + +Forever + +## Quick Links + +* [activity](/microbit/lessons/snowflake-fall/activity) +* [quiz](/microbit/lessons/snowflake-fall/quiz) +* [quiz answers](/microbit/lessons/snowflake-fall/quiz-answers) +* [challenges](/microbit/lessons/snowflake-fall/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to show LEDs with a, `pause` to pause program execution for a specified amount of milliseconds. We will be learning how to show images using forever loop as well as simple commands, such as pause and show LEDs. + +## What the teacher needs to know/QuickStart Computing Glossary + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* 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. + +## Documentation + +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **pause** : [read more...](/microbit/reference/basic/pause) +* **forever** : [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [activity](/microbit/lessons/snowflake-fall/activity) +* Activity: [quiz](/microbit/lessons/snowflake-fall/quiz) +* Extended Activity: [challenges](/microbit/lessons/snowflake-fall/challenges) + +## Objectives + +* learn how to show an image on the LED screen +* learn how to pause a program for a specified amount of time in milliseconds +* learn how to repeat code in the background forever + +## 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) + +#### 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/snowflake-fall/activity) +* [quiz](/microbit/lessons/snowflake-fall/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/snowflake-fall/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/snowflake-fall/challenges) + diff --git a/docs/lessons/snowflake-fall/activity.md b/docs/lessons/snowflake-fall/activity.md new file mode 100644 index 00000000..f9065309 --- /dev/null +++ b/docs/lessons/snowflake-fall/activity.md @@ -0,0 +1,63 @@ +# snowflake fall blocks activity + +design a blinking rectangle animation. #docs #tutorials #stepByStep + +### ~avatar avatar + +### @video td/videos/snowflake-fall-0 + +Welcome! This tutorial will teach how design a **snowfall animation**. Let's get started! + +### ~ + +Let's start by creating a `forever` loop that will allow us to repeat the show LEDs code. Any code in the `forever` loop will repeat in the background... forever. + + +```blocks +basic.forever(() => { + basic.showLeds(` + . . . . . + . . # . . + . # # # . + . . # . . + . . . . . + `) + basic.showLeds(` + . . . . . + . . . . . + . . . . . + . . . . . + . . . . . + `) +}) +``` + +The next step is to add two `show LEDs` blocks inside the `forever` loop to repeat an animation. + +```blocks +basic.forever(() => { + basic.showLeds(` + . . . . . + . . # . . + . # # # . + . . # . . + . . . . . + `) + basic.showLeds(` + . . # . . + . # . # . + # . . . # + . # . # . + . . # . . + `) +}) +```blocks + +Run your code in the simulator or download it to your BBC micro:bit to see what happens! + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/snowflake-fall/challenges)! + +### ~ + diff --git a/docs/lessons/snowflake-fall/challenges.md b/docs/lessons/snowflake-fall/challenges.md new file mode 100644 index 00000000..26f80a46 --- /dev/null +++ b/docs/lessons/snowflake-fall/challenges.md @@ -0,0 +1,34 @@ +# snowflake fall blocks challenges + +Coding challenges for snowflake fall. + +## Before we get started + +Complete the [snowflake fall](/microbit/lessons/snowflake-fall/activity) activity and your code will look like this: + +![](/static/mb/blocks/lessons/snowflake-fall-1.jpg) + +### Challenge 1 + +### @video td/videos/snowflake-fall-1 + +Let's begin creating our falling effect by adding another snowflake with `show LEDs` that displays a different snowflake pattern after the first one. We need 2 frames in the new animation that display both the first and the second snowflake images. + +![](/static/mb/blocks/lessons/snowflake-fall-2.jpg) + +* Run your program to see the cool animation. + +### Challenge 2 + +### @video td/videos/snowflake-fall-2 + +To finalize our snowflake fall, let's add a different snowflake pattern. + +![](/static/mb/blocks/lessons/snowflake-fall-3.jpg) + +* Run your program and see if it works. + +### Challenge 3 + +Add a fourth frame to the current animation... or make it your own! + diff --git a/docs/lessons/snowflake-fall/quiz-answers.md b/docs/lessons/snowflake-fall/quiz-answers.md new file mode 100644 index 00000000..4d11b2e5 --- /dev/null +++ b/docs/lessons/snowflake-fall/quiz-answers.md @@ -0,0 +1,30 @@ +# snowflake fall blocks quiz answers + +Create a snowflake fall animation. + +This is the answer key for the [snowflake fall quiz](/microbit/lessons/snowflake-fall/quiz). + +## 1. What is a forever loop? + +Run code in the background forever (answers may vary). + +## 2. Draw the picture that will be produced with this code + +![](/static/mb/blocks/lessons/snowflake-fall-4.png) + +![](/static/mb/lessons/flashing-heart-0.png) + +## 3.Write the code for a forever loop and show LEDS for these images! + +![](/static/mb/lessons/snowflake-fall-0.png) + +![](/static/mb/blocks/lessons/snowflake-fall-5.png) + +## 4. Write the code for a forever loop and show LEDS for these images! + +![](/static/mb/lessons/snowflake-fall-1.png) + +![](/static/mb/lessons/snowflake-fall-2.png) + +![](/static/mb/blocks/lessons/snowflake-fall-6.png) + diff --git a/docs/lessons/snowflake-fall/quiz.md b/docs/lessons/snowflake-fall/quiz.md new file mode 100644 index 00000000..cbd997c5 --- /dev/null +++ b/docs/lessons/snowflake-fall/quiz.md @@ -0,0 +1,36 @@ +# snowflake fall blocks quiz + +Create a snowflake fall animation + +## Name + +## Directions + +Use the hints in the [snowflake fall activity](/microbit/lessons/snowflake-fall/activity) to answer this quiz! + +## 1. What is a forever loop? + +
+ +## 2. Draw the picture that will be produced with this code + +![](/static/mb/blocks/lessons/snowflake-fall-4.png) + +![](/static/mb/empty-microbit.png) + +
+ +## 3. Write the code for a forever loop and show LEDS for these images! + +![](/static/mb/lessons/snowflake-fall-0.png) + +
+ +## 4. Write the code for a forever loop and show LEDS for these images! + +![](/static/mb/lessons/snowflake-fall-1.png) + +![](/static/mb/lessons/snowflake-fall-2.png) + +
+ diff --git a/docs/lessons/spinner.md b/docs/lessons/spinner.md new file mode 100644 index 00000000..eb0d8d9f --- /dev/null +++ b/docs/lessons/spinner.md @@ -0,0 +1,93 @@ +# spinner lesson + +a spin the BBC micro:bit game with the input on shake #button #pressed #math #random #var #string #if #docs + +### @video td/videos/spinner-0 + +## Topic + +If (Conditionals) + +## Quick Links + +* [activity](/microbit/lessons/spinner/activity) +* [challenges](/microbit/lessons/spinner/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use an if statement 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 + +* **If** : [read more...](/microbit/blocks/if) +* **Variables** : [read more...](/microbit/reference/variables/var) +* **Assignment Operator** : [read more...](/microbit/reference/variables/assign) +* **On Shake** : [read more...](/microbit/reference/input/on-gesture) +* **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 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 + +* 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/spinner/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/spinner/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/spinner/challenges) + diff --git a/docs/lessons/spinner/activity.md b/docs/lessons/spinner/activity.md new file mode 100644 index 00000000..f1f9aaec --- /dev/null +++ b/docs/lessons/spinner/activity.md @@ -0,0 +1,34 @@ +# spinner activity + +Create an arrow that randomly points to a player. + +### ~avatar avatar + +### @video td/videos/spinner-0 + +### ~ + +Welcome! This guided tutorial will teach how to program a script that randomly points to a player. Let's get started! + +Let's begin by adding an `on shake` condition to know when the micro:bit is shaken. + +![](/static/mb/blocks/lessons/spinner-0.jpg) + +Now let's randomly generate a number from 0 to 3 so that we can randomly display an arrow in a given direction. + +![](/static/mb/blocks/lessons/spinner-1.jpg) + +Now let's handle each of the cases by displaying the appropriate arrow. (Let's display an up arrow if `random arrow` is 0. + +![](/static/mb/blocks/lessons/spinner-2.jpg) + +Now let's handle the rest of the cases for `random arrow`. + +![](/static/mb/blocks/lessons/spinner-3.jpg) + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/spinner/challenges)! + +### ~ + diff --git a/docs/lessons/spinner/challenges.md b/docs/lessons/spinner/challenges.md new file mode 100644 index 00000000..6b468fc7 --- /dev/null +++ b/docs/lessons/spinner/challenges.md @@ -0,0 +1,30 @@ +# spinner challenges + +Create an arrow that randomly points to a player. + +## Before we get started + +Complete the following [guided tutorial](/microbit/lessons/spinner/activity), your code should look like this: + +![](/static/mb/blocks/lessons/spinner-3.jpg) + +### Challenge 1 + +Modify the random number generator so that it can include new arrows we will create in the next challenge. + +![](/static/mb/blocks/lessons/spinner-4.jpg) + +* Do **not** run the code yet because it will not work until you have conditions for every random number. + +### Challenge 2 + +Let's add four more arrows that point diagonally. + +![](/static/mb/blocks/lessons/spinner-5.jpg) + +* Run your code to see if it works as expected + +### Challenge 3 + +Add some other arrows if there are more than 8 players. + diff --git a/docs/lessons/stem.md b/docs/lessons/stem.md new file mode 100644 index 00000000..20462cf6 --- /dev/null +++ b/docs/lessons/stem.md @@ -0,0 +1,65 @@ +# Block Editor STEM Lessons + +Overview of Blocks lessons for the BBC micro:bit. #docs #contents + +### @short Lessons + +### ~column + +## Science + +* [Night Light](/microbit/lessons/night-light), dim the LEDs with set brightness +* [Hack your headphones](/microbit/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones +* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits +* [Telegraph](/microbit/lessons/telegraph), play the telegraph game between 2 BBC micro:bits +* [Zoomer](/microbit/lessons/zoomer), measure the force with acceleration +* [Glowing pendulum](/microbit/lessons/glowing-pendulum), construct a pendulum that glows using acceleration + +### ~ + +### ~column + +## Technology + +* [Beautiful Image](/microbit/lessons/beautiful-image), show a beautiful image with show LEDs +* [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 +* [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 +* [Happy birthday](/microbit/lessons/happy-birthday), create a popular song +* [Magic 8](/microbit/lessons/magic-8), a fortune teller game with the BBC micro:bit + +### ~ + +### ~column + +## Engineering + +* [The Watch](/microbit/lessons/the-watch), design and create The Watch +* [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 +* [Beatbox](/microbit/lessons/beatbox), make a beatbox music player with variables +* [Temperature](/microbit/lessons/temperature), get the ambient temperature (degree Celsius °C) + +### ~ + +### ~column + +## Math + +* [Lucky 7](/microbit/lessons/lucky-7), show a number on the LED screen with show number +* [Game Counter](/microbit/lessons/game-counter), displays the player's score with score and add points to score +* [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 +* [Looper](/microbit/lessons/looper), display a series of numbers with a for loop index +* [Strobe light](/microbit/lessons/strobe-light), develop shapes with a nested for loops +* [Digi Yoyo](/microbit/lessons/digi-yoyo), create a counter with a while loop +* [Rotation animation](/microbit/lessons/rotation-animation), control an animation with a boolean variable + +### ~ + diff --git a/docs/lessons/strobe-light.md b/docs/lessons/strobe-light.md new file mode 100644 index 00000000..2a5efdd7 --- /dev/null +++ b/docs/lessons/strobe-light.md @@ -0,0 +1,73 @@ +# strobe light lesson + +Learn how to create a blinking LED script. #LED #screen #plot #docs + +### @video td/videos/strobe-light-0 + +## Topic + +For Loop + +## Quick links + +* [activity](/microbit/lessons/strobe-light/activity) +* [challenges](/microbit/lessons/strobe-light/challenges) + +## Class + +Year 7 + +## Documentation + +* **For Loop**: [read more...](/microbit/reference/loops/for) +* **Plot**: [read more...](/microbit/reference/led/plot) +* **Unplot**: [read more...](/microbit/reference/led/unplot) +* **Pause**: [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to repeat code a fixed number of times +* learn how to turn on a LED light on the LED screen. Specify with LED using x, y coordinates +* learn how to turn off a LED light on the LED screen. Specify which LED which x, y coordinates +* learn how to pause program execution for the specified number of milliseconds + +## 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/strobe-light/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/strobe-light/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/strobe-light/challenges) + diff --git a/docs/lessons/strobe-light/activity.md b/docs/lessons/strobe-light/activity.md new file mode 100644 index 00000000..8ff62a3a --- /dev/null +++ b/docs/lessons/strobe-light/activity.md @@ -0,0 +1,55 @@ +# strobe light activity + +Develop shapes with a for loop. + +### ~avatar avatar + +### @video td/videos/strobe-light-0 + +Welcome! This guided tutorial will teach how to develop shapes with a for loop. Let's get started! + +### ~ + +Create a `for loop` that will loop from 0 to 4 to indicate the x-coordinates of the micro:bit display. + +```blocks +for (let i = 0; i < 5; i++) { + +} + +``` + +Create another for loop that will loop from 0 to 4, indicating the y-coordinates of the micro:bit instead. This for loop will light each LED by column. + + +```blocks +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + + } +} +``` + + +We will light up each LED by plotting them individually. + +```blocks +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + basic.pause(200) + } +} +``` + + +The pause will add a delay between lighting each LED. + +![](/static/mb/blocks/lessons/strobe-light-3.jpg) + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/strobe-light/challenges)! + +### ~ + diff --git a/docs/lessons/strobe-light/challenges.md b/docs/lessons/strobe-light/challenges.md new file mode 100644 index 00000000..963aa35c --- /dev/null +++ b/docs/lessons/strobe-light/challenges.md @@ -0,0 +1,73 @@ +# strobe light challenges + +Coding challenges for strobe light. + +## Before we get started + +Complete the following [guided tutorial](/microbit/lessons/strobe-light/activity), your code should look like this: + + +```blocks +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + basic.pause(200) + } +} +``` + + +### Challenge 1 + +### @video td/videos/strobe-light-1 + +Make the LEDs light up faster by changing the **pause** from 200 to 100 milliseconds: + +```blocks +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + basic.pause(100) + } +} +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +### @video td/videos/strobe-light-2 + +Make the board light up by rows instead of by columns by swapping the `i` and `j` variables in `plot(i, j)`. + +```blocks +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(j, i) + basic.pause(100) + } +} +``` + +* Run the code to see if it works as expected. + +### Challenge 3 + +### @video td/videos/strobe-light-ultimate + +Now that all the LEDs are lit up, let's make them turn off by reversing the strobe light pattern! You can use `unplot` to turn off a single LED. + +```blocks +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(j, i) + basic.pause(100) + } +} +for (let k = 0; k < 5; k++) { + for (let l = 0; l < 5; l++) { + led.unplot(4 - l, 4 - k) + basic.pause(100) + } +} +``` \ No newline at end of file diff --git a/docs/lessons/teach.md b/docs/lessons/teach.md new file mode 100644 index 00000000..52eefe59 --- /dev/null +++ b/docs/lessons/teach.md @@ -0,0 +1,80 @@ +# Teach Blocks + +Overview of lesson instructions for the BBC micro:bit. #docs #contents + +### @short Teach + +The [lessons](/microbit/lessons) promote computational thinking and computer science literacy from an early age and provide opportunities for learning these skills within the context of public and private education, where they will be available to Year 7 students. This page is a 'how to manual' for using the lessons in the classroom. + +### @section full + +## Summary + +The [lessons](/microbit/lessons) promote computational thinking and computer science literacy from an early age and provide opportunities for learning these skills within the context of public education, where they will be available to Year 7 students. You will find comprehensive teacher training and preparation (lesson plans, videos, guided tutorials, quiz, challenges, and quiz answers). The curriculum has been organized for students from Beginner to Advanced lessons in an effort to build student confidence with computational thinking and coding concepts. The lesson has been constructed with a teacher lesson plan, video(s), activity, quiz, challenges, and quiz answers to demonstrate mastery with the Progression Pathways and Computational Thinking Framework. The lesson should occur on-site during a single instructional block. + +## Lesson Resources + +1) Lesson Plan + +The lesson plan maps to the Progressions Pathways, Computing Curriculum, and QuickStart Computing Glossary. The lesson plan explains the concepts being taught for computational thinking while supporting your classroom instruction. A lesson plan also contains Quick Links to the lesson's tutorial, challenges, quiz, and quiz answers as shown in the [blink lesson plan](/microbit/lessons/blink). + +2) Activity + +Expand your knowledge of programming with lots of great step-by-step activities. All the lessons come with instructions that will drive the students to a complete, functional code. These activities are very directive to make sure that students keep progressing. When the activities are over, additional challenges are given to advance code through printed instructions. An activity contains supporting videos as shown with the [blink activity](/microbit/lessons/blink/activity). + +### @video td/videos/blink-0 + +3) Quiz + +Expand your knowledge of computational thinking and computer science literacy with lots of great quizzes. All the tutorials come with quiz questions that will encourage the students to process and evaluate the concepts being introduced throughout the lesson. The quiz questions are mapped to the concepts being introduced in the lesson to make sure that students understand the computer science concepts. Quizzes apply the concepts taught in the tutorial as shown with the [blink quiz](/microbit/lessons/blink/quiz). + +4) Quiz Answers + +The quiz answers provide responses to the quiz. This will allow teachers to accurately review and grade student responses. Please review a sample of the quiz answers provided with the [blink quiz answers](/microbit/lessons/blink/quiz-answers). + +5) Challenges + +After the student completes the quiz, tutorial, and compiles the code onto the BBC micro:bit, distribute the lesson’s challenges. Challenges are additional customizing and exercises for the students. Challenges reinforce the concepts followed in the tutorial and quiz responses as shown with the [blink challenges](/microbit/lessons/blink/challenges). + +## Teacher Directions + +1) Teacher select a lesson from the [lessons](/microbit/lessons) + +2) Print the quiz and the challenges for each student + +3) Print the quiz answers from you + +4) Distribute the printed quiz for every student + +5) Complete quiz questions by following the the guided tutorials + +6) Compile the code from the tutorial onto the BBC micro:bit + +7) Distribute the challenges for additional coding through paper instructions + +## Teacher Supplies + +1) Print: Lesson Quiz (1 copy per student) + +2) Print: Lesson Activity (1 copy per student) + +3) Print: Lesson Challenge (1 copy per student) + +## Lesson Timeline + +``00:00`` Introduce Objectives of Lesson Plan + +``05:00`` Distribute Lesson Quiz + +``07:00`` Access BBC micro:bit website + +``10:00`` Start Lesson Activity & Lesson Quiz + +``30:00`` Finish Lesson Tutorial & Lesson Quiz + +``35:00`` Start Lesson Challenges + +``55:00`` Finish Lesson + +``60:00`` Homework: Complete Challenges + diff --git a/docs/lessons/telegraph.md b/docs/lessons/telegraph.md new file mode 100644 index 00000000..adcd5537 --- /dev/null +++ b/docs/lessons/telegraph.md @@ -0,0 +1,25 @@ +# telegraph lesson + +display beautiful images on the BBC micro:bit #var #pause #docs + +## Topic + +Telegraph + +## Quick Links + +* [activity](/microbit/lessons/telegraph/activity) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to convert your BBC micro:bit into a telegraph using a second BBC micro:bit as well as pin P1, P2, 3V, GND, and crocodile clips (or spring clips). The connect BBC micro:bit uses pins P1, P2, 3V, GND. + +## Objectives + +* learn how to setup the BBC micro:bit with crocodile clips +* learn how to telegraph to another BBC micro:bit + diff --git a/docs/lessons/telegraph/activity.md b/docs/lessons/telegraph/activity.md new file mode 100644 index 00000000..a1222d86 --- /dev/null +++ b/docs/lessons/telegraph/activity.md @@ -0,0 +1,76 @@ +# telegraph activity + +Build a telgraph #microbit #docs + +# micro:bit telegraph + +![](/static/mb/lessons/telegraph-0.png) + +In this project, you will build your telegraph between micro:bits. 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/lessons/ornament-chain-2.png) + +Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the micro:bit. + +### Step 3 + +![](/static/mb/lessons/ornament-chain-3.png) + +Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the micro:bit. + +### Step 4 + +![](/static/mb/lessons/ornament-chain-4.png) + +Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the micro:bit. + +### Step 5 + +![](/static/mb/lessons/ornament-chain-5.png) + +Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd micro:bit. + +### Step 6 + +![](/static/mb/lessons/ornament-chain-6.png) + +Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd micro:bit. + +### Step 7 + +![](/static/mb/lessons/ornament-chain-7.png) + +Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd micro:bit. + +### Step 8 + +![](/static/mb/lessons/ornament-chain-8.png) + +Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd micro:bit + +### Step 9 + +![](/static/mb/lessons/telegraph-0.png) + +Your telegraph is ready! + +### Step 10 + +* Connect the first micro:bit to your computer using your USB cable and run the [telegraph](/microbit/nnudbr) script on it. +* Connect the second micro:bit to your computer using your USB cable and run the [telegraph](/microbit/nnudbr) script on it. +* The first person and second person take turns pressing button A to play the telegraph game! diff --git a/docs/lessons/temperature.md b/docs/lessons/temperature.md new file mode 100644 index 00000000..92ed1d9b --- /dev/null +++ b/docs/lessons/temperature.md @@ -0,0 +1,77 @@ +# temperature blocks lesson + +measure the temperature on the BBC micro:bit #temp #var #docs + +## Topic + +Temperature + +## Quick Links + +* [activity](/microbit/lessons/temperature/activity) +* [challenges](/microbit/lessons/temperature/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit. We will be learning how to get the temperature using on shake, local variables, as well as simple commands such as show number. + +## Documentation + +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **temperature** : [read more...](/microbit/reference/input/temperature) +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **show string** : [read more...](/microbit/reference/basic/show-string) + +## Objectives + +* learn how to create a variable to store data +* learn how to get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit. +* learn how to show a number on the LED screen + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* 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) +* Recognises that different algorithms exist for the same problem (AL) (GE) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(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) +* 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/temperature/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/temperature/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/temperature/challenges) + diff --git a/docs/lessons/temperature/activity.md b/docs/lessons/temperature/activity.md new file mode 100644 index 00000000..63beb8ef --- /dev/null +++ b/docs/lessons/temperature/activity.md @@ -0,0 +1,42 @@ +# temperature activity + +Measure the temperature on the micro:bit + +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 measure the temperature on the micro:bit. Let's get started! + +We want to display the temperature on shake. In order to do so, we need to register the event `on shake` that will execute whenever the user shakes the micro:bit; in the web browser, click the button labelled "SHAKE" under the simulator to generate a shake event + +```blocks +input.onGesture(Gesture.Shake, () => { + +}) +``` + +Let's measure the temperature and then store in it a variable `temp`. The temperature is measured in **Celsius**, so a value of `29` is equivalent to 29 degrees Celsius. + + +```blocks +input.onGesture(Gesture.Shake, () => { + let temp = input.temperature() +}) +``` + +Show the value of `temp` on the screen. + +```blocks +input.onGesture(Gesture.Shake, () => { + let temp = input.temperature() + basic.showNumber(temp) +}) +``` + +* click run to see if the code works as expected. + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/temperature/challenges)! + +### ~ + diff --git a/docs/lessons/temperature/challenges.md b/docs/lessons/temperature/challenges.md new file mode 100644 index 00000000..c81a26cc --- /dev/null +++ b/docs/lessons/temperature/challenges.md @@ -0,0 +1,33 @@ +# temperature challenges + +Coding challenges for zoomer. + +## Before we get started + +Complete the following guided [temperature activity](/microbit/lessons/temperature/activity). At the end of the activity, your code should look like this: + +```blocks +input.onGesture(Gesture.Shake, () => { + let temp = input.temperature() + basic.showNumber(temp) +}) +``` + +### Challenge 1 + +Let's add the code to display the text `C IS THE TEMP` with a `show string` block. Modify the `show string` block to slowly display the text by an interval of `300`. + +```blocks +input.onGesture(Gesture.Shake, () => { + let temp = input.temperature() + basic.showNumber(temp) + basic.showString("C IS THE TEMP") +}) +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +Let's add code to display the temperature gauge image with a `show LEDs` block. + diff --git a/docs/lessons/the-watch.md b/docs/lessons/the-watch.md new file mode 100644 index 00000000..ee108e64 --- /dev/null +++ b/docs/lessons/the-watch.md @@ -0,0 +1,31 @@ +# the watch lesson + +display beautiful images on the BBC micro:bit #var #pause #docs + +![](/static/mb/lessons/the-watch-0.png) + +## Topic + +The Watch + +## Quick Links + +* [activity](/microbit/lessons/the-watch/activity) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to design the BBC micro:bit watch with household supplies. + +## Objectives + +* learn how to design and make the watch with the BBC micro:bit + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/the-watch/activity) + diff --git a/docs/lessons/the-watch/activity.md b/docs/lessons/the-watch/activity.md new file mode 100644 index 00000000..5aad98f1 --- /dev/null +++ b/docs/lessons/the-watch/activity.md @@ -0,0 +1,160 @@ +# The watch activity + +Control images with variables. + +# micro:bit watch + +![](/static/mb/lessons/the-watch-0.png) + +In this project, you will build your own wearable micro:bit watch from an old pair of jeans and T-shirt. Project duration: 15 minutes. + +![](/static/mb/lessons/the-watch-1.png) + +## Materials + +* micro:bit, battery holder and 2 AAA batteries +* Old T-shirt +* Old Jeans +* Velcro with sticky back – 5cm x 5cm +* Double-sided tape – 22cm x 5cm. You can find carpet tape in your local hardware shop +* Ruler and pen +* Scissors + +![](/static/mb/lessons/the-watch-2.png) + +## Steps + +### Step 1 + +![](/static/mb/lessons/the-watch-3.png) + +Using the ruler and pen, mark a rectangle of more or less 26cm x 5cm on the T-shirt. Don’t worry if you don’t get it quite right, we’ll tidy things up later on. + +### Step 2 + +![](/static/mb/lessons/the-watch-4.png) + +Cut the rectangle using the scissors. Don’t worry about the quality of the cut, we’ll trim it later on. + +### Step 3 + +![](/static/mb/lessons/the-watch-5.png) + +Cut a piece of cloth from the pair of jeans. Cut straight by the seam. + +![](/static/mb/lessons/the-watch-6.png) + +### Step 4 + +![](/static/mb/lessons/the-watch-7.png) + +Using the ruler and pen, mark a rectangle of 22cm x 5cm (adults should use 24cm x 5cm) on the jeans cloth. + +### Step 5 + +![](/static/mb/lessons/the-watch-8.png) + +Stretch the cloth using your hands and apply the double-side tape on the rectangle marked on the jeans. You might need the help of a friend to achieve this step. Don’t worry if the tape is larger than the rectangle, we will trim it later. Make sure to apply pressure to the tape to secure it firmly. + +### Step 6 + +![](/static/mb/lessons/the-watch-9.png) + +Using the scissors, cut the rectangle of jeans. + +### Step 7 + +![](/static/mb/lessons/the-watch-10.png) + +Peal the tape protective layer from the rectangle. + +### Step 8 + +![](/static/mb/lessons/the-watch-11.png) + +Place the micro:bit pins on the tape at more or less **7** cm from the left border. Then lower the micro:bit on the tape and press **gently**. + +### Step 9 + +![](/static/mb/lessons/the-watch-12.png) + +Connect the battery holder and place it on the right of the micro:bit. Tuck the cables away on the tape to protect them. + +### Step 10 + +![](/static/mb/lessons/the-watch-13.png) + +Stick the T-shirt rectangle from the top of the micro:bit, over the battery cables. + +### Step 11 + +![](/static/mb/lessons/the-watch-14.png) + +Use your fingers to push the T-shirt cloth under the micro:bit to give access to the micro-USB plug. + +### Step 12 + +![](/static/mb/lessons/the-watch-15.png) + +Place the T-shirt over the battery holder and stick it up to the end. + +### Step 13 + +![](/static/mb/lessons/the-watch-16.png) + +Turn over the watch and cut the extra T-shirt material. + +### Step 14 + +![](/static/mb/lessons/the-watch-17.png) + +Stick the T-shirt cloth on the other side of the watch. Lift the micro:bit pins to slide the cloth under and leave them free from the tape. + +### Step 15 + +![](/static/mb/lessons/the-watch-18.png) + +Turn over the watch and cut left over T-shirt cloth. + +### Step 16 + +![](/static/mb/lessons/the-watch-19.png) + +Cut a 5cm x 5cm square of Velcro **loops**. + +### Step 17 + +![](/static/mb/lessons/the-watch-20.png) + +Cut a 5cm x 5cm square of Velcro **hooks**. + +### Step 18 + +![](/static/mb/lessons/the-watch-21.png) + +Stick the Velcro hooks on the right side of the battery holder on the T-shirt cloth. + +### Step 19 + +![](/static/mb/lessons/the-watch-22.png) + +Stick the Velcro loops on the other end on the jeans fabric. + +### Step 20 + +Trim any leftover fabric, threads or tape. + +### Step 21 + +![](/static/mb/lessons/the-watch-23.png) + +Your watch is ready! + +### Step 22 + +Connect your micro:bit to your computer using your USB cable and upload the [rock paper scissors](/microbit/rrwupw) script on it. Shake your watch to play against... the micro:bit! + +### Acknowledgements + +Artistic design by Melinda Hoeneisen. + diff --git a/docs/lessons/truth-or-dare.md b/docs/lessons/truth-or-dare.md new file mode 100644 index 00000000..06029fb1 --- /dev/null +++ b/docs/lessons/truth-or-dare.md @@ -0,0 +1,81 @@ +# truth or dare lesson + +create a love meter with the BBC micro:bit #button #pressed #math #random #var #string #if #docs + +### @video td/videos/truth-or-dare-0 + +## Topic + +If (Conditionals) + +## Quick Links + +* [activity](/microbit/lessons/truth-or-dare/activity) +* [challenges](/microbit/lessons/truth-or-dare/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use an if statement to run code run code depending on whether a condition is true or not. We will be learning how to create the game truth or dare using input an if statement, a local variable, math random as well as simple commands, such as show string and show LEDs. + +## Documentation + +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **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) +* **pick random** : [read more...](/microbit/blocks/math) +* **If** : [read more...](/microbit/blocks/if) +* **show string** : [read more...](/microbit/reference/basic/show-string) + +## Objectives + +* learn how to display an image on the BBC micro:bit +* learn how to run code when an input button is pressed +* learn how to a create a variable for a place where you can store and retrieve data +* 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 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 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 + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/truth-or-dare/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/truth-or-dare/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/truth-or-dare/challenges) + diff --git a/docs/lessons/truth-or-dare/activity.md b/docs/lessons/truth-or-dare/activity.md new file mode 100644 index 00000000..d0f7a1c4 --- /dev/null +++ b/docs/lessons/truth-or-dare/activity.md @@ -0,0 +1,98 @@ +# truth or dare activity + +A multi-player game that forces each player to reveal a secret or something funny. + +### ~avatar avatar + +### @video td/videos/truth-or-dare-0 + +Welcome! This tutorial will teach how to program a game of truth or dare on the micro:bit. Let's get started! + +### ~ + +Begin by using Show LEDs to create an "up-arrow" image, which will point to someone. + +```blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) + +``` + +Now let's create a condition to know when button `A` is pressed so that we can display "truth" or "dare" on the micro:bit. We want the BBC micro:bit to randomly choose whether to display "truth" or display "dare". We can use accomplish this by using `pick random (1)`. + +```blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +input.onButtonPressed(Button.A, () => { + let random = Math.random(2) +}) +``` + +Now let's display the appropriate message for each scenario of `random`. + +```blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +input.onButtonPressed(Button.A, () => { + let random = Math.random(2) + if (random == 0) { + basic.showString("TRUTH") + } else { + basic.showString("DARE") + } +}) +``` + + + +Notice how the arrow didn't display again after pressing button `A`. Let's add a line of code that displays the arrow again. + +```blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +input.onButtonPressed(Button.A, () => { + let random = Math.random(2) + if (random == 0) { + basic.showString("TRUTH") + } else { + basic.showString("DARE") + } + basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +}) + +``` + +* Run your program: Press button A! + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/truth-or-dare/challenges)! + +### ~ + diff --git a/docs/lessons/truth-or-dare/challenges.md b/docs/lessons/truth-or-dare/challenges.md new file mode 100644 index 00000000..cc5ca31a --- /dev/null +++ b/docs/lessons/truth-or-dare/challenges.md @@ -0,0 +1,104 @@ +# truth or dare challenges + +A multi-player game that forces each player to reveal a secret or something funny. + +## Before we get started + +Complete the following [guided tutorial](/microbit/lessons/truth-or-dare/activity), and your code should look like this + + +```blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +input.onButtonPressed(Button.A, () => { + let random = Math.random(2) + if (random == 0) { + basic.showString("TRUTH") + } else { + basic.showString("DARE") + } + basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +}) +``` + +### Challenge 1 + +Let's make the word "DARE" appear a little more often than "TRUTH". Change the line of code with `pick random (1)` to `pick random (2)`. + +```blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +input.onButtonPressed(Button.A, () => { + let random = Math.random(3) + if (random == 0) { + basic.showString("TRUTH") + } else { + basic.showString("DARE") + } + basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +}) +``` + + +### Challenge 2 + +Instead of just saying "TRUTH" or "DARE", let's sometimes say "SKIP". This would allow the skipped person to spin the micro:bit without completing a truth or dare. Modify the if statement as shown. + +``` blocks +basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +input.onButtonPressed(Button.A, () => { + let random = Math.random(2) + if (random == 1) { + basic.showString("TRUTH") + } else if (random == 0) { + basic.showString("DARE") + } else { + basic.showString("SKIP") + } + basic.showLeds(` + . . # . . + . # # # . + # # # # # + . . # . . + . . # . . + `) +}) + +``` + + + +* Run your code to see if it works as expected + +### Challenge 3 + +Add some other messages, such as "TWO DARES" for the micro:bit to show. You will need to modify the parameter inside `pick random (3)` as well as adding another `if` condition. + diff --git a/docs/lessons/variables.md b/docs/lessons/variables.md new file mode 100644 index 00000000..ac4c0607 --- /dev/null +++ b/docs/lessons/variables.md @@ -0,0 +1,38 @@ +# Blocks - Variables + +An introduction to variables for the Block Editor. #docs + +## What is a variable? + +Variables are things that are remembered by the BBC micro:bit. Variables can take a few formats and can have functions applied to them. For example, we could create a string, which is text. Or we could create a calculator that stores whichever number the user inputs as an integer, or whole number. + +We can modify variables but they must first be defined. Open the ‘Variables’ drawer to the left of your code. + +In the variables section you will see two blocks: `set item` and `item`. The set item block allows you to set a variable to another value or create a new variable. + +Drag the `set item` block into your code. Click the little arrow next to the word `item` and select **New Variable**, enter **value** as the name. You have now created a new variable called value, however you must set an initial value. Go to the **Maths** drawer and drag a `0` block, connecting it to the empty socket in the `set` value block. Your code should look like this: + +![](/static/mb/blocks/lessons/variables-0.png) + +## Using Variables + +We can also set value to something else using this line. For example, we could use the functions in the **Maths** drawer to set value to a new value. If we combine this with the `forever` loop and if statements from the previous page then we can create a counter: + +![](/static/mb/blocks/lessons/variables-1.png) + +Drag a `forever` block from the **Basic** drawer and add an `if` block from the **If** drawer. Attach the ‘button pressed’ block from the ‘Input’ drawer. + +Drag another `set item` block from the **Variables** draw and click the **down arrow** next to item, however this time select **value**, we don’t have to declare it again as we have already created it. Open the **Maths** drawer and drag a `+` block before clicking it into place in the `set` value block. Drag an `item` block from the **Variables** drawer and again click the **down arrow** before selecting **value**. Add a `0` from the **Maths** drawer and change the value from **0** to **1**. + +Finally, beneath that line, drag a `show number` block from the **Basic** drawer, and drag out the `0`. Drag another variable block from the **Variables** drawer, change it to `value`, and drop this into the space. + +### What does this code do? + +* We create a new variable called value and set it to 0 +* The code runs forever and waits for the user to press the A button +* When the user does, value will be set to value + 1 (value will be incremented by 1) +* Value will then be displayed on the BBC micro:bit's LEDS +* This effectively creates a counter + +Variables can also be used for conditions with loops. See the 'Loops' section to learn about this. + diff --git a/docs/lessons/zoomer.md b/docs/lessons/zoomer.md new file mode 100644 index 00000000..e92ba2e9 --- /dev/null +++ b/docs/lessons/zoomer.md @@ -0,0 +1,84 @@ +# zoomer blocks lesson + +measure the acceleration on the micro:bit in the "z" direction #acceleration #var #docs #if #show + +### @video td/videos/zoomer-0 + +## Topic + +Acceleration + +## Quick Links + +* [activity](/microbit/lessons/zoomer/activity) +* [challenges](/microbit/lessons/zoomer/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to get the **acceleration**, `acceleration` in one of three specified dimensions. We will be learning how to get the acceleration using a forever loop, local variables, input on button pressed, as well as simple commands, such as show number and pause. + +## Documentation + +* **forever** : [read more...](/microbit/reference/basic/forever) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **acceleration** : [read more...](/microbit/reference/input/acceleration) +* **if** : [read more...](/microbit/reference/logic/if) +* **button is pressed** : [read more...](/microbit/reference/input/button-is-pressed) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Objectives + +* learn how to repeat code in the background forever +* learn how to create a variable to store data +* learn how to get the acceleration value (g-force), in one of three specified dimensions +* 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 get the state of an input button +* learn how to show a number 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 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) +* 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) + +#### 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/zoomer/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/zoomer/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/zoomer/challenges) + diff --git a/docs/lessons/zoomer/activity.md b/docs/lessons/zoomer/activity.md new file mode 100644 index 00000000..142c8d9b --- /dev/null +++ b/docs/lessons/zoomer/activity.md @@ -0,0 +1,45 @@ +# zoomer block activity + +Measure the acceleration on the micro:bit in the "z" direction. + +### ~avatar avatar + +### @video td/videos/zoomer-0 + +### ~ + +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 measure the acceleration on the micro:bit in the "z" direction. Let's get started! + +We want to display the acceleration forever. In order to do so, we need a `forever` loop. + +```blocks +basic.forever(() => { + +}) +``` + +Let's measure the acceleration and then store in it a variable `az`. The acceleration is measured in **milli-gravities**, so a value of `-1000` is equivalent to `-1g` or `-9.81m/s^2`. + +```blocks +basic.forever(() => { + let az = input.acceleration(Dimension.Z) +}) +``` + +Show the value of `az` on the screen. + +```blocks +basic.forever(() => { + let az = input.acceleration(Dimension.Z) + basic.showNumber(az) +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/zoomer/challenges)! + +### ~ + diff --git a/docs/lessons/zoomer/challenges.md b/docs/lessons/zoomer/challenges.md new file mode 100644 index 00000000..3ccb4ec8 --- /dev/null +++ b/docs/lessons/zoomer/challenges.md @@ -0,0 +1,37 @@ +# zoomer blocks challenges + +Coding challenges for zoomer. + +## Before we get started + +Complete the following [activity](/microbit/lessons/zoomer/activity) and your finished code should look like this: + +```blocks +basic.forever(() => { + let az = input.acceleration(Dimension.Z) + basic.showNumber(az) +}) +``` +### Challenge 1 + +### @video td/videos/zoomer-2 + +We'll modify the code to display the `x` acceleration if the `A` button is pressed. For that, we need to store `acceleration (x)` in a new variable `ax` and use a `button (A) is pressed` to detect if the button is pressed. + +```blocks +basic.forever(() => { + let az = input.acceleration(Dimension.Z) + let ax = input.acceleration(Dimension.X) + if (input.buttonIsPressed(Button.A)) { + basic.showNumber(ax) + } + basic.showNumber(az) +}) +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +Display the `y` acceleration when `B` is pressed by adding another `if` statement using `button (B) is pressed`. + diff --git a/docs/reference.md b/docs/reference.md new file mode 100644 index 00000000..a0e54c43 --- /dev/null +++ b/docs/reference.md @@ -0,0 +1,460 @@ +# Reference + +### @section full + +### ~column + +### Basic + +[show number](/microbit/reference/basic/show-number) + +~~~~block +basic.showNumber(2) +~~~~ + +[show string](/microbit/reference/basic/show-string) + +~~~~block +basic.showString('Hello!') +~~~~ + +[show LEDs](/microbit/reference/basic/show-leds) + +~~~~block +basic.showLeds(`. . . . . +. # . # . +. . . . . +# . . . # +. # # # .`) +~~~~ + +[clear screen](/microbit/reference/basic/clear-screen) + +~~~~block +basic.clearScreen() +~~~~ + +[forever](/microbit/reference/basic/forever) + +~~~~block +basic.forever(() => { }) +~~~~ + +[pause](/microbit/reference/basic/pause) + +```block +basic.pause(200) +``` + +### Input + +[on button pressed](/microbit/reference/input/on-button-pressed) + +```block +input.onButtonPressed(Button.A, () => {}) +``` + +[on pin pressed](/microbit/reference/input/on-pin-pressed) + +```block +input.onPinPressed(TouchPin.P0, () => {}) +``` + +[on shake](/microbit/reference/input/on-shake) + +![](/static/mb/blocks/contents-22.jpg) + +[on logo up](/microbit/reference/on-logo-up) + +![](/static/mb/on-logo-up-0.jpg) + +[on logo down](/microbit/reference/on-logo-down) + +![](/static/mb/on-logo-down-0.jpg) + +[on screen up](/microbit/reference/on-screen-up) + +![](/static/mb/on-screen-up-0.jpg) + +[on screen down](/microbit/reference/on-screen-down) + +![](/static/mb/on-screen-down-0.jpg) + +[button is pressed](/microbit/reference/button-is-pressed) + +![](/static/mb/button-is-pressed-0.png) + +[compass heading](/microbit/reference/compass-heading) + +![](/static/mb/compass-heading-0.png) + +[temperature](/microbit/reference/temperature) + +![](/static/mb/temperature-0.png) + +[acceleration](/microbit/reference/input/acceleration) + +![](/static/mb/acceleration-0.png) + +[rotation](/microbit/reference/rotation) + +![](/static/mb/rotation-0.png) + +[magnetic force](/microbit/reference/magnetic-force) + +![](/static/mb/magnetic-force-0.png) + +[running time](/microbit/reference/running-time) + +![](/static/mb/running-time-0.png) + +### Loops + +[for](/microbit/reference/loops/for) + +```block +for(let i = 0;i<5;i++) {} +``` + +[repeat](/microbit/reference/loops/repeat) + +![](/static/mb/blocks/contents-0.png) + +[while](/microbit/reference/loops/while) + +```block +while(true) {} +``` + +[forever](/microbit/reference/basic/forever) + +```block +basic.forever(() => {}) +``` + + + +### ~ + +### ~column + +### Logic + +[if](/microbit/reference/logic/if) + +```block +if(false) { +} +``` + +[Boolean](/microbit/reference/types/boolean) values: *true*; *false* + +```block +true +false +``` + +Boolean binary operators: *and* (conjunction); *or* (disjunction) + +```block +true && false; +true || false; +``` + +Boolean negation operator + +```block +!true +``` + +Comparison operators (=, !=, <, >, <=, >=) + +```block +0 == 0; +1 !- 0; +0 < 1; +1 > 0; +0 <= 1; +1 >= 0; +``` + +### Variables + +[Assign](/microbit/reference/variables/assign) (set) a variable's value + +```block +let x = 0; +``` + +Get a variable's value + +```block +let x = 0; +x; +``` + +[Change](/microbit/reference/variables/change-var) a variable's value + +```block +let x = 0; +x+=1; +``` + +### Math + +[Numeric](/microbit/reference/types/number) values: 0, 1, 2, ... + +```block +0; +1; +2; +``` + +Arithmetic binary operation (+, -, *, /) + +```block +0+1; +0-1; +1*2; +3/4; +``` + +Absolute value + +```block +Math.abs(-5); +``` + +Minimum/maximum of two values + +```block +Math.min(0, 1); +Math.max(0, 1); +``` + +Random value + +```block +Math.random(5); +``` + +### LED + +[plot](/microbit/reference/led/plot) + +```block +led.plot(2,2) +``` + +[unplot](/microbit/reference/led/unplot) + +```block +led.unplot(2,2) +``` + +[point](/microbit/reference/point) + +```block +led.point(2,2) +``` + +[brightness](/microbit/reference/brightness) + +```block +led.brightness() +``` + +[set brightness](/microbit/reference/set-brightness) + +```block +led.setBrightness(255) +``` + +[stop animation](/microbit/reference/stop-animation) + +```block +led.stopAnimation() +``` + +[plot bar graph](/microbit/reference/led/plot-bar-graph) + +```block +led.plotBarGraph(0, 1023) +``` + +### Game + +[create sprite](/microbit/reference/game/create-sprite) + +![](/static/mb/create-sprite-0.png) + +[move](/microbit/reference/game/move) + +![](/static/mb/game-library/move-0.png) + +[turn](/microbit/reference/game/turn) + +![](/static/mb/game-library/turn-0.png) + +[change](/microbit/reference/game/change) + +![](/static/mb/change-0.png) + +[set](/microbit/reference/game/set) + +![](/static/mb/blocks/contents-21.png) + +[reports](/microbit/reference/reports) + +![](/static/mb/game-library/position-0.png) + +[touching](/microbit/reference/touching) + +![](/static/mb/game-library/touching-0.png) + +[touching edge](/microbit/reference/touching-edge) + +![](/static/mb/game-library/touching-edge-0.png) + +[if on edge, bounce](/microbit/reference/logic/if-on-edge-bounce) + +![](/static/mb/game-library/if-on-edge-bounce-0.png) + +[change score by](/microbit/reference/change-score-by) + +![](/static/mb/game-library/pic1.png) + +[score](/microbit/reference/score) + +![](/static/mb/game-library/pic2.png) + +[start countdown](/microbit/reference/start-countdown) + +![](/static/mb/game-library/pic3.png) + +[game over](/microbit/reference/game-over) + +![](/static/mb/game-library/pic0.png) + +### Music + +[play tone](/microbit/reference/play-tone) + +![](/static/mb/play-tone-0.jpg) + +[ring tone](/microbit/reference/ring-tone) + +![](/static/mb/ring-tone-0.jpg) + +[rest](/microbit/reference/rest) + +![](/static/mb/rest-0.jpg) + +[tempo](/microbit/reference/tempo) + +![](/static/mb/tempo-0.jpg) + +[set tempo](/microbit/reference/set-tempo) + +![](/static/mb/change-tempo-0.jpg) + +[change tempo](/microbit/reference/music/set-tempo) + +![](/static/mb/change-tempo-by-0.jpg) + +### Comments + +[comment](/microbit/reference/comment) + +### Images + +[show image](/microbit/reference/show-image) + +![](/static/mb/show-image-0.png) + +[scroll image](/microbit/reference/scroll-image) + +![](/static/mb/scroll-image-0.png) + +[create image](/microbit/reference/create-image) + +![](/static/mb/create-image-0.png) + + +### ~ + +### ~column + +### Pins + +[digital read pin](/microbit/reference/pins/digital-read-pin) + +![](/static/mb/digital-read-pin-0.png) + +[digital write pin](/microbit/reference/pins/digital-write-pin) + +![](/static/mb/digital-write-pin-0.png) + +[analog read pin](/microbit/reference/pins/analog-read-pin) + +![](/static/mb/analog-read-pin-0.png) + +[analog write pin](/microbit/reference/pins/analog-write-pin) + +![](/static/mb/blocks/contents-23.png) + +[analog set period](/microbit/reference/pins/analog-set-period) + +![](/static/mb/analog-set-period-0.png) + +[servo write pin](/microbit/reference/pins/servo-write-pin) + +![](/static/mb/servo-write-pin-0.png) + +[servo set pulse](/microbit/reference/pins/servo-set-pulse) + +![](/static/mb/servo-set-pulse-0.png) + +[map](/microbit/reference/map) + +![](/static/mb/map-0.png) + + +## Devices + +Functions in this category require to be connected to a remote device. + +[tell camera to](/microbit/reference/devices/tell-camera-to) + +![](/static/mb/tell-camera-to-0.png) + +[tell remote control to](/microbit/reference/devices/tell-remote-control-to) + +![](/static/mb/tell-remote-control-to-0.png) + +[raise alert to](/microbit/reference/devices/raise-alert-to) + +![](/static/mb/raise-alert-to-0.png) + +[on notified](/microbit/reference/on-notified) + +![](/static/mb/on-notified-0.png) + +[on gamepad button](/microbit/reference/on-gamepad-button) + +![](/static/mb/on-gamepad-button-0.png) + +[on notified](/microbit/reference/on-notified) + +![](/static/mb/on-notified-0.png) + +[signal strength](/microbit/reference/signal-strength) + +![](/static/mb/blocks/contents-24.png) + +[on signal strength changed](/microbit/reference/on-signal-strength-changed) + +![](/static/mb/blocks/contents-25.png) + +### ~ + diff --git a/docs/reference/basic/clear-screen.md b/docs/reference/basic/clear-screen.md new file mode 100644 index 00000000..dc43cc6c --- /dev/null +++ b/docs/reference/basic/clear-screen.md @@ -0,0 +1,31 @@ +# Clear Screen + +Turn off all the LED lights on the [LED screen](/microbit/device/screen). + +```sig +basic.clearScreen() +``` + +### Example: vanishing heart + +The following code displays a heart on the screen and then turns off all the LED lights using `clear screen`: + +```blocks +basic.showLeds(` +. # . # . +# # # # # +# # # # # +. # # # . +. . # . . +`) +basic.clearScreen() +``` + +### Lessons + +[blink](/microbit/lessons/blink), [flashing heart](/microbit/lessons/flashing-heart), [screen wipe](/microbit/lessons/screen-wipe) + +### See also + +[set brightness](/microbit/reference/led/set-brightness), [unplot](/microbit/reference/led/unplot), [plot](/microbit/reference/led/plot), [Image](/microbit/reference/image/image), [clear](/microbit/reference/basic/clear-screen) + diff --git a/docs/reference/basic/forever.md b/docs/reference/basic/forever.md new file mode 100644 index 00000000..e1a5f063 --- /dev/null +++ b/docs/reference/basic/forever.md @@ -0,0 +1,65 @@ +# Forever + +Repeat code [in the background](/microbit/reference/control/in-background) forever. + +```sig +basic.forever(() => { +}) +``` + +### Example: compass + +The following example constantly checks the [compass heading](/microbit/reference/input/compass-heading) and updates the screen with the direction. + +```blocks +basic.forever(() => { + let heading = input.compassHeading() + if (heading < 45) { + basic.showString("N", 100) + } else if (heading < 135) { + basic.showString("E", 100) + } + else if (heading < 225) { + basic.showString("S", 100) + } + else { + basic.showString("W", 100) + } +}) +``` + +### Example: counter + +The following example continually shows the current value of a global variable: + +```blocks +let num = 0 +basic.forever(() => { + basic.showNumber(num, 150) +}) +input.onButtonPressed("A", () => { + num = num + 1 +}) +``` + +### Contention for the LED display + +If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example: + +```blocks +basic.forever(() => { + basic.showNumber(6789, 150) +}) +input.onButtonPressed(Button.A, () => { + basic.showNumber(2, 150) +}) +``` + +### Lessons + +[blink](/microbit/lessons/blink), [bounce-image](/microbit/lessons/bounce-image), [snowflake-fall](/microbit/lessons/snowflake-fall), [flashing-heart](/microbit/lessons/flashing-heart) + +### See also + +[while](/microbit/js/while), [on button pressed](/microbit/reference/input/on-button-pressed), [in background](/microbit/reference/control/in-background) + diff --git a/docs/reference/basic/pause.md b/docs/reference/basic/pause.md new file mode 100644 index 00000000..0caa8ee6 --- /dev/null +++ b/docs/reference/basic/pause.md @@ -0,0 +1,31 @@ +# Pause + +Pause program execution for the specified number of milliseconds. This function is helpful when you need to slow down your program's execution. + +```sig +basic.pause(400) +``` + +### Parameters + +* ``ms`` - the number of milliseconds that you want to pause (100 = 1/10 second, 1000 milliseconds = 1 second) + +### Example: diagonal line + +The following example code turns on LED `0, 0` thru `4, 4`, pausing 500 milliseconds after each LED. Without `pause`, the code would run so fast that you wouldn't see each individual LED turning on. + +```blocks +for (let i = 0; i < 5; i++) { + led.plot(i, i) + basic.pause(500) +} +``` + +### Lessons + +[blink](/microbit/lessons/blink), [lucky 7](/microbit/lessons/lucky-7), [smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart) + +### See also + +[while](/microbit/js/while), [running time](/microbit/reference/input/running-time), [for](/microbit/reference/loops/for) + diff --git a/docs/reference/basic/show-animation.md b/docs/reference/basic/show-animation.md new file mode 100644 index 00000000..966df578 --- /dev/null +++ b/docs/reference/basic/show-animation.md @@ -0,0 +1,61 @@ +# Show Animation + +Show a series of image frames on the [LED screen](/microbit/device/screen), pausing the specified time after each frame. + +```sig +basic.showAnimation(` +. . # . . . # # # . . # # # . +. # # . . . . . # . . . . # . +. . # . . . . # . . . # # # . +. . # . . . # . . . . . . # . +. . # . . . # # # . . # # # . +`) +``` + +### Parameters + +* `leds` - [String](/microbit/reference/types/string); a series of LED on/off states +* `interval` - [Number](/microbit/reference/types/number); the number of milliseconds to pause after each image frame + +### Show a series of image frames + +``` +basic.showAnimation(` +. . # . . . # # # . . # # # . +. # # . . . . . # . . . . # . +. . # . . . . # . . . # # # . +. . # . . . # . . . . . . # . +. . # . . . # # # . . # # # . +`) +``` + +### ~hint + +If the series of images appear too fast, increase the value of the *interval* parameter. + +### ~ + +### Example: animating frames + +The following example creates an image with six frames and then shows each frame o the screen, pausing 500 milliseconds after each frame: + +``` +basic.showAnimation(` +. . . . . # . . . . . . . . . . . . . # . . . . . # . . . . +. . # . . . . . . . . . # . . . . . . . . . # . . . . . . . +. # . # . . . # . . . # . # . . . # . . . # . # . . . # . . +. . # . . . . . . . . . # . . . . . . . . . # . . . . . . . +. . . . . . . . . # . . . . . # . . . . . . . . . . . . . # +`, 500) +``` + +### ~hint + +Use [forever](/microbit/reference/basic/forever) to continually repeat an animation + +### ~ + +### Lessons + +[smiley](/microbit/lessons/smiley), [bounce image](/microbit/lessons/bounce-image), [snowflake fall](/microbit/lessons/snowflake-fall), [rotation animation](/microbit/lessons/rotation-animation) + diff --git a/docs/reference/basic/show-leds.md b/docs/reference/basic/show-leds.md new file mode 100644 index 00000000..6f6e7993 --- /dev/null +++ b/docs/reference/basic/show-leds.md @@ -0,0 +1,45 @@ +# Show LEDs + +Display an image on the BBC micro:bit's [LED screen](/microbit/device/screen). + +```sig +basic.showLeds(` + . . . . . + . # . # . + . . # . . + # . . . # + . # # # . + ` +) +``` + +### Parameters + +* ``leds`` - a series of LED on/off states that form an image (see steps below) +* (optional) ``ms`` - [Number](/microbit/reference/types/number) - time to wait after displaying image. In blocks, ``ms`` is 400 by default. + +### Example - Block Editor + +1. Open the `basic` category and select the `show leds` blocks. + +```blocks +basic.showLeds(` + # # . # # + # # . # # + . # # # . + . # . # . + . # . # . + ` +) +``` + +In JavaScript, the led off is represented by a `.` and the led on by a `#` character. + +### Lessons + +[smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart), [magic logo](/microbit/lessons/magic-logo) + +### See also + +[plot leds](/microbit/reference/led/plot-leds), [show animation](/microbit/reference/led/show-animation) + diff --git a/docs/reference/basic/show-number.md b/docs/reference/basic/show-number.md new file mode 100644 index 00000000..bf423499 --- /dev/null +++ b/docs/reference/basic/show-number.md @@ -0,0 +1,52 @@ +# Show Number + +Show a number on the [LED screen](/microbit/device/screen), one digit at a time (scrolling from left to right) + +~~~~sig +basic.showNumber(2, 150) +~~~~ + +### Parameters + +* value - a [Number](/microbit/reference/types/number) +* (optional) interval (ms) - [Number](/microbit/reference/types/number); the time (in milliseconds) before scrolling by one LED; the larger the number, the slower the scroll + +### ~ + +To display the number 10: + +~~~~blocks +basic.showNumber(10) +~~~~ + +To display the number stored in the `x` variable: + +~~~~blocks +let x = 1 +basic.showNumber(x) +~~~~ + +### Example: count to 5 + +This example uses a [for](/microbit/reference/loops/for) loop to show numbers ``1`` through ``5`` on the screen: + +~~~~blocks +for (let i = 0; i < 5; i++) { + basic.showNumber(i + 1) + basic.pause(200) +} +~~~~ + +### Other show functions + +* use [show string](/microbit/reference/basic/show-string) to show a string on the screen +* use [show animation](/microbit/reference/basic/show-animation) to show a series of images on the screen + +### Lessons + +* [lucky 7](/microbit/lessons/lucky-7) + +### See also + +[show string](/microbit/reference/basic/show-string), [show animation](/microbit/reference/basic/show-animation), [Number](/microbit/reference/types/number), [math library](/microbit/js/math) + diff --git a/docs/reference/basic/show-string.md b/docs/reference/basic/show-string.md new file mode 100644 index 00000000..8fa834d6 --- /dev/null +++ b/docs/reference/basic/show-string.md @@ -0,0 +1,41 @@ +# Show String + +Show a string on the [LED screen](/microbit/device/screen) one character at a time (scrolling from left to right). + +```sig +basic.showString("Hello!") +``` + +### Parameters + +* `text` - a [String](/microbit/reference/types/string) +* (optional) `ms` - [Number](/microbit/reference/types/number); the time (in milliseconds) before scrolling left by one LED; the larger the number, the slower the scroll + +### Examples: + +To display Hello: + +```blocks +basic.showString("Hello") +``` + +To display the content of a string variable: + +```blocks +let s = "Hi" +basic.showString(s) +``` + +### Other show functions + +* use [show number](/microbit/reference/basic/show-number) to show a number on the screen +* use [show animation](/microbit/reference/basic/show-animation) to show a series of images on the screen + +### Lessons + +[answering machine](/microbit/lessons/answering-machine), [rock paper scissors](/microbit/lessons/rock-paper-scissors), [love meter](/microbit/lessons/love-meter), [digital pet](/microbit/lessons/digital-pet) + +### See also + +[String](/microbit/reference/types/string), [string functions](/microbit/reference/types/string-functions), [show number](/microbit/reference/basic/show-number), [show animation](/microbit/reference/basic/show-animation) + diff --git a/docs/reference/blocks-vs-js.md b/docs/reference/blocks-vs-js.md new file mode 100644 index 00000000..e119abff --- /dev/null +++ b/docs/reference/blocks-vs-js.md @@ -0,0 +1,141 @@ +# From Block Editor to Touch Develop + +#docs + +The Block Editor and Touch Develop programming languages provide similar features, but are not identical in their functionality. This presents a learning opportunity for teachers and students: to understand a few basic concepts and how they are expressed in different programming languages. The objective is to make students better able to navigate the sea of programming languages they will encounter later. + +## Concept 1: Inclusive and exclusive intervals + +In mathematics, numeric intervals are a useful shorthand for expressing a sequence of numbers. For example, the notation [0,9] represents the sequence of ten numbers 0,1,2,3,4,5,6,7,8,9. This is known as an "inclusive" interval because the sequence includes the endpoints of the interval, namely 0 and 9. On the other hand, the interval (0,9) represents the sequence of eight numbers 1,2,3,4,5,6,7,8 and is known as "exclusive". + +In the interval notation, the brackets "[" and "]" represent inclusive endpoints and the parentheses "(" and ")" represent exclusive endpoints. Brackets can be mixed and matched, so [0,9) represents the sequence of nine numbers 0,1,2,3,4,5,6,7,8 while (0,9] represents the sequence of nine numbers 1,2,3,4,5,6,7,8,9. Let's call the former interval "inclusive-exclusive" and the latter interval "exclusive-inclusive". + +### Block Editor for loop uses a 0-based inclusive interval + +Numeric intervals arise in the context of for loops, both in the Block Editor and Touch Develop. Here's a Block Editor for loop to draw a diagonal line from the top-left corner of the [LED screen](/microbit/device/screen) to the bottom-right corner. The loop iteration variable *i* ranges "from 0 to 4": + +![](/static/mb/blocks/to-td-0.png) + +What interval does "from 0 to 4" represent? The answer is the inclusive interval [0,4], meaning that the loop iteration variable `i` will take on the values 0,1,2,3,4 over the *five* iterations of the loop. Experiments have shown that the *inclusive internal* is most familiar to students with no previous programming experience. + +### TouchDevelop for loop uses a 0-based inclusive-exclusive interval + +To achieve the same result in Touch Develop, we write the for loop slightly differently because the upper bound of the 0-based loop is *exclusive* rather than inclusive: + +``` +for (let i = 0; i < 5; i++) { + led.plot(i, i) +} +``` + +If we translated the Block Editor loop directly into Touch Develop, we would have: + +``` +for (let i1 = 0; i1 < 4; i1++) { + led.plot(i1, i1) +} +``` + +which would result in the loop iteration variable taking on values in the interval [0,4), namely 0,1,2,3. + +### ~hint + +The use of an exclusive upper-bound in for loops is standard practice in most programming languages. The basic reason for this is that with a 0-based inclusive lower bound, an exclusive upper bound U conveniently happens to be the length of the sequence represented by [0,U). This, of course, begs the question of why we count by starting with zero (0) in programming whereas we learn to count with one (1) in math. + +### ~ + +## Concept 2: variable scope + +A variable's *scope* is defined by two other concepts: its *lifetime* and *visibility*. Imagine program execution like a timeline with each point in the timeline being a step in the program's execution. + +* A variable's *lifetime* can be thought of as an interval [birth, death) in the program execution during which the variable exists and has a value. Within that interval of the program execution, we say the variable is *alive*. +* A variable is visible if its value can be read/written at a point in program execution. Visibility often is based on program structure and where the current point of program execution is. Imagine program structure like a house with only doors and no windows: if you are outside the house, you cannot see the objects (variables) inside the house - they are not visible to you even though they may exist; however, if you enter the house through the door, you can see the variables inside the house. The house itself may be divided into rooms, each of which defines another space in which certain variables are visible and others are not visible. + +A variable is "in scope" at a program point if it is both alive and visible at that point. A variable is "not in scope" if it is not alive or if it is not visible. + +### The Block Editor has variables with only global scope + +In the Block Editor, all variables are *global* variables, which means that all variables are alive and visible during the entire program execution. Consider the following Block Editor program: + +![](/static/mb/blocks/to-td-1.png) + +This program will draw a diagonal line, wait for one second and then show the value of global variable `i`. What number will be shown on the LED screen? After the fifth iteration of the for loop, the value of variable `i` is 4. At the end of this iteration, the variable `i` is incremented and takes on the value 5. Since 5 is greater than the upper (inclusive) endpoint of 4, the loop terminates with the value of `i` at 5. + +### Problems with global variables: unintended interference + +The Block Editor program belows shows a problem with having only variables with global scope. The intent of the program below is fairly clear: if the user presses button A, slowly draw a diagonal line from top-left to lower-right; if the user presses button B, slowly draw a diagonal line from top-right to lower-left. Pressing both buttons should lead to an X being displayed on the screen. + +![](/static/mb/blocks/to-td-2.png) + +The problem with the above program is that we have two loops using the same global variable *i* as the loop iteration variable. If the user first presses button A and then quickly presses button B, the loops execute concurrently, both reading and writing global variable *i* - this can cause unexpected results (in particular, you won't necessarily end up with an X displayed on the screen). You can see this more clearly by pressing the convert button in the Block Editor and examining the Touch Develop code that implements the Block Editor semantics: + +![](/static/mb/blocks/to-td-3.png) + +### JavaScript has variables with both local and global scope + +In Touch Develop, in contrast to the Block Editor, the for-loop iteration variable has scope that is local to the loop: + +``` +for (let i2 = 0; i2 < 5; i2++) { + led.plot(i2, i2) +} +``` + +This means that: + +1. the loop iteration variable *i* comes into existence just before the loop begins and goes out of existence just after the loop terminates. + +2. the variable `i` only is visible from the code that appears textually between the `do` and `end` keywords of the for loop (this is known as lexical scoping). + +The value of the loop iteration variable is completely determined by the semantics of the for loop. As such, Touch Develop doesn't allow the programmer to overwrite the value of a loop iteration variable, as shown below: + +``` +for (let i3 = 0; i3 < 5; i3++) { + led.plot(i3, i3) + i3 = 42 +} +``` + +### Why is local scope useful? + +Local scope allows you to use the same variable name in different parts of a program without concern about interference (as with variables with global scope). Here's the Touch Develop program that implements the "X" program without interference: + +``` +input.onButtonPressed("A", () => { + for (let i4 = 0; i4 < 5; i4++) { + led.plot(i4, i4) + basic.pause(1000) + } +}) +input.onButtonPressed("B", () => { + for (let i5 = 0; i5 < 5; i5++) { + led.plot(4 - i5, i5) + basic.pause(1000) + } +}) +``` + +Even though the same variable name (i) appears in both loops, these are different variables, each with their own lifetime and visibility (as defined by the for-loop). + +## Concept 3: static types + +A variable has a *static type* if it holds the same kind of value (integer, string, Boolean) everywhere that it is in scope. If a variable can hold values of different types at different program locations, then it does not have a static type. + +### Block Editor blocks not plugged to an event will run + +Blocks not plugged to an event will run. Blocks are running even if they are not inside of an `event`. As shown below, ``show string`` *Hello* will show a string on the LED screen one character at a time (scrolling from left to right). + +![](/static/mb/blocks/to-td-4.png) + +### Google's Blockly variables do not have static types + +In Blockly, a variable can hold different types of values at different program locations. As shown below, the global variable *Count* can be first set to a number and later to a string: + +![](/static/mb/blocks/to-td-5.png) + +### Block Editor and Touch Develop variables have static types + +In the Block Editor (based on Blockly) and Touch Develop, each variable has a static type. This means that some programs don't make sense, such as: + +![](/static/mb/blocks/to-td-6.png) + diff --git a/docs/reference/comment.md b/docs/reference/comment.md new file mode 100644 index 00000000..d1963315 --- /dev/null +++ b/docs/reference/comment.md @@ -0,0 +1,38 @@ +# Comment + +A note in code. #docs #comment #language + +### @parent blocks/statement + +A comment is a line of code that contains text, usually an explanation or a note. All comments are ignored during script execution. + +### Block + +Right click on any block and add a comment + +### ~hint + +To find out how to insert comments using the Blocks editor, see [the Blocks editor](/microbit/blocks/editor). + +### ~ + +### Sample code with comments + +![](/static/mb/blocks/comment-0.png) + +### Commenting out code + +During the debugging process, you may want to comment out a section of your code so that it doesn't run. + +To comment out a block of code: + +1. Right click on any block of code that you want to comment out. + +1. Select add comment + +When you want to uncomment your code, right click the on the comment, and then click delete block. + +### See also + +[Block editor](/microbit/blocks/editor) + diff --git a/docs/reference/control/in-background.md b/docs/reference/control/in-background.md new file mode 100644 index 00000000..cae98c00 --- /dev/null +++ b/docs/reference/control/in-background.md @@ -0,0 +1,55 @@ +# In Background + +Run code in the background as a separate process or thread; for more information on this advanced construct, see [the micro:bit - a reactive system](/microbit/device/reactive). + +``` +control.inBackground(() => { +}) +``` + +### Example + +The example below shows how a background process can be used to display the current value of the global variable `num`, while code (like the `on button pressed` handler) can change the value of the variable. + +``` +let num = 0 +control.inBackground(() => { + while (true) { + basic.showNumber(num, 150) + basic.pause(100) + } +}) +input.onButtonPressed("A", () => { + num++; +}) +``` + +The code below using the `forever` loop is equivalent to the code above + +``` +let num = 0 +basic.forever(() => { + basic.showNumber(num, 150) +}) +input.onButtonPressed("A", () => { + num++; +}) +``` + +### Contention for the LED display + +If you have multiple processes that each show something on the LED screen, you may get unexpected results. Try, for example: + +``` +basic.forever(() => { + basic.showNumber(6789, 150) +}) +input.onButtonPressed("A", () => { + basic.showNumber(2, 150) +}) +``` + +### See also + +[while](/microbit/reference/loops/while), [forever](/microbit/reference/basic/forever), [on button pressed](/microbit/reference/input/on-button-pressed) + diff --git a/docs/reference/control/reset.md b/docs/reference/control/reset.md new file mode 100644 index 00000000..16c985ee --- /dev/null +++ b/docs/reference/control/reset.md @@ -0,0 +1,8 @@ +# Reset + +Reset the BBC micro:bit (as if you pushed the reset button on the back of the device), which causes the program to start again. + +```sig +control.reset() +``` + diff --git a/docs/reference/devices/on-gamepad-button.md b/docs/reference/devices/on-gamepad-button.md new file mode 100644 index 00000000..0f30f2f4 --- /dev/null +++ b/docs/reference/devices/on-gamepad-button.md @@ -0,0 +1,28 @@ +# On Gamepad Button + +Register code to run when the micro:bit receives a command from the paired gamepad. + +## Bluetooth required + +The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). + +The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Block Editor + +![](/static/mb/on-gamepad-button-0.png) + +### KindScript + +``` +export function onGamepadButton(name: string, body:td.Action) +``` + +### Parameters + +* ``body``: Action code to run when the the micro:bit receives a command from the paired gamepad. + +### See Also + +[tell remote control to](/microbit/reference/devices/tell-remote-control-to), [raise alert to](/microbit/reference/devices/raise-alert-to), [on notified](/microbit/reference/devices/on-notified), [signal strength](/microbit/reference/devices/signal-strength), [on signal strength changed](/microbit/reference/devices/on-signal-strength-changed) + diff --git a/docs/reference/devices/on-signal-strength-changed.md b/docs/reference/devices/on-signal-strength-changed.md new file mode 100644 index 00000000..08b20987 --- /dev/null +++ b/docs/reference/devices/on-signal-strength-changed.md @@ -0,0 +1,40 @@ +# On Signal Strength Changed + +The `on signal strength changed` function. #docs #devices #ble + +Register code to run when the signal strength of the paired device changes. + +## Bluetooth required + +The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). + +The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Block Editor + +![](/static/mb/on-signal-strength-changed-0.png) + +### KindScript + +``` +export function onSignalStrengthChanged(body:td.Action) +``` + +### Parameters + +* ``body``: code to run when the signal strength changes. + +### Examples + +Display the signal strength on screen: + +``` +devices.onSignalStrengthChanged(() => { + basic.showNumber(devices.signalStrength(), 150) +}) +``` + +### See Also + +[tell remote control to](/microbit/reference/devices/tell-remote-control-to), [raise alert to](/microbit/reference/devices/raise-alert-to), [on notified](/microbit/reference/devices/on-notified), [signal strength](/microbit/reference/devices/signal-strength) + diff --git a/docs/reference/devices/raise-alert-to.md b/docs/reference/devices/raise-alert-to.md new file mode 100644 index 00000000..f61d8bfe --- /dev/null +++ b/docs/reference/devices/raise-alert-to.md @@ -0,0 +1,68 @@ +# raise alert to + +The raise alert to function. #docs #antenna #ble + +Raise an alert on a remote device. + +## + +The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). + +The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### KindScript + +![](/static/mb/raise-alert-to-0.png) + +### KindScript + +``` +export function raiseAlertTo(event: string) +``` + +### Parameters + +* event - an event identifier + +### Examples + +To tell the connected device to display toast + +``` +devices.raiseAlertTo("display toast") +``` + +To tell the connected device to vibrate + +``` +devices.raiseAlertTo("vibrate") +``` + +To tell the connected device to play a sound + +``` +devices.raiseAlertTo("play sound") +``` + +To tell the connected device to play a ringtone + +``` +devices.raiseAlertTo("play ringtone") +``` + +To tell the connected device to find my phone + +``` +devices.raiseAlertTo("find my phone") +``` + +To tell the connected device to ring alarm + +``` +devices.raiseAlertTo("ring alarm") +``` + +### See also + +[tell remote control to](/microbit/reference/devices/tell-remote-control-to), [tell camera to](/microbit/reference/devices/tell-camera-to), [on notified](/microbit/reference/devices/on-notified) + diff --git a/docs/reference/devices/receive-number.md b/docs/reference/devices/receive-number.md new file mode 100644 index 00000000..4fdf7fa9 --- /dev/null +++ b/docs/reference/devices/receive-number.md @@ -0,0 +1,42 @@ +# Receive Number + +The broadcast function. #docs #ble #radio + +Reads the next radio packet as a number data packet. + +## Important Security Consideration + +The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits. + +This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. + +For serious applications, BLE should be considered a substantially more secure alternative. + +### Block Editor + +![](/static/mb/receive-number-0.png) + +### KindScript + +``` +export function receiveNumber() : number +``` + +### Returns + +* packet - a number received. + +### Examples + +Broadcasts the value of ``acceleration`` x to other micro:bits. + +``` +radio.onDataReceived(() => { + led.plotBarGraph(radio.receiveNumber(), 1023) +}) +``` + +### See also + +[send number](/microbit/reference/radio/send-number), [receive number](/microbit/reference/radio/receive-number), [on data received](/microbit/reference/radio/on-data-received), [set group](/microbit/reference/radio/set-group) + diff --git a/docs/reference/devices/signal-strength.md b/docs/reference/devices/signal-strength.md new file mode 100644 index 00000000..e927baeb --- /dev/null +++ b/docs/reference/devices/signal-strength.md @@ -0,0 +1,40 @@ +# Signal Strength + +The `signal strength` function. #docs #antenna #ble + +Returns the signal strength reported by the paired device from ``0`` (no signal) to ``4`` (full strength). + +## Bluetooth required + +The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). + +The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Block Editor + +![](/static/mb/signal-strength-0.png) + +### KindScript + +``` +export function signalStrength() : number +``` + +### Returns + +* the signal strength from ``0`` (no signal) to ``4`` (full strength). + +### Examples + +Display the signal strength on screen: + +``` +devices.onSignalStrengthChanged(() => { + basic.showNumber(devices.signalStrength(), 150) +}) +``` + +### See Also + +[tell remote control to](/microbit/reference/devices/tell-remote-control-to), [raise alert to](/microbit/reference/devices/raise-alert-to), [on notified](/microbit/reference/devices/on-notified), [on signal strength changed](/microbit/reference/devices/on-signal-strength-changed) + diff --git a/docs/reference/devices/tell-camera-to.md b/docs/reference/devices/tell-camera-to.md new file mode 100644 index 00000000..73fb0cd3 --- /dev/null +++ b/docs/reference/devices/tell-camera-to.md @@ -0,0 +1,80 @@ +# tell camera to + +The tell camera to function. #docs #antenna #ble + +Access the photo/video-taking functionality of a remote device using the ``tell camera to`` function. + +## Bluetooth required + +The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). + +The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Block Editor + +![](/static/mb/tell-camera-to-0.png) + +### KindScript + +``` +export function tellCameraTo(event: string) +``` + +### Parameters + +* event - an event identifier + +### Examples + +To tell the connected device to take a picture: + +``` +devices.tellCameraTo("take photo") +``` + +To tell the connected device to start recording a video + +``` +devices.tellCameraTo("start video capture") +``` + +To tell the connected device to stop recording a video + +``` +devices.tellCameraTo("stop video capture") +``` + +To tell the connected device to toggle front-rear + +``` +devices.tellCameraTo("toggle front-rear") +``` + +To tell the connected device to launch photo mode + +``` +devices.tellCameraTo("launch photo mode") +``` + +To tell the connected device to launch video mode + +``` +devices.tellCameraTo("launch video mode") +``` + +To tell the connected device to stop photo mode + +``` +devices.tellCameraTo("stop photo mode") +``` + +To tell the connected device to stop video mode + +``` +devices.tellCameraTo("stop video mode") +``` + +### See Also + +[tell remote control to](/microbit/reference/devices/tell-remote-control-to), [raise alert to](/microbit/reference/devices/raise-alert-to), [on notified](/microbit/reference/devices/on-notified) + diff --git a/docs/reference/devices/tell-microphone-to.md b/docs/reference/devices/tell-microphone-to.md new file mode 100644 index 00000000..98be644d --- /dev/null +++ b/docs/reference/devices/tell-microphone-to.md @@ -0,0 +1,58 @@ +# tell microphone to + +The tell microphone to function. #docs #antenna #ble + +Access the audio recording capabilities of the device using the ``tell microphone to`` function. + +The functions in the antenna namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Block Editor + +![](/static/mb/tell-microphone-to-0.png) + +### KindScript + +``` +export function tellMicrophoneTo(event: string) +``` + +### Parameters + +* event - an event identifier + +### Event values + +* play +* stop +* pause +* forward +* rewind +* volume up +* volume down +* previous track +* next track + +### Examples + +To tell the connected device to start recording audio + +``` +antenna.tellMicrophoneTo("start capture") +``` + +To tell the connected device to stop recording audio + +``` +antenna.tellMicrophoneTo("stop capture") +``` + +### Other show functions + +* use [tell remote control to](/microbit/reference/devices/tell-remote-control-to) to control presentation of media content +* use [tell camera to](/microbit/reference/devices/tell-camera-to) to control the photo/video recording of connected devices +* use [raise alert to](/microbit/reference/devices/raise-alert-to) to control the microphone of connected devices + +### See also + +[Antenna](/microbit/js/antenna) + diff --git a/docs/reference/devices/tell-remote-control-to.md b/docs/reference/devices/tell-remote-control-to.md new file mode 100644 index 00000000..07fefdee --- /dev/null +++ b/docs/reference/devices/tell-remote-control-to.md @@ -0,0 +1,92 @@ +# tell remote control to + +The tell remote control to function. #docs #antenna #ble + +Control the presentation of media content available on a remote device using the `tell remote control` to function. + +## + +The functions in the ``devices`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). + +The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Block Editor + +![](/static/mb/tell-remote-control-to-0.png) + +### KindScript + +``` +export function tellRemoteControlTo(event: string) +``` + +### Parameters + +* event - an event identifier + +### Event values + +* play +* stop +* pause +* forward +* rewind +* volume up +* volume down +* previous track +* next track + +### Examples + +To tell the connected device to start playing: + +``` +devices.tellRemoteControlTo("play") +``` + +To tell the connected device to stop playing + +``` +devices.tellRemoteControlTo("stop") +``` + +To tell the connected device to go to next track + +``` +devices.tellRemoteControlTo("next track") +``` + +To tell the connected device to go to previous track + +``` +devices.tellRemoteControlTo("previous track") +``` + +To tell the connected device to go forward + +``` +devices.tellRemoteControlTo("forward") +``` + +To tell the connected device to rewind + +``` +devices.tellRemoteControlTo("rewind") +``` + +To tell the connected device volume up + +``` +devices.tellRemoteControlTo("volume up") +``` + +To tell the connected device volume down + +``` +devices.tellRemoteControlTo("volume down") +``` + +### See also + +[tell camera to](/microbit/reference/devices/tell-camera-to), [raise alert to](/microbit/reference/devices/raise-alert-to), [on notified](/microbit/reference/devices/on-notified) + diff --git a/docs/reference/game/change-score-by.md b/docs/reference/game/change-score-by.md new file mode 100644 index 00000000..fd033133 --- /dev/null +++ b/docs/reference/game/change-score-by.md @@ -0,0 +1,43 @@ +# Change Score By + +The game library + +The game library supports simple single-player time-based games. The player will ** add points to score**. + +## Block Editor + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen. + +![](/static/mb/change-score-by-0.png) + +## KindScript + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/change.md b/docs/reference/game/change.md new file mode 100644 index 00000000..7cb09b3c --- /dev/null +++ b/docs/reference/game/change.md @@ -0,0 +1,30 @@ +# Change + +The game library + +### Change + +Sprite will change the x position by this number + +## Block Editor + +![](/static/mb/change-0.png) + +## KindScript + +Sprite will change the x position by this number + +``` +export function changeXBy(_this: micro_bitSprites.LedSprite, x: number) +``` + +Sprite will change the y position by this number + +``` +export function changeYBy(_this: micro_bitSprites.LedSprite, y: number) +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/clear.md b/docs/reference/game/clear.md new file mode 100644 index 00000000..74179c5c --- /dev/null +++ b/docs/reference/game/clear.md @@ -0,0 +1,39 @@ +# Clear + +The clear function for images. #clear #docs + +Turn off all the pixels in an [Image](/microbit/reference/image/image). + +### KindScript + +``` +export function clear(img: micro_bit.Image) +``` + +### Parameters + +* none + +### Example + +The following example turns off the pixels of `img` when the A input button is pressed: + +``` +let img = images.createImage(` +. . . . . +. # # # . +. # # # . +. # # # . +. . . . . +`) +img.showImage(0) +input.onButtonPressed("A", () => { + img.clear() + img.showImage(0) +}) +``` + +### See also + +[Image](/microbit/reference/image/image), [show animation](/microbit/reference/basic/show-animation), [show image](/microbit/reference/images/show-image), [scroll image](/microbit/reference/images/scroll-image), [create image](/microbit/reference/images/create-image) + diff --git a/docs/reference/game/game-library.md b/docs/reference/game/game-library.md new file mode 100644 index 00000000..9b4684d9 --- /dev/null +++ b/docs/reference/game/game-library.md @@ -0,0 +1,161 @@ +# Game Library + +The game library #docs + +The game library supports simple single-player time-based games. The player has a **sprite**, number of **lives** and a **score**. The game has a sprite, number of **levels** and a **countdown clock**. The general goal of a game will be to move the sprite and achieve a top score before time runs out or the number of lives goes to zero. + +## Block Editor + +![](/static/mb/game-library/pic0.png) + +## KindScript + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### [Create sprite](/microbit/functions/game-library/create-sprite) + +Create sprite with x, y coordinates and returns a LED Sprite. Create a new LED sprite. + +![](/static/mb/create-sprite-0.png) + +``` +export function createSprite(x: number, y: number) : micro_bitSprites.LedSprite +``` + +### [Move](/microbit/functions/game-library/move) + +Sprite move by a certain number + +![](/static/mb/game-library/move-0.png) + +``` +export function move(_this: micro_bitSprites.LedSprite, leds: number) +``` + +### [Turn](/microbit/functions/game-library/turn) + +Rotates a sprite to the right by a certain number of degrees + +![](/static/mb/game-library/turn-0.png) + +``` +export function turnRight(_this: micro_bitSprites.LedSprite, degrees: number) +``` + +Rotates a sprite to the left by a certain number of degrees + +``` +export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number) +``` + +### [Change](/microbit/functions/game-library/change) + +Sprite will change the x position by this number + +![](/static/mb/change-0.png) + +``` +export function changeXBy(_this: micro_bitSprites.LedSprite, x: number) +``` + +Sprite will change the y position by this number + +``` +export function changeYBy(_this: micro_bitSprites.LedSprite, y: number) +``` + +### [Set](/microbit/functions/game-library/set) + +Sprite will change the x position by this number + +``` +export function setX(_this: micro_bitSprites.LedSprite, x: number) +``` + +Sprite will change the y position by this number + +![](/static/mb/change-0.png) + +``` +export function changeYBy(_this: micro_bitSprites.LedSprite, y: number) +``` + +### [If on edge, bounce](/microbit/functions/game-library/if-on-edge-bounce) + +Sprite - If the sprite is on the edge, the sprite will bounce + +![](/static/mb/game-library/if-on-edge-bounce-0.png) + +``` +export function ifOnEdge_Bounce(_this: micro_bitSprites.LedSprite) +``` + +### [Change score by](/microbit/functions/game-library/change-score-by) + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +![](/static/mb/game-library/pic1.png) + +``` +export function addScore(points: number) +``` + +### [Score](/microbit/functions/game-library/score) + +* set the current score to a particular value. + +``` +export function setScore(value: number) +``` + +* get the current score value + +![](/static/mb/game-library/pic2.png) + +``` +export function score() : number +``` + +### [Countdown](/microbit/functions/game-library/start-countdown) + +If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. + +* start a countdown with the maximum duration of the game in milliseconds. + +![](/static/mb/game-library/pic3.png) + +``` +export function startCountdown(ms: number) +``` + +### [Game over](/microbit/functions/game-library/game-over) + +If the `life` reaches zero or the time expires (see countdown), the game enters the **game over** mode. When the game is over, `game->is running` returns false + +* check if the game still running. + +``` +let running = game.isRunning() +``` + +You can also end the game by calling the `game -> game over` function: + +![](/static/mb/game-library/pic0.png) + +``` +game.gameOver() +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/game-over.md b/docs/reference/game/game-over.md new file mode 100644 index 00000000..e1a66b22 --- /dev/null +++ b/docs/reference/game/game-over.md @@ -0,0 +1,24 @@ +# Game Over + +The game library + +The game library supports simple single-player time-based games. The game can end the game by calling the `game over` function + +## Block Editor + +You can end the game by calling the `game over ` function. In this example, if BBC micro:bit's answer to the question is GAME OVER, GAME OVER will be displayed to end the game. + +![](/static/mb/game-library/game-over-0.png) + +## KindScript + +You can end the game by calling the `game -> game over` function: + +``` +game.gameOver() +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) + diff --git a/docs/reference/game/move.md b/docs/reference/game/move.md new file mode 100644 index 00000000..883301c9 --- /dev/null +++ b/docs/reference/game/move.md @@ -0,0 +1,22 @@ +# Move + +The game library + +### Move + +Sprite move by a certain number + +## Block Editor + +![](/static/mb/game-library/move-0.png) + +## KindScript + +``` +export function move(_this: micro_bitSprites.LedSprite, leds: number) +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/position.md b/docs/reference/game/position.md new file mode 100644 index 00000000..2c14c4db --- /dev/null +++ b/docs/reference/game/position.md @@ -0,0 +1,32 @@ +# Position + +The game library + +### Create sprite + +Reports the x or y position of a sprite on the LED screen + +## Block Editor + +Reports the x position of a sprite on the LED screen + +![](/static/mb/game-library/position-0.png) + +## KindScript + +Reports the x position of a sprite on the LED screen + +``` +export function x(_this: micro_bitSprites.LedSprite) : number +``` + +Reports the y position of a sprite on the LED screen + +``` +export function y(_this: micro_bitSprites.LedSprite) : number +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/reports.md b/docs/reference/game/reports.md new file mode 100644 index 00000000..3bdb2156 --- /dev/null +++ b/docs/reference/game/reports.md @@ -0,0 +1,56 @@ +# Reports + +The game library + +### Reports + +Reports the x or y position, the current direction of a sprite, or the brightness of a sprite on the LED screen + +## Block Editor + +Reports the x position of a sprite on the LED screen + +![](/static/mb/game-library/position-0.png) + +Reports the y position of a sprite on the LED screen + +![](/static/mb/game-library/reports-0.jpg) + +Reports the brightness of a sprite on the LED screen + +![](/static/mb/game-library/reports-1.jpg) + +Reports the direction of a sprite on the LED screen + +![](/static/mb/game-library/reports-2.jpg) + +## KindScript + +Reports the x position of a sprite on the LED screen + +``` +export function x(_this: micro_bitSprites.LedSprite) : number +``` + +Reports the y position of a sprite on the LED screen + +``` +export function y(_this: micro_bitSprites.LedSprite) : number +``` + +Reports the brightness of a sprite on the LED screen + +``` +export function brightness(_this: micro_bitSprites.LedSprite) : number +``` + +Reports the current direction of a sprite on the LED screen + +``` +export function direction(_this: micro_bitSprites.LedSprite) : number +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/score.md b/docs/reference/game/score.md new file mode 100644 index 00000000..24f05c69 --- /dev/null +++ b/docs/reference/game/score.md @@ -0,0 +1,59 @@ +# Score + +The game library #docs + +The game library supports simple single-player games. The player has a **score**. + +## Block Editor + +The code below shows a simple game where the user gets to press the button ``A`` and adds 1 point to score that will be displayed on the BBC micro:bit screen + +![](/static/mb/game-library/add-point-to-score-0.png) + +## KindScript + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* set the current score to a particular value. + +``` +export function setScore(value: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Countdown + +If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. + +* start a countdown with the maximum duration of the game in milliseconds. + +``` +export function startCountdown(ms: number) +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/start-countdown.md b/docs/reference/game/start-countdown.md new file mode 100644 index 00000000..8c0122af --- /dev/null +++ b/docs/reference/game/start-countdown.md @@ -0,0 +1,57 @@ +# Start Countdown + +The game library #docs + +The game library supports simple single-player time-based games. The general goal of a game will be to achieve a top score before time runs out of time. + +## Block Editor + +![](/static/mb/game-library/start-countdown-0.png) + +## KindScript + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* set the current score to a particular value. + +``` +export function setScore(value: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Countdown + +If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. + +* start a countdown with the maximum duration of the game in milliseconds. + +``` +export function startCountdown(ms: number) +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/touching.md b/docs/reference/game/touching.md new file mode 100644 index 00000000..72eb9dd5 --- /dev/null +++ b/docs/reference/game/touching.md @@ -0,0 +1,24 @@ +# Touching + +The game library + +### Touching + +Reports true if sprite is touching specified sprite + +## Block Editor + +![](/static/mb/game-library/touching-0.png) + +## KindScript + +Reports true if sprite is touching specified sprite + +``` +export function isTouching(_this: micro_bitSprites.LedSprite, other: micro_bitSprites.LedSprite) : boolean +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/game/turn.md b/docs/reference/game/turn.md new file mode 100644 index 00000000..12ec009a --- /dev/null +++ b/docs/reference/game/turn.md @@ -0,0 +1,30 @@ +# Turn + +The game library + +Rotates a sprite to the right by a certain number of degrees + +## Block Editor + +Rotates a sprite to the right by a certain number of degrees + +![](/static/mb/game-library/turn-0.png) + +## KindScript + +Rotates a sprite to the right by a certain number of degrees + +``` +export function turnRight(_this: micro_bitSprites.LedSprite, degrees: number) +``` + +Rotates a sprite to the left by a certain number of degrees + +``` +export function turnLeft(_this: micro_bitSprites.LedSprite, degrees: number) +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/images/create-image.md b/docs/reference/images/create-image.md new file mode 100644 index 00000000..7c279c2a --- /dev/null +++ b/docs/reference/images/create-image.md @@ -0,0 +1,39 @@ +# Create Image + +Create an [Image](/microbit/reference/image/image) to show on the [LED screen](/microbit/device/screen). + +```sig +images.createImage(` +. . # . . +. # # # . +# # # # # +. # # # . +. . # . . +`) +``` + +### Example: rock, paper, scissors + +The following example shows one of three images (rock, paper, or scissors) when you shake the micro:bit: + +``` +input.onGesture(Gesture.Shake, () => { + let rockpaper = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + rockpaper.showFrame(Math.random(3)) +}) +``` + +### Lessons + +[rock paper scissors](/microbit/lessons/rock-paper-scissors), [digital pet](/microbit/lessons/digital-pet), [offset-image](/microbit/lessons/offset-image) + +### See also + +[show animation](/microbit/reference/basic/show-animation), [image](/microbit/reference/image/image), [show image](/microbit/reference/image/show-image), [scroll image](/microbit/reference/image/scroll-image) + diff --git a/docs/reference/images/image.md b/docs/reference/images/image.md new file mode 100644 index 00000000..b9a8adb7 --- /dev/null +++ b/docs/reference/images/image.md @@ -0,0 +1,56 @@ +# Image + +An image for the micro:bit screen. #docs #image #screen #LED + +### @parent blocks/language + +An *Image* is a matrix of pixels to show on the [LED screen](/microbit/device/screen) + +### Block Editor: Show LEDs + +To display an image using the [Block Editor](/microbit/blocks/editor): + +* click `Basic` , `Show LEDs`, and tap on the LEDs` +* when you're done, return to your code + +![](/static/mb/show-leds-1.png) + +You should see code similar to this: + +### Creating an image + +To create an image that you can later modify, see the [create image](/microbit/reference/images/create-image) function. + +### Block editor: create and show images + +To create images using the [Block editor](/microbit/blocks/editor): + +1. Click the **Images** category on the left. + +2. Drag and drop the **show image** block into your code. + +3. Drag and drop the **create image** or **create big image** block onto the **show image** block so that they connect. + +4. Make an image on the **create image** block by clicking on the squares. + +You should see code similar to this: + +![](/static/mb/blocks/image-0.png) + +### Image functions + +* [create image](/microbit/reference/images/create-image): create an image from a series of on/off LED states +* [clear](/microbit/reference/basic/clear-screen): turn off all the pixels in an image +* [pixel](/microbit/reference/images/pixel): get the state of a pixel in an image +* [show-leds](/microbit/reference/basic/show-leds): show a single-frame image on the LED screen +* [show image](/microbit/reference/images/show-image): show an image on the screen +* [scroll image](/microbit/reference/images/scroll-image): scroll an image on the screen + +### Lessons + +* [smiley](/microbit/lessons/smiley) + +### See also + +[Show LEDs](/microbit/reference/basic/show-leds), [create image](/microbit/reference/images/create-image), [show image](/microbit/reference/images/show-image), [LED screen](/microbit/device/screen) + diff --git a/docs/reference/images/pixel.md b/docs/reference/images/pixel.md new file mode 100644 index 00000000..6b4ae3f3 --- /dev/null +++ b/docs/reference/images/pixel.md @@ -0,0 +1,51 @@ +# Pixel + +The pixel function. #pixel #image #docs + +Get the state of a pixel in an [Image](/microbit/reference/image/image). + +### KindScript + +``` +export function pixel(_this: micro_bit.Image, x: number, y: number) : boolean +``` + +### Parameters + +* x - [Number](/microbit/reference/types/number); the *x coordinate* or horizontal position of a pixel in an [image](/microbit/reference/image/image) +* y - [Number](/microbit/reference/types/number); the *y coordinate* or vertical position of a pixel in an [image](/microbit/reference/image/image) + +### x, y coordinates? + +To figure out the ``x``, ``y`` coordinates, see [LED screen](/microbit/device/screen). + +### Returns + +* [Boolean](/microbit/reference/types/boolean) - `true` for on and `false` for off + +### Example + +This example gets the state of pixel `0, 0` in the `img` variable: + +### ~hide + +``` +let img = images.createImage(` +. . # . . . . . . . +. # . # . . . # . . +. . # . . . . . . . +. # . # . . . # . . +. . # . . . . . . . +`) +``` + +### ~ + +``` +let state = img.pixel(0, 0) +``` + +### See also + +[set pixel](/microbit/reference/images/set-pixel), [show image](/microbit/reference/images/show-image), [image](/microbit/reference/image/image), [create image](/microbit/reference/images/create-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/images/plot-frame.md b/docs/reference/images/plot-frame.md new file mode 100644 index 00000000..5b6d08df --- /dev/null +++ b/docs/reference/images/plot-frame.md @@ -0,0 +1,41 @@ +# Plot Frame + +The plot frame function. #plotframe #docs #image #screen #LED + +Display an [Image](/microbit/reference/image/image) on the BBC micro:bit's [LED screen](/microbit/device/screen) + +### KindScript + +``` +export function plotFrame(_this: micro_bit.Image, index: number) +``` + +### Parameters + +* index - [Number](/microbit/reference/types/number); which frame of the image to display + +### Difference from `plot image` + +The `plot frame` function takes the index of the frame (if there are two frames, then the possible indices are 0 and 1), whereas `plot image` accepts an offset (if there are two frames, the offset would range between 0 and 9). + +### Example + +``` +let img = images.createImage(` +# . . . # # . . . # +. # . # . . # # # . +. . # . . . # # # . +. # . # . . # # # . +# . . . # # . . . # +`) +img.plotFrame(1) +``` + +### Lessons + +[smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart), [magic logo](/microbit/lessons/magic-logo) + +### See also + +[create image](/microbit/reference/images/create-image), [show animation](/microbit/reference/basic/show-animation), [image](/microbit/reference/image/image), [show image](/microbit/reference/images/show-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/images/plot-image.md b/docs/reference/images/plot-image.md new file mode 100644 index 00000000..fceee108 --- /dev/null +++ b/docs/reference/images/plot-image.md @@ -0,0 +1,41 @@ +# Plot Image + +The plot image function. #plotimage #docs #image #screen #LED + +Display an [Image](/microbit/reference/image/image) on the BBC micro:bit's [LED screen](/microbit/device/screen) + +### KindScript + +``` +export function plotImage(_this: micro_bit.Image, xOffset: number) +``` + +### Parameters + +* x offset - [Number](/microbit/reference/types/number); the horizontal starting point of an image; use 0 for the first frame of the image, 5 for the second frame of the image, 10 for the third frame and so on. + +### Difference from `show image` + +The `show image` function has a built in delay of 400ms after display of the image, whereas `plot image` has no built-in delay. + +### Example + +``` +let img = images.createImage(` +# . . . # # . . . # +. # . # . . # # # . +. . # . . . # # # . +. # . # . . # # # . +# . . . # # . . . # +`) +img.plotImage(0) +``` + +### Lessons + +[smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart), [magic logo](/microbit/lessons/magic-logo) + +### See also + +[create image](/microbit/reference/images/create-image), [show animation](/microbit/reference/basic/show-animation), [image](/microbit/reference/image/image), [show image](/microbit/reference/images/show-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/images/scroll-image.md b/docs/reference/images/scroll-image.md new file mode 100644 index 00000000..d71bfd09 --- /dev/null +++ b/docs/reference/images/scroll-image.md @@ -0,0 +1,73 @@ +# Scroll Image + +The scroll image function. #scrollimage #image #docs + +Scrolls the frames within an [Image](/microbit/reference/image/image) on the [LED screen](/microbit/device/screen). + +### Block Editor + +![](/static/mb/scroll-image-0.png) + +### KindScript + +``` +export function scrollImage(_this: micro_bit.Image, xOffsetPerStep: number, interval: number) +``` + +### Parameters + +* x offset per step : [Number](/microbit/reference/types/number) - the number of columns to scroll at a time (horizontal offset). Use a positive number to scroll an image to the right and a negative number to scroll left. To jump from one image frame to the next, use an offset of 5 or -5. +* interval (ms) : [Number](/microbit/reference/types/number) - the time (in milliseconds) before scrolling by `x offset per step`; the larger the number, the slower the scroll. + +### ~hide + +``` +let img = images.createImage(` +. . # . . . # # # . . # # # . +. . # . . . . . # . . . . # . +. . # . . . . # . . . # # # . +. . # . . . # . . . . . . # . +. . # . . . # # # . . # # # . +`) +``` + +### ~ + +To scroll an image 1 column at a time to the right: + +``` +img.scrollImage(1, 1000) +``` + +To scroll an image 5 columns at a time (skip from frame to frame): + +``` +img.scrollImage(5, 1000) +``` + +To scroll an image 1 column at a time to the left: + +``` +img.scrollImage(-1, 500) +``` + +### Example: scroll through frames + +This example creates an image with 3 frames, then scrolls through the 3 frames: + +``` +img = images.createImage(` +. . # . . . # # # . . # # # . +. . # . . . . . # . . . . # . +. . # . . . . # . . . # # # . +. . # . . . # . . . . . . # . +. . # . . . # # # . . # # # . +`) +img.showImage(0) +img.scrollImage(5, 1000) +``` + +### See also + +[show image](/microbit/reference/images/show-image), [image](/microbit/reference/image/image), [create image](/microbit/reference/images/create-image), [show animation](/microbit/reference/basic/show-animation) + diff --git a/docs/reference/images/set-pixel.md b/docs/reference/images/set-pixel.md new file mode 100644 index 00000000..afbb4941 --- /dev/null +++ b/docs/reference/images/set-pixel.md @@ -0,0 +1,42 @@ +# Set Pixel + +The set pixel function. #set pixel #image #docs + +Set the on/off state of pixel in an [Image](/microbit/reference/image/image). + +### KindScript + +``` +export function setPixel(_this: micro_bit.Image, x: number, y: number, value: boolean) +``` + +### Parameters + +* x - [Number](/microbit/reference/types/number); the *x coordinate* or horizontal position of a pixel in an [image](/microbit/reference/image/image) +* x - [Number](/microbit/reference/types/number); the *y coordinate* or vertical position of a pixel in an [image](/microbit/reference/image/image) +* value -[Boolean](/microbit/reference/types/boolean); the on/off state of a pixel; `true` for on, `false` for off + +### x, y coordinates? + +To figure out the ``x``, ``y`` coordinates, see [LED screen](/microbit/device/screen). + +### Example + +The following example creates an image and stores it in the `img` variable. The `set pixel` function sets the centre pixel off, before `img` is shown using `show image`. + +``` +let img = images.createImage(` +. . # . . +. # . # . +. . # . . +. # . # . +. . # . . +`) +img.setPixel(2, 2, false) +img.showImage(0) +``` + +### See also + +[pixel](/microbit/reference/images/pixel), [show image](/microbit/reference/images/show-image), [image](/microbit/reference/image/image), [create image](/microbit/reference/images/create-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/images/show-frame.md b/docs/reference/images/show-frame.md new file mode 100644 index 00000000..f408a2ce --- /dev/null +++ b/docs/reference/images/show-frame.md @@ -0,0 +1,41 @@ +# Show Frame + +The show frame function. #showframe #docs #image #screen #LED + +Display an [Image](/microbit/reference/image/image) on the BBC micro:bit's [LED screen](/microbit/device/screen) + +### KindScript + +``` +export function showFrame(img: micro_bit.Image, frame: number) +``` + +### Parameters + +* index - [Number](/microbit/reference/types/number); which frame of the image to display + +### Difference from `plot frame` + +The `show frame` function is the same as [plot frame](/microbit/reference/image/plot-frame), but contains a built-in delay after the LED screen has been updated (whereas `plot frame` has no built-in delay) + +### Example + +``` +let img = images.createImage(` +# . . . # # . . . # +. # . # . . # # # . +. . # . . . # # # . +. # . # . . # # # . +# . . . # # . . . # +`) +img.showFrame(1) +``` + +### Lessons + +[smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart), [magic logo](/microbit/lessons/magic-logo) + +### See also + +[create image](/microbit/reference/images/create-image), [show animation](/microbit/reference/basic/show-animation), [image](/microbit/reference/image/image), [show image](/microbit/reference/images/show-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/images/show-image.md b/docs/reference/images/show-image.md new file mode 100644 index 00000000..7be95240 --- /dev/null +++ b/docs/reference/images/show-image.md @@ -0,0 +1,61 @@ +# Show Image + +The show image function. #showimage #docs #image #screen #LED + +Show an [Image](/microbit/reference/image/image) on the [LED screen](/microbit/device/screen), followed by a 400ms pause. + +### Block Editor + +![](/static/mb/show-image-0.png) + +### KindScript + +``` +export function showImage(_this: micro_bit.Image, xOffset: number) +``` + +### Parameters + +* x offset - [Number](/microbit/reference/types/number); the horizontal starting point of an image; use 0 for the first frame of the image, 5 for the second frame of the image, 10 for the third frame and so on. + +### Create image and show image + +Use the [image editor](/microbit/reference/image/image) to create images using the [create image](/microbit/reference/image/create-image) function, and then use `show image` like this: + +``` +let img = images.createImage(` +. . # . . +. # . # . +. . # . . +. # . # . +. . # . . +`) +img.showImage(0) +``` + +### Example: display numbers 1-5 + +The following example creates an image with 5 frames and then uses a [for loop](/microbit/reference/loops/for) to show each frame on the screen: + +``` +let img2 = images.createImage(` +. . # . . . # # # # . # # # . . . . # . . # # # . +. # # . . . . . . # . . . # . . . # # . . # . . . +. . # . . . . . # . . . # . . . # # # # . # # # . +. . # . . . . # . . . . . # . . . . # . . . . # . +. . # . . . # # # # . # # # . . . . # . . # # # . +`) +for (let i = 0; i < 5; i++) { + img2.showImage(i * 5) + basic.pause(1000) +} +``` + +### Lessons + +[rock paper scissors](/microbit/lessons/rock-paper-scissors), [digital pet](/microbit/lessons/digital-pet), [offset-image](/microbit/lessons/offset-image) + +### See also + +[show animation](/microbit/reference/basic/show-animation), [image](/microbit/reference/image/image), [create image](/microbit/reference/images/create-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/images/width.md b/docs/reference/images/width.md new file mode 100644 index 00000000..451b9dcb --- /dev/null +++ b/docs/reference/images/width.md @@ -0,0 +1,62 @@ +# Width + +The width function. #width #image #docs + +Get the width of an [Image](/microbit/reference/image/image) in columns. + +### KindScript + +``` +export function width(_this: micro_bit.Image) : number +``` + +### Parameters + +* none + +### Returns + +* [Number](/microbit/reference/types/number) - the number of columns in a image. This function returns 5 if the image has 1 frame, 10 for 2 frames, 15 for 3 frames and so on. Divide the number of columns by 5 to find out how many frames an image has (see example below). + +The following example gets the width of `img` and stores it in the `w` variable: + +### ~hide + +``` +let img = images.createImage(` +. . # . . . . . . . +. # . # . . . # . . +. . # . . . . . . . +. # . # . . . # . . +. . # . . . . . . . +`) +``` + +### ~ + +``` +let w = img.width() +``` + +### Example: show each frame + +The following example uses the `width` function with a [for](/microbit/reference/loops/for) loop to show each image frame on the screen: + +``` +let img2 = images.createImage(` +. . # . . . # # # # . # # # . +. # # . . . . . . # . . . # . +. . # . . . . . # . . . # . . +. . # . . . . # . . . . . # . +. . # . . . # # # # . # # # . +`) +for (let i = 0; i < img2.width() / 5; i++) { + img2.showImage(i * 5) + basic.pause(1000) +} +``` + +### See also + +[show image](/microbit/reference/images/show-image), [image](/microbit/reference/image/image), [create image](/microbit/reference/images/create-image), [scroll image](/microbit/reference/images/scroll-image), [show animation](/microbit/reference/basic/show-animation) + diff --git a/docs/reference/input/acceleration.md b/docs/reference/input/acceleration.md new file mode 100644 index 00000000..d0381916 --- /dev/null +++ b/docs/reference/input/acceleration.md @@ -0,0 +1,49 @@ +# Acceleration + +Get the acceleration value (milli g-force), in one of three specified dimensions. + +```sig +input.acceleration(Dimension.X); +``` + +### Parameters + +* dimension : [String](/microbit/reference/types/string) - one of three values specifying the axis of acceleration: ``x`` (left/right); ``y`` (forward/backwards); ``z`` (up/down) + +### Returns + +* [Number](/microbit/reference/types/number) - acceleration, in milli-gravities. When the micro:bit is laying flat with the screen up, x=0, y=0 and z=-1023. + +### Example: bar chart + +Use the ``plot bar chart`` to visual the acceleration on the LED screen. + +```blocks +basic.forever(() => { + led.plotBarGraph(input.acceleration("x"), 1023) +}) +``` + +### Example: micro:bit leveller + +The following example uses the `acceleration` and the `plot` function to help you move the micro:bit until it's level (the centre LED is *on* when the device is level). When running this code in a web browser, move your mouse to simulate the accelerometer. + +```blocks +basic.forever(() => { + let ax = input.acceleration(Dimension.X) + let x = pins.map(-1023, 1023, 0, 4, ax) + let ay = input.acceleration("y") + let y = pins.map(-1023, 1023, 0, 4, ay) + basic.clearScreen() + led.plot(x, y) +}) +``` + +### Lessons + +[zoomer](/microbit/lessons/zoomer) + +### See also + +[compass-heading](/microbit/input/compass-heading), [lightlevel](/microbit/input/lightlevel) + diff --git a/docs/reference/input/button-is-pressed.md b/docs/reference/input/button-is-pressed.md new file mode 100644 index 00000000..9c4ade4a --- /dev/null +++ b/docs/reference/input/button-is-pressed.md @@ -0,0 +1,41 @@ +# Button Is Pressed + +Get the state of an input button. The micro:bit has two input buttons: A and B. + +```sig +input.buttonIsPressed(Button.A); +``` + +### Parameters + +* name - [String](/microbit/reference/types/string); input button "A", "B", or "A+B" (both input buttons) + +### Returns + +* [Boolean](/microbit/reference/types/boolean) - `true` if pressed, `false` if not pressed + +### Example + +The following code uses an [if](/microbit/reference/logic/if) statement to run code, depending on whether or not the A button is pressed: + +```blocks +basic.forever(() => { + let pressed = input.buttonIsPressed(Button.A) + if (pressed) { + // this code runs if the A button is pressed + basic.showNumber(1, 150) + } else { + // this code runs if the A button is *not* pressed + basic.showNumber(0, 150) + } +}) +``` + +### Lessons + +[zoomer](/microbit/lessons/zoomer) + +### See also + +[on button pressed](/microbit/input/on-button-pressed), [if](/microbit/reference/logic/if), [forever](/microbit/basic/forever) + diff --git a/docs/reference/input/compass-heading.md b/docs/reference/input/compass-heading.md new file mode 100644 index 00000000..9ecd2637 --- /dev/null +++ b/docs/reference/input/compass-heading.md @@ -0,0 +1,63 @@ +# Compass Heading + +Get the compass heading of the micro:bit in degrees. Your micro:bit has a built-in **magnetometer** so it can your direction with respect to the North Magnetic Pole. + +```sig +input.compassHeading(); +``` + +### Returns + +* [Number](/microbit/reference/types/number) - the heading in degrees (0 to 360 degrees). If the compass is calibrating, it returns ``-1003``. + +## Simulator + +Calibration does not work on the simulator. + +### Example + +The following code gets the compass heading and stores it in the `degrees` variable: + +```blocks +let degrees = input.compassHeading() +``` + +### ~hint + +When running code with this function in a web browser, click and drag the on-screen compass needle to change heading. + +### ~ + +### Example: compass + +The following example gets the `compass heading` and then displays a letter depending on the value of `degrees`: N for north, E for East, S for South, and W for West. + +```blocks +basic.forever(() => { + let degrees = input.compassHeading() + if (degrees < 45) + basic.showString("N") + else if (degrees < 135) + basic.showString("E") + else if (degrees < 225) + basic.showString("S") + else basic.showString("W") +}) +``` + +### Calibration + +On the first use of the compass, the **calibration** procedure will automatically start. The user must draw a circle with the device until it is fully calibrated. + +An enclosure made from metal, or using in proximity of metal objects, might affect the accuracy of the reading and calibration. + +During calibration, ``compass heading`` returns ``-1003``. + +### Lessons + +[compass](/microbit/lessons/compass) + +### See also + +[acceleration](/microbit/reference/input/acceleration) + diff --git a/docs/reference/input/light-level.md b/docs/reference/input/light-level.md new file mode 100644 index 00000000..f4d62300 --- /dev/null +++ b/docs/reference/input/light-level.md @@ -0,0 +1,30 @@ +# Light Level + +Gets the light level from ``0`` (dark) to ``255`` (bright). The light is measured by using various LEDs from the screen. + +This function will return ``0`` on the first call to this method, a light reading will be available after the display has activated the light sensor for the first time. + +```sig +input.lightLevel(); +``` + +### Returns + +* [Number](/microbit/reference/types/number) - light level from ``0`` (dark) to ``255`` (bright). + +### Example: chart light level + +Use `plot bar chart` to visual the influence of various light source on the light level. + +```blocks +basic.forever(() => { + led.plotBarGraph(input.lightLevel(), 255) +}) +``` + +### Lessons + +### See also + +[acceleration](/microbit/reference/input/acceleration), [compass-heading](/microbit/input/compass-heading) + diff --git a/docs/reference/input/magnetic-force.md b/docs/reference/input/magnetic-force.md new file mode 100644 index 00000000..4d2a873a --- /dev/null +++ b/docs/reference/input/magnetic-force.md @@ -0,0 +1,32 @@ +# Magnetic Force + +Get the magnetic force (micro Teslas), in one of three specified dimensions. + +```sig +input.magneticForce(Dimension.X); +``` + +### Parameters + +* dimension : [String](/microbit/reference/types/string) - one of three values specifying the axis of the force: ``x`` (left/right); ``y`` (forward/backwards); ``z`` (up/down); ``strength`` (the length of the vector) + +### Returns + +* [Number](/microbit/reference/types/number) - magnetic force, in micro-Teslas. + +### Example: metal detector + +The following example uses the `magnetic force` to control the brightness of the screen. When the magnetic force increases, the center LED will appear brighter. + +```blocks +led.plot(2, 2) +basic.forever(() => { + let f = input.magneticForce(Dimension.X) + led.setBrightness(f / 2000) +}) +``` + +### See also + +[compass heading](/microbit/input/compass-heading) + diff --git a/docs/reference/input/on-button-pressed.md b/docs/reference/input/on-button-pressed.md new file mode 100644 index 00000000..41e3d239 --- /dev/null +++ b/docs/reference/input/on-button-pressed.md @@ -0,0 +1,40 @@ +# On Button Pressed + +Register an [event handler](/microbit/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/microbit/js/simulator) with this function in a web browser, click an on-screen input button - labelled A or B. + +```sig +input.onButtonPressed(Button.A, () => {}) +``` + +### Example: count button clicks + +This example counts how many times the left or right input button is pressed. Each time a button is pressed, the global count variable is increased by 1 and displayed on the screen. + +```blocks +let count = 0 +basic.showNumber(count) +input.onButtonPressed(Button.A, () => { + count++; + basic.showNumber(count); +}) +``` + +### Example: roll a dice + +This example generates a random number when you press the B input button, and then displays a random die image: + +```blocks +input.onButtonPressed(Button.B, () => { + let dice = Math.random(6) + basic.showNumber(dice) +}) +``` + +### Lessons + +[smiley](/microbit/lessons/smiley), [answering machine](/microbit/lessons/answering-machine), [screen wipe](/microbit/lessons/screen-wipe), [rotation animation](/microbit/lessons/rotation-animation) + +### See also + +[button is pressed](/microbit/reference/input/button-is-pressed), [forever](/microbit/reference/basic/forever) + diff --git a/docs/reference/input/on-gesture.md b/docs/reference/input/on-gesture.md new file mode 100644 index 00000000..024cdda8 --- /dev/null +++ b/docs/reference/input/on-gesture.md @@ -0,0 +1,45 @@ +# On Gesture + +Register an [event handler](/microbit/reference/event-handler) that will execute whenever the user executes a gesture withthe BBC micro:bit. + +```sig +input.onGesture(Gesture.Shake,() => { +}) +``` + +## Gestures + + + +### Example: random number + +The following example displays a number from 0-9 on the screen when you shake the BBC micro:bit. + +```blocks +input.onGesture(Gesture.Shake,() => { + let x = Math.random(10) + basic.showNumber(x, 100) +}) +``` + +### Example: rock, paper, scissors + +The following example shows one of three images (rock, paper, or scissors) when you shake the BBC micro:bit. + +```blocks +input.onGesture(Gesture.Shake,() => { + let img = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + img.showFrame(Math.random(3)) +}) +``` + +### Lessons + +[bounce image](/microbit/lessons/bounce-image), [rock paper scissors](/microbit/lessons/rock-paper-scissors) + diff --git a/docs/reference/input/on-pin-pressed.md b/docs/reference/input/on-pin-pressed.md new file mode 100644 index 00000000..a0aee311 --- /dev/null +++ b/docs/reference/input/on-pin-pressed.md @@ -0,0 +1,32 @@ +# On Pin Pressed + +Register an [event handler](/microbit/reference/event-handler) that will execute whenever the user holds the `GND` pin with one hand, and presses pin `0`, `1`, or `2` with the other hand, thus completing a circuit; when you run a script with this function in a web browser, click pins 0 , 1, or 2 on the simulator. + +*Note* that this function works best when the BBC micro:bit is powered by AAA battery. + +```sig +input.onPinPressed(TouchPin.P0, () => { +}) +``` + +### Example: pin pressed counter + +This example counts how many times the P0 pin is pressed. Each time the pin is pressed, the global count variable is increased by 1 and displayed on the screen. + +```blocks +let count = 0 +basic.showNumber(count, 100) +input.onPinPressed(TouchPin.P0, () => { + count = count + 1 + basic.showNumber(count, 100) +}) +``` + +### Lessons + +[love meter](/microbit/lessons/love-meter) + +### See also + +[BBC micro:bit pins](/microbit/device/pins), [pin is pressed](/microbit/input/pin-is-pressed), [analog read pin](/microbit/pins/analog-read-pin), [analog write pin](/microbit/pins/analog-write-pin), [digital read pin](/microbit/pins/digital-read-pin), [digital write pin](/microbit/pins/digital-write-pin) + diff --git a/docs/reference/input/pin-is-pressed.md b/docs/reference/input/pin-is-pressed.md new file mode 100644 index 00000000..e14fdeec --- /dev/null +++ b/docs/reference/input/pin-is-pressed.md @@ -0,0 +1,36 @@ +# Pin Is Pressed + +Gets the pin state (pressed or not pressed), by detecting when the user holds the `GND` pin with one hand, and presses pin `0`, `1`, or `2` with the other hand, thus completing a circuit. + +*Note* that this function works best when the BBC micro:bit is powered by AAA battery. + +```sig +input.pinIsPressed(TouchPin.P0); +``` + +### Parameters + +* name - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2") + +### returns + +* [Boolean](/microbit/reference/types/boolean) - `true` if pressed, `false` if not pressed + +### Example + +This example displays 1 if P0 is pressed, and 0 if P0 is not pressed: + +```blocks +basic.forever(() => { + if (input.pinIsPressed(TouchPin.P0)) { + basic.showNumber(1, 150) + } else { + basic.showNumber(0, 150) + } +}) +``` + +### See also + +[BBC micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/input/on-pin-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) + diff --git a/docs/reference/input/rotation.md b/docs/reference/input/rotation.md new file mode 100644 index 00000000..01c04b89 --- /dev/null +++ b/docs/reference/input/rotation.md @@ -0,0 +1,48 @@ +# Rotation + +Get a rotation angle in degrees inferred from the accelerometer readings. + +```sig +input.rotation(Rotation.Roll); +``` + +### Parameters + +* kind: [String](/microbit/reference/types/string) - one of values specifying the kind of rotation: ``pitch`` (up/down around the ``x`` axis); ``roll`` (left/right around the ``y`` axis) + +### Returns + +* [Number](/microbit/reference/types/number) - angle, in degrees. + +### Example: micro:bit leveller + +The following example uses the `rotation` and the `plot leds` function to help you move the BBC micro:bit until it's level: when it is level, a smiley shows up on the screen. When running this code in a web browser, move your mouse to simulate the rotation. + +```sig +basic.forever(() => { + let pitch = input.rotation(Rotation.Pitch) + let roll = input.rotation(Rotation.Roll) + if (Math.abs(pitch) < 10 && Math.abs(roll) < 10) { + basic.plotLeds(` +. . . . . +. # . # . +. . . . . +# . . . # +. # # # . +`) + } else { + basic.plotLeds(` +# . . . # +. # . # . +. . # . . +. # . # . +# . . . # +`) + } +}) +``` + +### See also + +[acceleration](/microbit/reference/input/acceleration), [compass-heading](/microbit/reference/input/compass-heading) + diff --git a/docs/reference/input/running-time.md b/docs/reference/input/running-time.md new file mode 100644 index 00000000..0d3c7b9d --- /dev/null +++ b/docs/reference/input/running-time.md @@ -0,0 +1,29 @@ +# Running Time + +Get the number of milliseconds elapsed since the script began. 1,000 milliseconds = 1 second. + +```sig +input.runningTime(); +``` + +### Returns + +* [Number](/microbit/reference/types/number) + +### Example: elapsed time + +This code gets the elapsed time since the start of the program execution and displays it on the screen. + +```blocks +let now = input.runningTime() +basic.showNumber(now) +``` + +### Lessons + +[speed button](/microbit/lessons/speed-button) + +### See also + +[show number](/microbit/reference/basic/show-number), [pause](/microbit/reference/basic/pause) + diff --git a/docs/reference/input/temperature.md b/docs/reference/input/temperature.md new file mode 100644 index 00000000..416ad954 --- /dev/null +++ b/docs/reference/input/temperature.md @@ -0,0 +1,35 @@ +# Temperature + +Get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit. + +```sig +input.temperature(); +``` + +### Returns + +* [Number](/microbit/reference/types/number) - temperature in degree Celsius °C. + +### How does it work? + +The BBC micro:bit does not have a dedicated temperature sensor. Instead, the temperature provided is actually the temperature of the silicon die on the main CPU. As the processor generally runs cold though (it is a high efficiency ARM core), the temperature is a good approximation of the ambient temperature... you might warm up if you give the processor a lot of work to do though, and don't [sleep](/microbit/reference/basic/pause)! + +The temperature sensor has a high precision, but isn't trimmed for accuracy. In other words, it can sense changes in temperature very well, but there may be (and probably is) base line offset. i.e. it might return 20 degrees when it's actually 17, but it would return 21 when it is 18 etc. + +### Example: micro:bit thermometer + +The following example uses the `temperature` and the `show number` to display the room temperature. + +```sig +basic.forever(() => { + let temp = input.temperature() + basic.showNumber(temp) +}) +``` + +### Lessons + +### See also + +[compass-heading](/microbit/reference/input/compass-heading), [acceleration](/microbit/reference/input/acceleration) + diff --git a/docs/reference/js/antenna.md b/docs/reference/js/antenna.md new file mode 100644 index 00000000..3491be6b --- /dev/null +++ b/docs/reference/js/antenna.md @@ -0,0 +1,81 @@ +# Antenna Library + +The events library #docs + +The functions in the ``antenna`` namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. + +### Remote control + +Control the presentation of media content available on a remote device using the `tell remote control to` function + +``` +export function tellRemoteControlTo(event: string) +``` + +The remote control specific events include: + +* play +* pause +* stop +* next track +* previous track +* forward +* rewind +* volume up +* volume down + +### Camera + +Access the photo/video-taking functionality of a remote device using the *camera* function: + +``` +export function tellCameraTo(event: string) +``` + +The camera-specific events include: + +* toggle front-rear +* launch photo mode +* take photo +* stop photo mode +* launch video mode +* start video capture +* stop video capture +* stop video mode + +### Alert + +Raise an alert on a remote device using the `raise alert to` function + +``` +export function raiseAlertTo(event: string) +``` + +The set of alerting-specific events include: + +* display toast +* vibrate +* play sound +* play ringtone +* find my phone +* alarm 1 +* alarm 2 +* alarm 3 +* alarm 4 +* alarm 5 +* alarm 6 + +### Microphone + +Access the audio recording capabilities of the device using the `tell microphone to` function + +``` +export function tellMicrophoneTo(event: string) +``` + +The set of audio recorder events include: + +* launch +* start capture +* end capture +* stop diff --git a/docs/reference/js/assign.md b/docs/reference/js/assign.md new file mode 100644 index 00000000..1fbdd986 --- /dev/null +++ b/docs/reference/js/assign.md @@ -0,0 +1,54 @@ +# Assignment Operator + +Set the value for local and global variables #docs #assignment #language #var #data + +### @parent js/operators + + +Set or change the value of a variable + +### Block Editor + +![](/static/mb/antenna-0.png) + +### Touch Develop + +Use the assignment operator (:=) to set or change the value of a [local variable](/microbit/reference/variables/var) or a [global variable](/microbit/js/data). + +### Declare a variable + +Declare a new *local* variable using the [var](/microbit/reference/variables/var) statement and the assignment operator (`:=`). Like this: + +```blocks +let num1 = 7 +let name = "Joe" +``` + +The variable's name is on the left of the assignment operator (`:=`) and the variable's value is on the right: + +*variable name* `:=` *value* + +See [global variable](/microbit/js/data) for info on declaring a global variable. + +### Change a variable + +After a global or local variable is defined, use the assignment operator (`:=`) to change the variable's value. + +``` +g = 42 +num1 = 42 +``` + +### Notes + +* Don't confuse the assignment operator `:=` with the equality operator `=`, which is used to compare values. +* You can use the assignment operator `:=` with variables of each of the supported [types](/microbit/js/types). + +### Lessons + +[counter](/microbit/lessons/counter), [rotation animation](/microbit/lessons/rotation-animation), [digital pet](/microbit/lessons/digital-pet), [offset image](/microbit/lessons/offset-image) + +### See also + +[local variables](/microbit/reference/variables/var), [global variables](/microbit/js/data), [types](/microbit/js/types) + diff --git a/docs/reference/js/bits.md b/docs/reference/js/bits.md new file mode 100644 index 00000000..88087acc --- /dev/null +++ b/docs/reference/js/bits.md @@ -0,0 +1,67 @@ +# Bits Library + +Functions in the Bits library. #docs #bits #32bit #signed #unsigned + +### @parent td/language + +The binary numeral system represents numeric values using values 0 and 1. This is how almost all modern computers store data. Each 0 or 1 digit is called a binary digit, or bit for short. + +The Bits library includes functions for bit-level manipulation of integers. In the [Touch Develop editor](/microbit/js/editor), click `bits` to see the following bit functions: + +## Bitwise and, or, and xor functions + +#### Syntax + +bits `->` *and/or/xor* uint32 (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +#### Parameters + +* x - an unsigned 32 bit integer [Number](/microbit/reference/types/number) +* y - another unsigned 32 bit integer [Number](/microbit/reference/types/number) + +### and uint32 + +performs bitwise AND; returns `1` at position i if both bits *x[i]* and *y[i]* are `1`, otherwise returns `0`. + +### or uint32 + +performs bitwise OR; returns `1` at position *i* if either bit *x[i]* or *y[i]* is `1`, otherwise returns `0`. + +### xor uint32 + +performs bitwise exclusive XOR; returns `1` at position *i* if *x[i]=1 and y[i]=0* or *x[i] = 0 and y[i] =1*; returns `0` otherwise + +## Rotate left and rotate right + +Rotate bits to the left or the right, by the specified number of positions. + +#### Syntax + +bits `->` rotate left unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +bits `->` rotate right unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +#### Parameters + +* x - [Number](/microbit/reference/types/number); +* bits - [Number](/microbit/reference/types/number); + +## Shift left and shift right + +Shift bits to the left or the right, by the specified number of positions. + +#### Syntax + +bits `->` shift left unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +bits `->` shift right unint32 (x : [Number](/microbit/reference/types/number), bits : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +#### Parameters + +* x - [Number](/microbit/reference/types/number); +* bits - [Number](/microbit/reference/types/number); + +### See also + +[statements and operators](/microbit/js/statements), [math functions](/microbit/js/math), [Number](/microbit/reference/types/number) + diff --git a/docs/reference/js/boolean.md b/docs/reference/js/boolean.md new file mode 100644 index 00000000..300d09bd --- /dev/null +++ b/docs/reference/js/boolean.md @@ -0,0 +1,122 @@ +# Boolean + +true or false. + +### @parent js/language + +A Boolean has one of two possible values: `true`; `false`. Boolean (logical) operators (*and*, *or*, *not*) take Boolean inputs and yields a Boolean value. Comparison operators on other types ([numbers](/microbit/reference/types/number), [strings](/microbit/reference/types/string)) yields a Boolean value. + +### Block Editor + +In the Block Editor, the following blocks represent the true and false Boolean values, which can be plugged in anywhere a Boolean value is expected: + +![](/static/mb/boolean-0.png) + +The next three blocks represent the three Boolean (logic) operators: + +![](/static/mb/boolean-1.png) + +The next six blocks represent comparison operators that yield a Boolean value. Most comparisons you will do involve [numbers](/microbit/reference/types/number): + +![](/static/mb/boolean-2.png) + +### Touch Develop + +### ~hide + +``` +let condition = true +let condition2 = true +``` + +### ~ + +Boolean values and operators are often used with an [if](/microbit/reference/logic/if) or [while](/microbit/js/while) statement to determine which code will execute next. For example: + +``` +if (condition && condition2) { + // This code runs if both `condition` and `condition2` are `true` +} else { + // This code runs if either `condition` or `condition2` is `false` +} +``` + +### Functions that return a Boolean + +Some functions return a Boolean value, which you can store in a Boolean variable. For example, the following code gets the on/off state of `point (1, 2)` and stores this in the Boolean variable named `on`. Then the code clears the screen if `on` is `true`: + +``` +let on = led.point(1, 2) +if (on) { + basic.clearScreen() +} +``` + +### Boolean operators + +Boolean operators take Boolean inputs and evaluate to a Boolean output: + +### Conjunction: `A and B` + +`A and B` evaluates to `true` if-and-only-if both A and B are true: + +- `false and false` = `false` + +- `false and true` = `false` + +- `true and false` = `false` + +- `true and true` = `true` + +### Disjunction: `A or B` + +`A or B` evaluates to `true` if-and-only-if either A is true or B is true: + +- `false or false` = `false` + +- `false or true` = `true` + +- `true or false` = `true` + +- `true or true` = `true` + +### Negation: `not A` + +`not A` evaluates to the opposite (negation) of A: + +* `not false` = `true` +* `not true` = `false` + +### Example + +This example turns on LED `3 , 3`, if LEDs `1 , 1` and `2 , 2` are both on: + +``` +if (led.point(1, 1) && led.point(2, 2)) { + led.plot(3, 3) +} +``` + +### Comparisons of numbers and strings + +When you compare two Numbers, you get a Boolean value, such as the comparison `x < 5` in the code below: + +``` +let x = Math.random(10) +if (x < 5) { + basic.showString("Low", 150) +} else { + basic.showString("High", 150) +} +``` + +See the documentation on [Numbers](/microbit/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/microbit/reference/types/string-functions) using the `equals` function. + +### Lessons + +[rotation animation](/microbit/lessons/rotation-animation), [digi yoyo](/microbit/lessons/digi-yoyo), [love meter](/microbit/lessons/love-meter), [zoomer](/microbit/lessons/zoomer) + +### See also + +[if](/microbit/reference/logic/if), [while](/microbit/js/while), [number](/microbit/reference/types/number) + diff --git a/docs/reference/js/break.md b/docs/reference/js/break.md new file mode 100644 index 00000000..db469969 --- /dev/null +++ b/docs/reference/js/break.md @@ -0,0 +1,37 @@ +# Break + +Break statement; exit a for or while loop. #docs #break #language #loop #for #while + +### @parent js/language + + +Exit a [while](/microbit/js/while) or [for](/microbit/reference/loops/for) loop before the loop is complete. + +### Touch Develop syntax + +**break** + +### Example: count to a random number + +The following example counts from 0 to a random number from 0-9. When the for loop counter equals the random number (`i = x`), the `break` statement exits the loop: + +``` +let x = Math.random(10) +for (let i = 0; i < 10; i++) { + if (i == x) { + break + } else { + basic.showNumber(i, 0) + basic.pause(500) + } +} +``` + +### Lessons + +[jailbreak](/microbit/lessons/jailbreak) + +### See also + +[for](/microbit/reference/loops/for), [while](/microbit/js/while) + diff --git a/docs/reference/js/call.md b/docs/reference/js/call.md new file mode 100644 index 00000000..cd696c7c --- /dev/null +++ b/docs/reference/js/call.md @@ -0,0 +1,63 @@ +# Call a Function + +How to call a function in your code. #docs #function #call #language + +### @parent js/language + + +Type a function name in your code to call an existing [function](/microbit/js/function) in your script. + +### Call a function + +1. In the Touch Develop editor, click a line of code to open the on-screen [Code Keyboard](/microbit/js/editor). + +2. Click `code` to see the functions in your script. + +2. Click the function that you want to call. + +3. Click `store in var` to store the return value in a variable. + +### Example: the square function + +Here's a function called `square`, with a [Number](/microbit/reference/types/number) input parameter: + +``` +/** + * // returns the square of the input parameter x + * @param x TODO + */ +export function square(x: number) : number { + let result: number + return x * x + return result +} +``` + +The following code calls the `square` function, passing it an input parameter (`x`), and storing the return value in the `result` variable: + +### ~hide + +``` +let x1 = 2 +``` + +### ~ + +``` +let result1 = square(x1) +``` + +Or this code, which displays the result of the `square` function (without first storing the value in a variable): + +``` +basic.showNumber(square(x1), 150) +``` + +### See all your functions + +To see a list of the functions in a script, open the script and then click `script` (in the upper-right corner). All of the functions appear under the **code** heading. Click on a function to open it in the editor. + +### See also + +[function parameters](/microbit/js/functionparameters), [create a function](/microbit/js/function), [return statement](/microbit/js/return) + diff --git a/docs/reference/js/code.md b/docs/reference/js/code.md new file mode 100644 index 00000000..92d53df4 --- /dev/null +++ b/docs/reference/js/code.md @@ -0,0 +1,31 @@ +# function + +A function with inputs and outputs. #docs #function #language + +### @parent js/language + + +To add a **functions** to your script, click the `script` button, then click the `+` `add new function` button + +### functions + +A **function** takes [inputs](/microbit/actionparameters), runs code and (optionally) returns an output. + +TouchDevelop functions are similar to `mathematical functions`. Consider the function that computes the square of `x`: `square(x) = x*x`. In code, it would look like this: + +``` +export function square(x: number) : number { + let result: number + return x * x + return result +} +``` + +### private function + +An function can be marked as **private** in the properties. A private function is not visible outside a library (if the script is a library) + +### documentation + +The comment(s) at the beginning of a function used to provide a description of its purpose. This text will show in the help area when the function is called from the code editor. This is particularly useful for [libraries](/microbit/libraries). + diff --git a/docs/reference/js/collections.md b/docs/reference/js/collections.md new file mode 100644 index 00000000..4bde7f8a --- /dev/null +++ b/docs/reference/js/collections.md @@ -0,0 +1,111 @@ +# The Collections Library + +#docs + +A collection allows you to store an arbitrary number of elements. If you have a collection of numbers, you can add new numbers to the collection; remove numbers; check if a number is in there; iterate over all the numbers in the collection. + +## Creation + +A collection is created as follows. Note that we are providing the *type* of the elements that are meant to go in the collection. + +``` +let c = ([]) +``` + +At the moment, you can create collections of numbers, booleans, strings, and any of the object types that you defined. + +**Important:** if your collection is a global variable, make sure you initialise it at the beginning of your script. + +``` +c = ([]) +``` + +Trying to use an uninitialised collection will crash the simulator, and display a sad face on the device. + +## Adding and finding elements; counting + +``` +c.push(3) +``` + +The line above just added the number `3` to the collection. One can think of a collection as a list, where `add` appends the element at the end of the list. + +At this stage, our collection has size `1`, meaning that the line below will display `1`. + +``` +basic.showNumber(c.length, 150) +``` + +We can add another number as follows. + +``` +c.push(5) +``` + +At this stage, the count of elements in the collection is `2`. We mentioned earlier that a collection is like a list: adding elements appends them at the end of the list. This means that, at this point in the program, the first element in the list is 3 (we added it earlier), and the second element in the list is 5 (we just added it). + +``` +basic.showNumber(c[0], 150) +``` + +Can you guess what the line above does? Remember that in computing, indexing starts at zero. This function takes the *first element* in the list. This means that the line above displays `3`. + +We can ask questions such as: "what is the index of this element"? The line below displays `1`, meaning that the number `5` is first found at index `1` (it is the *second* element in the list). + +``` +basic.showNumber(c.indexOf(5, 0), 150) +``` + +## Iterating over the elements + +A classic pattern consists in iterating over all the elements in the collection. Here's one way to do it: + +``` +for (let i = 0; i < c.length; i++) { + basic.showString("The element at index " + i.toString() + " is " + c[i].toString(), 150) +} +``` + +The code above will first print `The element at index 0 is 3`, then `The element at index 1 is 5`. + +## Modifying and removing elements + +One can modify an existing collection using `set at`, which changes the element *at a given index*. + +``` +c[0] = 7 +``` + +The line above modifies the collection `c` so that, after the line above, the first element of the collection is now `7`. + +Removing elements can be done in two different ways. We can remove the *first occurrence* of an element. + +``` +c.remove(5) +``` + +This removes the first occurrence of `5` in the list. At this point in the program, our list now has just one element (at index 0). If we wish, we can use `remove at` to remove the element at a given index. + +``` +c.splice(0, 1) +``` + +Now, the collection is empty. + +## Complete example + +This program will record the current acceleration measured on `x` when you press `A`; when you press `B`, the program will print out all the acceleration values that were measured, then will clear the collection. + +``` +let accelerations = ([]) +input.onButtonPressed("A", () => { + accelerations.push(input.acceleration("x")) +}) +input.onButtonPressed("B", () => { + for (let i1 = 0; i1 < accelerations.length; i1++) { + basic.showString(accelerations[i1].toString(), 150) + } + accelerations.clear() +}) +``` + diff --git a/docs/reference/js/comment.md b/docs/reference/js/comment.md new file mode 100644 index 00000000..4974d5a4 --- /dev/null +++ b/docs/reference/js/comment.md @@ -0,0 +1,79 @@ +# Comment + +A note in code. #docs #comment #language + +### @parent js/statement + + +A comment is a line of code that contains text, usually an explanation or a note. All comments are ignored during script execution. + +### Block + +Right click on any block and add a comment + +### Touch Develop syntax + +To insert a comment in a Touch Develop script: + +1. Click a line in your script. + +2. Click `+`. + +3. Click `// comment` and then type some text (your comment). + +### ~hint + +To find out how to insert comments using the Blocks editor, see [the Blocks editor](/microbit/blocks/editor). + +### ~ + +### Sample function with comments + +This function has comments that describe the purpose of the function: + +``` +/** + * // square function : + * // returns the square of the input parameter x + * @param x TODO + */ +export function square(x: number) : number { + let result: number + return x * x + return result +} +``` + +### Formatting + +Use [markdown syntax](/microbit/js/markdown) to format your comments (for example, **bold** and *italic* formatting). + +### Commenting out code + +During the debugging process, you may want to comment out a section of your code so that it doesn't run. + +To comment out a block of code: + +1. Click the first line of code that you want to comment out. + +2. Press and hold the Shift key, and then press the Down arrow key to select a block of code. + +3. In the block editing window, scroll down to **surround with** and click `comment out`. This adds an [if](/microbit/reference/logic/if) statement around your code, like this: + +``` +if (false) { + // the commented code here... +} +``` + +When you want to uncomment your code, click the `if false then` statement in your code, and then click `uncomment`. + +### Library and function comments + +* Use [comments](/microbit/js/comment) at the beginning of a library to describe the library +* Use [comments](/microbit/js/comment) at the beginning of a [function](/microbit/js/function) to describe a function. The comment will appear in the help area of the Touch Develop editor when you insert the function + +### See also + +[markdown syntax](/microbit/js/markdown), [Touch Develop editor](/microbit/js/editor), [Block editor](/microbit/blocks/editor) + diff --git a/docs/reference/js/compiler.md b/docs/reference/js/compiler.md new file mode 100644 index 00000000..4e629a33 --- /dev/null +++ b/docs/reference/js/compiler.md @@ -0,0 +1,30 @@ +# In-browser compiler + +The BBC micro:bit pins #docs #gnd #p1 #p2 #p3 #3V + +## We listened to your feedback! + +Following the feedback from teachers, the following improvements were made: + +* compile without signing in +* compile offline +* save and load code using files + +## A new in-browser compiler + +The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The BBC micro:bit compilation process (see page 10 in the Quick Start book) has been updated below to reflect the new compiler architecture, shown below. + +![](/static/mb/offline-2.png) + +The C++ compiler now only is used to compile the micro:bit runtime - this is done offline by the micro:bit team and the precompiled runtime linked with your compiled script in the browser. + +## Save and load code using files + +![](/static/mb/offline-0.png) + +The BBC micro:bit automatically saves and synchronizes scripts for signed in users through the cloud. Unfortunately, this scenario would not work always so we decided to also support files. Users are now able to import and export scripts as files. For example, they can simply email it or submit them in their classroom portal. + +![](/static/mb/offline-1.png) + +Compiled .hex files can also be imported back into the web site. This make it easy for a teacher to review the source of a script by simply drag and dropping the file into the editor. + diff --git a/docs/reference/js/contents.md b/docs/reference/js/contents.md new file mode 100644 index 00000000..5285ea84 --- /dev/null +++ b/docs/reference/js/contents.md @@ -0,0 +1,216 @@ +# Touch Develop Documentation + +Touch Develop docs for the micro:bit #docs #contents #apis #functions #language #statements + +### @section full + +### @parent editor-documentation + +### @short Touch Develop + +### ~hint + +**Spotty internet? No problem!** (1) When online, go to https://www.microbit.co.uk/app/ and bookmark this URL; (2) use the bookmark to reload the web app, even without the internet. + +### ~ + +Welcome to the Touch Develop home page for the BBC micro:bit. Below you will find resources about the Touch Develop programming language and code editor. Good places to start include: + +* [the Touch Develop Editor](/microbit/js/editor) +* [30+ BBC micro:bit lessons](/microbit/lessonss) +* [offline support](/microbit/offline) + +### ~column + +## Language {#pconst} + +### Variables + +* [local variables](/microbit/reference/variables/var) +* [global variables ](/microbit/js/data) + +### Types + +* [Number](/microbit/reference/types/number) +* [Boolean](/microbit/reference/types/boolean) +* [String](/microbit/reference/types/string) +* [Image](/microbit/reference/image/image) + +### Statements and control structures + +* [assignment operator](/microbit/reference/variables/assign) `:=` +* [if](/microbit/reference/logic/if) +* [for](/microbit/reference/loops/for) +* [while](/microbit/js/while) +* [break](/microbit/js/break) +* [forever](/microbit/reference/basic/forever) +* [in background](/microbit/reference/control/in-background) +* [function](/microbit/js/function) +* [return](/microbit/js/return) + +### Maths + +* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [Numbers](/microbit/reference/types/number) +* comparison operators (such as `>`, `=`) on [Numbers](/microbit/reference/types/number) +* the [math](/microbit/js/math) library +* the [bits](/microbit/js/bits) library + +### Logical + +* [Boolean](/microbit/reference/types/boolean) values `true` and `false` +* Operations (`not`, `or`, `and`) on [Booleans](/microbit/reference/types/boolean) + +### Strings + +* [string functions](/microbit/reference/types/string-functions) + +### Functions + +* [create a function](/microbit/js/function) +* [function parameters](/microbit/js/functionparameters) +* [call a function](/microbit/js/call) + +### Collections + +* read the [collections tutorial](/microbit/js/collections) + +### Custom object types + +* see the [object types tutorial](/microbit/js/object-types) +* read the [object disclaimer](/microbit/js/object-disclaimer) if you're an advanced user + +### Libraries + +* [create and use libraries](/microbit/js/libraries) + +### Documentation + +* [comments](/microbit/js/comment) +* [markdown syntax](/microbit/js/markdown) + +### ~ + +### ~column + +## BBC micro:bit functions + +### Basic + +* [clear screen](/microbit/reference/basic/clear-screen) +* [forever](/microbit/reference/basic/forever) +* [pause](/microbit/reference/basic/pause) +* [show leds](/microbit/reference/basic/show-leds) +* [show animation](/microbit/reference/basic/show-animation) +* [show number](/microbit/reference/basic/show-number) +* [show string](/microbit/reference/basic/show-string) + +### LED + +* [brightness](/microbit/reference/led/brightness) +* [fade in](/microbit/reference/led/fade-in) +* [fade out](/microbit/reference/led/fade-out) +* [plot](/microbit/reference/led/plot) +* [plot all](/microbit/reference/led/plot-all) +* [point](/microbit/reference/led/point) +* [screenshot](/microbit/functions/screenshot) +* [set display mode](/microbit/functions/set-display-mode) +* [set brightness](/microbit/reference/led/set-brightness) +* [stop animation](/microbit/reference/led/stop-animation) +* [toggle](/microbit/reference/led/toggle) +* [toggle all](/microbit/reference/led/toggle-all) +* [unplot](/microbit/reference/led/unplot) + +### Input + +* [acceleration](/microbit/reference/input/acceleration) +* [rotation](/microbit/functions/rotation) +* [button is pressed](/microbit/reference/input/button-is-pressed) +* [compass heading](/microbit/reference/input/compass-heading) +* [temperature](/microbit/reference/input/temperature) +* [running time](/microbit/reference/input/running-time) +* [on shake](/microbit/reference/input/on-gesture) +* [on button pressed](/microbit/reference/input/on-button-pressed) +* [on logo down](/microbit/functions/on-logo-down) +* [on logo up](/microbit/functions/on-logo-up) +* [on pin pressed](/microbit/reference/input/on-pin-pressed) +* [on screen down](/microbit/functions/on-screen-down) +* [on screen up](/microbit/functions/on-screen-up) +* [pin is pressed](/microbit/reference/input/pin-is-pressed) + +### Image + +* [create image](/microbit/reference/images/create-image) +* [clear](/microbit/reference/basic/clear-screen) +* [pixel](/microbit/reference/images/pixel) +* [plot frame](/microbit/reference/led/plot-frame) +* [plot image](/microbit/reference/led/plot-image) +* [scroll image](/microbit/reference/images/scroll-image) +* [show frame](/microbit/functions/show-frame) +* [set pixel](/microbit/reference/images/set-pixel) +* [show image](/microbit/reference/images/show-image) +* [width](/microbit/functions/width) + +### Music + +* [play note](/microbit/functions/play-note) +* [note](/microbit/functions/note) +* [ring](/microbit/reference/music/ring) + +### Pins + +* [digital read pin](/microbit/reference/pins/digital-read-pin) +* [digital write pin](/microbit/reference/pins/digital-write-pin) +* [analog read pin](/microbit/reference/pins/analog-read-pin) +* [analog write pin](/microbit/reference/pins/analog-write-pin) +* [analog set period](/microbit/reference/pins/analog-set-period) +* [analog pitch](/microbit/reference/pins/analog-pitch) +* [analog set pitch pin](/microbit/reference/pins/analog-set-pitch-pin) +* [servo write pin](/microbit/reference/pins/servo-write-pin) +* [servo set pulse](/microbit/reference/pins/servo-set-pulse) +* [map](/microbit/functions/map) + +### Control + +* [in background](/microbit/reference/control/in-background) +* [reset](/microbit/functions/reset) + +### Devices + +Functions in this category require to be connected to a remote device. + +* [tell camera to](/microbit/reference/devices/tell-camera-to) +* [tell remote control to](/microbit/reference/devices/tell-remote-control-to) +* [raise alert to](/microbit/reference/devices/raise-alert-to) +* [on notified](/microbit/reference/devices/on-notified) + +### Libraries + +* [game library](/microbit/js/game-library) +* [serial library](/microbit/js/serial-library) + +### ~ + +### ~column + +## Run + +* [scripts in the browser](/microbit/js/simulator) +* [scripts on your BBC micro:bit](/microbit/device/usb) + +## Debugging + +* use the [serial library](/microbit/js/serial-library) to print data from your micro:bit on your computer +* learn about the [device error codes](/microbit/device/errors) that are displayed when sad faces occur + +## Edit/Publish + +* [the Touch Develop Editor](/microbit/js/editor) +* [publish a script](/microbit/js/publishing) + +## Creating Tutorials + +* [create a tutorial](/microbit/js/create-tutorials) +* [markdown syntax](/microbit/js/markdown) + +### ~ + diff --git a/docs/reference/js/data.md b/docs/reference/js/data.md new file mode 100644 index 00000000..d786b259 --- /dev/null +++ b/docs/reference/js/data.md @@ -0,0 +1,112 @@ +# Global Variables + +How to define and use global variables. #docs #data #language #variables + +### @parent js/language + +A variable is a place where you can store data so that you can use it later in your code. A *global* variable is accessible from every point in your code. + +### Block Editor + +In the Block Editor, all variables are global. See [Block Editor](/microbit/blocks/editor) for info on creating global variables in a Block Editor script. The following block is used to set (assign) global variable's value: + +![](/static/mb/antenna-0.png) + +The block below retrieves (gets) the current value of a global variable: + +![](/static/mb/data-0.png) + +### Touch Develop + +In Touch Develop variables are either [global](/microbit/js/data) or [local](/microbit/reference/variables/var). Variables have a name, a [type](/microbit/js/types), and value: + +* the *name* is how you'll refer to the variable +* the *type* refers to the kind of value a variable can store +* the *value* refers to what's stored in the variable + +[Global variables](/microbit/js/data) are variables that are available throughout your script. Unlike [local variables](/microbit/reference/variables/var), global variables are accessible across functions and in nested code blocks. + +### Create a global variable + +To create a new global variable: + +1. In the Touch Develop [editor](/microbit/js/editor), click `script` (to the right of the search box). + +2. Click `+` **add new**. + +3. Click `data->` **data** and then choose a [type](/microbit/js/types). + +4. Enter a name for your global variable and click **OK**. + +### Set and use a global variable + +To use a global variable that you've declared (using steps above): + +1. In the Touch Develop [editor](/microbit/js/editor), click `data-> ` **data** or `data->` + *variable name*. + +2. Click `:=` (assignment). + +2. Click on the right-side of `:=` and type or click what you want to store in the variable. + +Your code should look something like this: + +// global number variable + +``` +counter = 2 +``` + +// global string variable + +``` +name2 = "Mike" +``` + +// global boolean variable + +``` +bool = true +``` + +(for info on creating image variables, see [Image](/microbit/reference/image/image)) + +Once you've defined a variable and set it's initial value, use the variable's name whenever you need what's stored in the variable. For example, the following code gets the value stored in the global `counter` variable and shows it on the screen: + +``` +basic.showNumber(counter, 100) +``` + +To change the contents of a variable use the [assignment operator](/microbit/reference/variables/assign) `:=`. The following code increments `counter` by 10: + +``` +counter = counter + 10 +``` + +### Promote, demote, and extract + +To **promote** a local variable to a global variable: + +* select the local variable name and click `promote to data`. The [var](/microbit/reference/variables/var) keyword changes to the data symbol `data->`. + +To **demote** a global variable to a local variable: + +* select the global variable name and click `demote to var` + +To **extract** the content of a global variable to a local variable: + +* select the global variable name and click `extract to var` + +### See your global variables + +To see a list of the global variables in your script: + +* click `script` (along the top) and scroll down to the **vars** heading + +### Lessons + +[counter](/microbit/lessons/counter), [rotation animation](/microbit/lessons/rotation-animation), [digital pet](/microbit/lessons/digital-pet), [offset image](/microbit/lessons/offset-image) + +### See also + +[local variables](/microbit/reference/variables/var), [types](/microbit/js/types), [assignment operator](/microbit/reference/variables/assign) + diff --git a/docs/reference/js/editor.md b/docs/reference/js/editor.md new file mode 100644 index 00000000..49767225 --- /dev/null +++ b/docs/reference/js/editor.md @@ -0,0 +1,112 @@ +# Touch Develop Editor + +The Touch Develop editor. #docs #editor #scripts #compile #run #keyboard + +### @parent js/contents + + +The Touch Develop editor is where you write and test your code. If you're new to Touch Develop, check out the [Touch Develop editor video](/microbit/getting-started/touchdevelop-editor). + +To create a new Touch Develop script: + +1. Go to the micro:bit website and click **Create Code** (along the top). + +2. Under the Touch Develop editor heading, click **New project**. + +3. Type a name for your script and click **create**. + +An empty script with a [function](/microbit/js/function) called `main` is created. + +## The Editor Menu Bar + +The Touch Develop editor has a bar of options above the code area: + +![](/static/mb/data-1.jpg) + +* `my scripts` takes you back to a list of your scripts (My Scripts). The open script is automatically saved (in the cloud) when you leave the editor. +* `run` executes your script, showing you the results on the on-screen micro:bit device. See [run scripts in the browser](/microbit/js/simulator) for more about this. +* `compile` sends your script to an ARM compiler, which creates a file that you can run on your micro:bit. See [run scripts on your micro:bit](/microbit/device/usb) for more info. +* `undo` undoes changes that you made to your script. +* `search code...` search for functions in libraries such as the micro:bit library. +* `script` opens script options, where you can do things like publish and preview. See **script options** below. + +Many of the above buttons aren't much use until you've written some code, so let's move on to the Code Keyboard. + +## Code Keyboard + +The Code Keyboard makes it easy to write code on a touch screen device or by using your mouse. You can also type code using your computer keyboard if you know what function or statement you want (see [Touch Develop documentation](/microbit/js/contents) for a complete list). + +To open the Code Keyboard, click on a line of code: + +![](/static/mb/data-2.jpg) + +An on-screen keyboard appears, with buttons that vary depending on what's selected. + +### Statements + +The first row of the Code Keyboard has Touch Develop [statements](/microbit/js/statements) that you can insert into your code. These buttons are blue and include things like [var](/microbit/reference/variables/var), [if](/microbit/reference/logic/if), [for](/microbit/reference/loops/for) , and [while](/microbit/js/while). Click `more` to see additional statements. + +### The BBC micro:bit, math, and code buttons + +* `micro:bit`: click to see all the [micro:bit functions](/microbit/js/contents); click `more` to scroll left to right. The micro:bit functions are also grouped together behind the following category buttons: `basic`, `control`, `input`, `image`, `led`, and`pins` +* `code`: click to access functions you've written (see [call a function](/microbit/js/call) for more info) +* `math`: click to see [math functions](/microbit/js/math); such as `abs` and `round` +* `bits`: click to see functions for bit-level manipulation of integers + +### Editing code: add, copy, paste, and cut + +In the coding area... + +* **add**: to add a new line, click on a line and then click a **+** to add a new line above or below the current line +* **copy, paste, cut**: click on a line then click **copy** or **cut**. Then click on a new line, and click **paste**. + +### Block editing + +To copy, cut, or comment out a block of code (more than one line): + +1. Click on a line of code. + +2. Press and hold the `Shift` key, and then press the `Up arrow` or `Down arrow` key on your keyboard (this selects multiple lines). + +3. Choose a block editing option like copy, cut, or [comment out](/microbit/js/comment). + +### Script options + +Click `script` (in the upper-right corner) to open the script options: + +![](/static/mb/data-3.jpg) + +Here you'll find options like... + +* `script properties`: the script name, description, and whether or not the script is a library (more info below) +* `publish`: share a script with other users by [publishing](/microbit/js/publishing) it +* `share`: share a link to a published script (see [publish as script](/microbit/js/publishing) for more info) +* `preview`: preview a documentation script +* `+` `add new`: add a new [function](/microbit/js/function), [global variable](/microbit/js/data), picture, or library to a script +* *code*: the functions in your script; click a function to open it in the editor +* *global vars*: the [global variables](/microbit/js/data) in your script; click a variable to go to that variable +* *libraries*: the libraries added to your script +* *art*: picture and video resources added to your script + +### Script properties + +To edit a script's properties, click `script` (in the upper-right corner), and then click the script name or script properties. + +![](/static/mb/data-4.png) + +* `name`: the script's name (60 character limit) +* `description`: a description of what your script does along with #hashtags for search (for example, #game or #maker). Hashtags are especially important if you publish your script (200 character limit). +* `this script is a library`: click this check box to turn a script into a library + +### Comments + +Comments are notes within your scripts. To learn how to insert comments into your scripts, see [Comments](/microbit/js/comment). You can format your comments using [markdown syntax](/microbit/js/markdown). + +### Share your scripts + +Share your scripts with other people by publishing them. See [publish a script](/microbit/js/publishing) for more info. + +### See also + +[publish a script](/microbit/js/publishing), [Touch Develop documentation](/microbit/js/contents) + diff --git a/docs/reference/js/event-handler.md b/docs/reference/js/event-handler.md new file mode 100644 index 00000000..a11a1001 --- /dev/null +++ b/docs/reference/js/event-handler.md @@ -0,0 +1,59 @@ +# event handler + +Event handlers - how they work. #eventhandler #docs #input #button + +An event handler is code that is associated with a particular event, such as "button A pressed". You create (or register) the association between an event and an event handler by calling a function named "on ". After registering an event handler with an event, then whenever that event occurs, the event handler code executes. + +### Registering an event handler + +Functions named "on " create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A: + +``` +input.onButtonPressed("A", () => { + basic.showString("hello", 150) +}) +``` + +After this code executes, then whenever button A is pressed in the future, the string "hello" will be printed. + +### Event handlers are active for the entire program execution + +Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute: + +``` +input.onButtonPressed("A", () => { +}) +``` + +The above code associated an event handler that does nothing with the event of a press of button A. + +### There is only one event handler per event + +The above example also illustrates that there is only one event handler for each event. What is the result of the following code? + +``` +input.onButtonPressed("A", () => { + basic.showString("hello", 150) +}) +input.onButtonPressed("A", () => { + basic.showString("goodbye", 150) +}) +``` + +The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this: + +``` +input.onButtonPressed("A", () => { + basic.showString("hello", 150) + basic.showString("goodbye", 150) +}) +``` + +### To learn more + +To learn more about how the BBC micro:bit queues up and schedules event handlers, see [the BBC micro:bit - a reactive system](/microbit/device/reactive) + +### see also + +[on button pressed](/microbit/reference/input/on-button-pressed), [on logo up](/microbit/functions/on-logo-up), [on logo down](/microbit/functions/on-logo-down), [on screen up](/microbit/functions/on-screen-up), [on screen down](/microbit/functions/on-screen-down), [on shake](/microbit/reference/input/on-gesture), [on pin pressed](/microbit/reference/input/on-pin-pressed) + diff --git a/docs/reference/js/events.md b/docs/reference/js/events.md new file mode 100644 index 00000000..3337ae20 --- /dev/null +++ b/docs/reference/js/events.md @@ -0,0 +1,81 @@ +# Events Library + +The events library #docs + +The functions in the events namespace allow the BBC micro:bit to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the BBC micro:bit apps available for the remote device. The events accessible from Touch Develop are listed below. + +### Remote control + +Control the presentation of media content available on a remote device using the `remote control` function + +``` +export function remoteControl(event: string) +``` + +The remote control specific events include: + +* play +* pause +* stop +* next track +* previous track +* forward +* rewind +* volume up +* volume down + +### Camera + +Access the photo/video-taking functionality of a remote device using the *camera* function: + +``` +export function camera(event: string) +``` + +The camera-specific events include: + +* toggle front-rear +* launch photo mode +* take photo +* stop photo mode +* launch video mode +* start video capture +* stop video capture +* stop video mode + +### Alert + +Raise an alert on a remote device using the `alert` function + +``` +export function alert(event: string) +``` + +The set of alerting-specific events include: + +* display toast +* vibrate +* play sound +* play ringtone +* find my phone +* alarm 1 +* alarm 2 +* alarm 3 +* alarm 4 +* alarm 5 +* alarm 6 + +### Audio recorder + +Access the audio recording capabilities of the device using the `audio recording` function + +``` +export function audioRecorder(event: string) +``` + +The set of audio recorder events include: + +* launch +* start capture +* end capture +* stop diff --git a/docs/reference/js/for.md b/docs/reference/js/for.md new file mode 100644 index 00000000..0127b27e --- /dev/null +++ b/docs/reference/js/for.md @@ -0,0 +1,83 @@ +# For + +Repeat code a preset number of times. #docs #for #endfor #language + +### @parent js/language + + +Repeat code a fixed number of times. + +### Block Editor + +![](/static/mb/events-0.png) + +The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times: + +``` +for (let k = 0; k < 4; k++) { +} +``` + +### Touch Develop + +### ~hide + +``` +let upper = 5 +``` + +### ~ + +``` +for (let k1 = 0; k1 < upper; k1++) { + // Add code to repeat here, also called the `loop body` +} +``` + +where + +* `0` is initial value of the loop index variable `k` +* the value of `k` increases by 1 after each execution of the `loop body` +* `upper` is the number of times the loop body will repeat + +In other words, the index variable (`k`) starts at 0 and increases by 1 each time the `loop body` executes, until `k = upper`. + +### Example: count to 5 + +The following example displays numbers 1 through 5 on the LED screen: + +``` +for (let i = 0; i < 5; i++) { + basic.showNumber(i + 1, 100) + basic.pause(500) +} +``` + +### Example: draw a box + +The [LED screen](/microbit/device/screen) has a fixed number of rows and columns (5x5), which is ideal for a for loop. This example uses a for loop to turn on the LEDs along the edge of the screen, making a square. + +``` +for (let i1 = 0; i1 < 5; i1++) { + led.plot(0, i1) + led.plot(4, i1) + led.plot(i1, 0) + led.plot(i1, 4) + basic.pause(500) +} +``` + +### ~hint + +Want to exit a loop early? The [break](/microbit/js/break) statement exits a loop before the end value is reached. + +### ~ + +### Lessons + +[looper](/microbit/lessons/looper), [strobe light](/microbit/lessons/strobe-light) + +### See also + +[while](/microbit/js/while), [break](/microbit/js/break), [if](/microbit/reference/logic/if) + diff --git a/docs/reference/js/function.md b/docs/reference/js/function.md new file mode 100644 index 00000000..bcac7c81 --- /dev/null +++ b/docs/reference/js/function.md @@ -0,0 +1,117 @@ +# Create a Function + +How to define a function with input and output parameters. #docs #function #language + +### @parent js/language + + +A function is a unit of code that performs a specific task and returns a result. + +Functions are ideal when you need to perform an action multiple times. Instead of repeating a block of code in your script, you can put the code in a function and simply [call the function](/microbit/js/call) when needed. + +*Why use functions?* Functions makes your code easier to read, debug, and update. + +### Add a function + +To add a function to a Touch Develop script: + +1. Open a script and then click `script` (in the upper-right corner). + +2. Click `+` **add new**. + +3. Click **function()**. + +A new function appears, like this: + +``` +export function doStuff(p: number) { +} +``` + +Functions begin with the `function` keyword and end with `end function`. The function name appears after the `function` keyword (in this case, `do stuff`). + +### ~hint + +Click the function name to edit the function properties (i.e. change the name or add parameters - see below). + +### ~ + +### Function components + +Functions have three parts: + +* [input and output parameters](/microbit/js/functionparameters) +* the function *body* (the code that performs a task) + +- one or more [return](/microbit/js/return) statements (the output of the function) + +#### Example function + +``` +/** + * // returns the square of the input parameter x + * @param x TODO + */ +export function square(x: number) : number { + let result: number + return x * x + return result +} +``` + +In the above code... + +* ``x `` is the [input parameter](/microbit/js/functionparameters) ([Number](/microbit/reference/types/number) type) +* ``result`` is the [output parameter](/microbit/js/functionparameters) ([Number](/microbit/reference/types/number) type) +* `return x * x` is the function body (which returns the value of the expression `x * x`) + +### Add function parameters + +1. Open your function (if needed). To do this, open your script and then click `script` (in the upper-right corner). + +2. Under **code** click your function name. + +3. Click the function name in the code window. This opens the function panel. + +4. Click **add input parameter** or **add output parameter**. The parameter is added to your function. + +Click the parameter name to rename it and click the [type](/microbit/js/types) to change the variable type. For more info, see [function parameters](/microbit/js/functionparameters). + +### ~hide + +### Extract code into a function + +If you've already written some code that you'd like to have in a function, you can extract the code. Here's how: + +1. Click the first line of code that you want to extract. + +2. Press and hold the Shift key, and then press the Down arrow on your keyboard to select multiple lines of code. + +3. In the block editing window, scroll down to **extract selection into function** and click `extract`. + +### ~ + +### Function documentation + +Use a [comment](/microbit/js/comment) at the beginning of your functions to describe the function. When you insert a function into your code, the comment text appears in the help area of the Code Keyboard. + +### See all your functions + +To see all the functions in a script, open the script and then click `script` (in the upper-right corner). All of the functions in your script appear under **code**. + +### ~hide + +### Private functions + +If you don't want people to see the code in your function, you can make the function private. To do this, open the function, click the function name, and then mark the **private function** check box. Private functions have a locked icon instead of a play icon. + +### ~ + +### Lessons + +[digital pet](/microbit/lessons/digital-pet) + +### See also + +[function parameters](/microbit/js/functionparameters), [call a function](/microbit/js/call), [return from a function](/microbit/js/return) + diff --git a/docs/reference/js/functionparameters.md b/docs/reference/js/functionparameters.md new file mode 100644 index 00000000..40bd3fe4 --- /dev/null +++ b/docs/reference/js/functionparameters.md @@ -0,0 +1,66 @@ +# Function Parameters + +How to use parameters to pass info in and out of an function. #docs #input #output #function #functionparameters + +### @parent js/function + + +A [function](/microbit/js/function) can have multiple input parameters and/or a single output parameter. The parameters must be one of the supported variable [types](/microbit/js/types). + +When you first [create a function](/microbit/js/function), it looks like this: +``` +export function doStuff() { +} +``` + +### Add a function parameter + +1. Open your script (if needed) and then click `script` in the upper-right corner. + +2. Under **code** click your function name. + +3. Click the function name in your code (this opens the function panel). + +4. Click **add input parameter** or **add output parameter**. The parameter is added to your function. + +#### Input parameters + +The default type for an input parameter is [Number](/microbit/reference/types/number): + +``` +export function oneInput(p: number) { +} +``` + +To change the default type, click the type ([Number](/microbit/reference/types/number) in this case) and change it to [String](/microbit/reference/types/string), [Boolean](/microbit/reference/types/boolean), or [Image](/microbit/reference/image/image). You can add multiple input parameters to a function. + +#### Output parameter + +the default type for an output parameter is [Number](/microbit/reference/types/number): + +``` +export function output() : number { + let r: number + return 42 + return r +} +``` + +To change the default type, click the type ([Number](/microbit/reference/types/number) in this case) and change it to [String](/microbit/reference/types/string), [Boolean](/microbit/reference/types/boolean), or [Image](/microbit/reference/image/image). + +### Inputs and output function + +The following sample function has two inputs and one output parameter (all are the Number type): + +``` +export function inputsAndOutput(p: number, q: number) : number { + let r: number + return p + q + return r +} +``` + +### See also + +[call a function](/microbit/js/call), [create a function](/microbit/js/function), [return](/microbit/js/return) + diff --git a/docs/reference/js/gallery.md b/docs/reference/js/gallery.md new file mode 100644 index 00000000..605110c5 --- /dev/null +++ b/docs/reference/js/gallery.md @@ -0,0 +1,106 @@ +# Gallery + +Overview of Touch Develop lessons for the BBC micro:bit. #docs #contents + +### @short Gallery + +### ~column + + +## Maker + +* [Telegraph](/microbit/pzeagwoudd), play the telegraph game between 2 BBC micro:bits +* [Ornament Chain](/microbit/rnvpgo), play the ornament chain game between 2 BBC micro:bits + +### ~hide + +* [The Watch](/microbit/lessons/the-watch), design and create The Watch +* [Hack your headphones](/microbit/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones +* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits + +### ~ + +## Beginner + +* [Night light](/microbit/vltwrzuqto), dim the LEDs with set brightness +* [Beautiful image](/microbit/nudwzmphyx), show a beautiful image with show LEDs +* [Smiley,](/microbit/zsohipimef) smiley and frowney with show animation +* [Lucky 7](/microbit/rqhxxqppqu), show a number on the LED screen with show number +* [Answering machine](/microbit/bnkmeqymuh), show a text message with show string +* [Snowflake fall](/microbit/zhcfmiejlg), repeat an animation with forever +* [Screen wipe](/microbit/hlnitnqjjk), turn off the LEDs with clear screen +* [Flashing heart](/microbit/bwmxfwqswx), display images with a pause +* [Blink](/microbit/jbbutifslm), turn an LED on and off with plot + +### ~hide + +* [Bounce image](/microbit/lessons/bounce-image), scroll an image across the screen on shake +* [Magic logo](/microbit/lessons/magic-logo), show an image on logo up +* [Glowing sword](/microbit/lessons/glowing-sword), make a glowing sword with fade in and fade out + +### ~ + +### ~column + +## Intermediate + +* [Zoomer](/microbit/fwrohhjqql), measure the force with acceleration +* [Strobe light](/microbit/jguqlzeayr), develop shapes with a nested for loops +* [Digi yoyo](/microbit/lppocrbpys), create a counter with a while loop +* [Die roll](/microbit/lzblatmknq), spin with more if statements +* [Spinner](/microbit/dzijduruek), spin the arrow with multiple if statements +* [Truth or dare](/microbit/filuzbwauo), a game that forces each player to reveal a secret or do something funny with if statement +* [Love meter](/microbit/rrmlrvojfa), create a love meter with on pin pressed +* [Guess the number](/microbit/ftsenbvqwz), guess a random number with random +* [Magic 8](/microbit/fyjinpjuqu), a fortune teller game with the BBC micro:bit +* [Counter](/microbit/rerlmjgjut), display a number with a variable +* [Glowing pendulum](/microbit/xrnsveuwxj), construct a pendulum that glows using acceleration +* [Looper](/microbit/nxcddtbizi), display a series of numbers with a for loop index + +### ~hide + +* [Rotation animation](/microbit/lessons/rotation-animation), control an animation with a boolean variable +* [Offset image](/microbit/lessons/offset-image), shift an image horizontally with image offset +* [Compass](/microbit/lessons/compass), displays the direction the BBC micro:bit is pointing + +### ~ + +### ~column + +## Advanced + +* [Rock paper scissors](/microbit/tnmtbvyyma), use image offsets with local variables +* [Digital pet](/microbit/vefocoajpb), a display of pet images with sub-functions +* [Catch the egg](/microbit/reczlreqob), catch falling eggs in a basket with an acceleration controller +* [Headbands](/microbit/bzrusu), create a charades game with a collection of strings that hold the words +* [Prank WiFi](/microbit/dceikq), create fake WiFi to trick your friends +* [Flipping bird](/microbit/lbhvywjzkv), use modulo with a conditional +* [Runaway pac man](/microbit/loafab), construct the game pac man with the BBC micro:bit +* [Line of Fire](/microbit/fzcoly), make a game to test hand-eye coordination +* [The hat game](/microbit/njynsd), make a game to test your focus on the moving ball +* [Pong](/microbit/xcenyy), a light bouncing from left to right +* [Meteorite](/microbit/zaidka), a game where meteorites are coming for you one by one +* [Minesweeper](/microbit/jaeeve), make a game to test your memory for placing a LED mine then finding the hidden LED mine +* [Bop it](/microbit/zlpndm), a game where you have to keep up with the commands +* [Letter Up](/microbit/ftlqjo), a guessing game with string operators with string at +* [Racing Buttons](/microbit/hcuxid), racing game to determine if player 1 presses Button A faster or if player 2 presses Button B faster + +### ~hide + +* [Transformers](/microbit/lessons/transformers), use functions to return values +* [Speed button](/microbit/lessons/speed-button), code a speed game with running time +* [Jailbreak](/microbit/lessons/jailbreak), break out of a counting loop by pressing button "A" +* [2 player pong](/microbit/bzycll), collaborate with a classmate to develop Pong on multiple BBC micro:bits + +### ~ + +### ~hide + +* [Number psych](/microbit/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple BBC micro:bits and a breadboard + +### ~ + +### @section full + +The lessons promote computational thinking and computer science literacy[ read more...](/microbit/lessons/teach) + diff --git a/docs/reference/js/game-library.md b/docs/reference/js/game-library.md new file mode 100644 index 00000000..951b591b --- /dev/null +++ b/docs/reference/js/game-library.md @@ -0,0 +1,155 @@ +# Game Library + +The game library #docs + +The game library supports simple single-player time-based games. The player has a number of **lives** and a **score**. The game has a number of **levels** and a **countdown clock**. The general goal of a game will be to achieve a top score before time runs out or the number of lives goes to zero. + +## Touch Develop + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### [Countdown](/microbit/js/game-library/start-countdown) + +If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. + +* start a countdown with the maximum duration of the game in milliseconds. + +``` +export function startCountdown(ms: number) +``` + +### [Game over](/microbit/js/game-library/game-over) + +If the `life` reaches zero or the time expires (see countdown), the game enters the **game over** mode. When the game is over, `game->is running` returns false + +* check if the game still running. + +``` +export function isRunning() : boolean +``` + +Indicates if the game is display the game over sequence. + +``` +export function isGameOver() : boolean +``` + +You can also end the game by calling the `game -> game over` function: + +``` +export function gameOver() +``` + +### Score + +When a player achieves a goal, you can increase the game score + +[Add Point to Score](/microbit/js/game-library/add-point-to-score) + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +[Score](/microbit/js/game-library/score) + +* set the current score to a particular value. + +``` +export function setScore(value: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Life + +Manage the player lives. When the life count reaches 0 or less, the game is over. + +* remove one or more lives + +``` +export function removeLife(life: number) +``` + +* add lives + +``` +export function addLife(lives: number) +``` + +* set the life to a particular value + +``` +export function setLife(value: number) +``` + +* get the current life value + +``` +export function life() : number +``` + +### Levels + +When the game increases in difficulty, you can increase the level and use that value in your game logic. + +* increase the level by 1 + +``` +export function levelUp() +``` + +* get the current level + +``` +export function level() : number +``` + +### Time + +The game immediately starts tracking the time from the moment the device started. + +* get the current time + +``` +export function currentTime() : number +``` + +You can start the time again by using `game->start stopwatch`. + +* start the game timer + +``` +game.startStopwatch() +``` + +### Blink + +Reports the blink duration of a `sprite` . + +``` +export function blink(_this: micro_bitSprites.LedSprite) : number +``` + +Sets the blink duration interval in milliseconds . + +``` +export function setBlink(sprite: micro_bitSprites.LedSprite, ms: number) +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/js/game-library/add-point-to-score.md b/docs/reference/js/game-library/add-point-to-score.md new file mode 100644 index 00000000..2a526a94 --- /dev/null +++ b/docs/reference/js/game-library/add-point-to-score.md @@ -0,0 +1,43 @@ +# Add Points to Score + +The game library #docs + +The game library supports simple single-player time-based games. The player will ** add points to score**. + +## Block Editor + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen. + +![](/static/mb/game-library/add-point-to-score-0.png) + +## Touch Develop + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/js/game-library/change-score-by.md b/docs/reference/js/game-library/change-score-by.md new file mode 100644 index 00000000..9c2e7ddb --- /dev/null +++ b/docs/reference/js/game-library/change-score-by.md @@ -0,0 +1,43 @@ +# Change Score By + +The game library #docs + +The game library supports simple single-player time-based games. The player will ** add points to score**. + +## Block Editor + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible and the score will display on the screen. + +![](/static/mb/change-score-by-0.png) + +## Touch Develop + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/js/game-library/game-over.md b/docs/reference/js/game-library/game-over.md new file mode 100644 index 00000000..c89a389f --- /dev/null +++ b/docs/reference/js/game-library/game-over.md @@ -0,0 +1,24 @@ +# Game Over + +The game library #docs + +The game library supports simple single-player time-based games. The game can end the game by calling the `game over` function + +## Block Editor + +You can end the game by calling the `game over ` function. In this example, if BBC micro:bit's answer to the question is GAME OVER, GAME OVER will be displayed to end the game. + +![](/static/mb/game-library/game-over-0.png) + +## Touch Develop + +You can end the game by calling the `game -> game over` function: + +``` +game.gameOver() +``` + +### Lessons + +[game of chance](/microbit/lessons/game-of-chance) + diff --git a/docs/reference/js/game-library/score.md b/docs/reference/js/game-library/score.md new file mode 100644 index 00000000..4548c063 --- /dev/null +++ b/docs/reference/js/game-library/score.md @@ -0,0 +1,59 @@ +# Score + +The game library #docs + +The game library supports simple single-player games. The player has a **score**. + +## Block Editor + +The code below shows a simple game where the user gets to press the button ``A`` and adds 1 point to score that will be displayed on the BBC micro:bit screen + +![](/static/mb/game-library/add-point-to-score-0.png) + +## Touch Develop + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* set the current score to a particular value. + +``` +export function setScore(value: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Countdown + +If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. + +* start a countdown with the maximum duration of the game in milliseconds. + +``` +export function startCountdown(ms: number) +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/js/game-library/start-countdown.md b/docs/reference/js/game-library/start-countdown.md new file mode 100644 index 00000000..5ccaa3ed --- /dev/null +++ b/docs/reference/js/game-library/start-countdown.md @@ -0,0 +1,57 @@ +# Start Countdown + +The game library #docs + +The game library supports simple single-player time-based games. The general goal of a game will be to achieve a top score before time runs out of time. + +## Block Editor + +![](/static/mb/game-library/start-countdown-0.png) + +## Touch Develop + +The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. + +``` +input.onButtonPressed("A", () => { + game.addScore(1) +}) +game.startCountdown(10000) +``` + +### Score + +When a player achieves a goal, you can increase the game score + +* add score points to the current score + +``` +export function addScore(points: number) +``` + +* set the current score to a particular value. + +``` +export function setScore(value: number) +``` + +* get the current score value + +``` +export function score() : number +``` + +### Countdown + +If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. + +* start a countdown with the maximum duration of the game in milliseconds. + +``` +export function startCountdown(ms: number) +``` + +### Lessons + +[bop it](/microbit/lessons/bop-it) | [game of chance](/microbit/lessons/game-of-chance) | [game counter](/microbit/lessons/game-counter) + diff --git a/docs/reference/js/game.md b/docs/reference/js/game.md new file mode 100644 index 00000000..66691bbd --- /dev/null +++ b/docs/reference/js/game.md @@ -0,0 +1,11 @@ +# game + +A #microbit game library. + +Gets the current score + +``` +init() +return _score +``` + diff --git a/docs/reference/js/games.md b/docs/reference/js/games.md new file mode 100644 index 00000000..2c216747 --- /dev/null +++ b/docs/reference/js/games.md @@ -0,0 +1,89 @@ +# Game Tutorials + +Overview of Games for the BBC micro:bit. #docs #contents + +### @short Games + +### ~column + +## Beginner Games + +* [The Watch](/microbit/lessons/the-watch/activity), design and create The Watch +* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits + +### ~hide + +* [Smiley,](/microbit/lessons/smiley) smiley and frowney with show animation +* [Lucky 7](/microbit/lessons/lucky-7), show a number on the LED screen with show number +* [Snowflake fall](/microbit/lessons/snowflake-fall), repeat an animation with forever +* [Answering machine](/microbit/lessons/answering-machine), show a text message with show string +* [Bounce image](/microbit/lessons/bounce-image), scroll an image across the screen on shake +* [Magic logo](/microbit/lessons/magic-logo), show an image on logo up +* [Screen wipe](/microbit/lessons/screen-wipe), turn off the LEDs with clear screen +* [Blink](/microbit/lessons/blink), turn an LED on and off with plot +* [Flashing heart](/microbit/lessons/flashing-heart/tutorial), display images with a pause + +### ~ + +* [Night light](/microbit/lessons/night-light/tutorial), dim the LEDs with set brightness +* [Glowing sword](/microbit/lessons/glowing-sword/tutorial), make a glowing sword with fade in and fade out +* [Guess the number](/microbit/lessons/guess-the-number/tutorial), guess a random number with random +* [Rock paper scissors](/microbit/lessons/rock-paper-scissors/tutorial), use image offsets with local variables +* [Counter](/microbit/lessons/counter/tutorial), display a number with a variable +* [Love meter](/microbit/lessons/love-meter/tutorial), create a love meter with on pin pressed + +### ~column + +## Intermediate Games + +* [Truth or dare](/microbit/lessons/truth-or-dare/tutorial), a game that forces each player to reveal a secret or do something funny with if statement +* [Spinner](/microbit/lessons/spinner/tutorial), spin the arrow with multiple if statements +* [Die roll](/microbit/lessons/die-roll/tutorial), spin with more if statements +* [Looper](/microbit/lessons/looper/tutorial), display a series of numbers with a for loop index +* [Strobe light](/microbit/lessons/strobe-light/tutorial), develop shapes with a nested for loops +* [Digi yoyo](/microbit/lessons/digi-yoyo/tutorial), create a counter with a while loop +* [Magic 8](/microbit/lessons/magic-8/tutorial), a fortune teller game with the BBC micro:bit +* [Compass](/microbit/lessons/compass/tutorial), displays the direction the BBC micro:bit is pointing +* [Speed button](/microbit/lessons/speed-button/tutorial), code a speed game with running time + +### ~hide + +* [Zoomer](/microbit/lessons/zoomer/tutorial), measure the force with acceleration +* [Rotation animation](/microbit/lessons/rotation-animation/tutorial), control an animation with a boolean variable +* [Offset image](/microbit/lessons/offset-image/tutorial), shift an image horizontally with image offset + +### ~ + +### ~column + +## Advanced Games + +### ~hide + +* [Digital pet](/microbit/lessons/digital-pet/tutorial), a display of pet images with sub-functions +* [Jailbreak](/microbit/lessons/jailbreak/tutorial), break out of a counting loop by pressing button "A" +* [Transformers](/microbit/lessons/transformers/tutorial), use functions to return values +* [Flipping bird](/microbit/lessons/flipping-bird/tutorial), use modulo with a conditional + +### ~ + +* [Catch the egg](/microbit/lessons/catch-the-egg-game/tutorial), catch falling eggs in a basket with an acceleration controller +* [Headbands](/microbit/lessons/headbands/tutorial), create a charades game with a collection of strings that hold the words +* [Pong](/microbit/lessons/pong/tutorial), a light bouncing from left to right +* [Meteorite](/microbit/lessons/meteorite/tutorial), a game where meteorites are coming for you one by one +* [Minesweeper](/microbit/lessons/minesweeper/tutorial), make a game to test your memory for placing a LED mine then finding the hidden LED mine +* [Bop it](/microbit/lessons/bop-it/tutorial), a game where you have to keep up with the commands +* [Letter Up](/microbit/lessons/letter-up/tutorial), a guessing game with string operators with string at +* [Prank WiFi](/microbit/lessons/prank-wifi/tutorial), create fake WiFi to trick your friends +* [Runaway pac man](/microbit/lessons/runaway-pacman/tutorial), construct the game pac man with the BBC micro:bit +* [The hat game](/microbit/lessons/the-hat-game/tutorial), make a game to test your focus on the moving ball +* [2 player pong](/microbit/lessons/2-player-pong/tutorial), collaborate with a classmate to develop Pong on multiple BBC micro:bits + +### ~hide + +* [Glowing pendulum](/microbit/lessons/glowing-pendulum/tutorial), construct a pendulum that glows using acceleration +* [Line of Fire](/microbit/lessons/line-of-fire/tutorial), make a game to test hand-eye coordination +* [Number psych](/microbit/lessons/number-psych/tutorial), collaborate with multiple classmates to develop a game on multiple BBC micro:bits and a breadboard + +### ~ + diff --git a/docs/reference/js/guides/basic-led-show.md b/docs/reference/js/guides/basic-led-show.md new file mode 100644 index 00000000..0ee79ab2 --- /dev/null +++ b/docs/reference/js/guides/basic-led-show.md @@ -0,0 +1,86 @@ +# basic LED show + +#tutorial #docs + +### Challenge 0 + +You have successfully following the [guided tutorial] (https://live.microbit.co.uk/td/tutorials/blink). If not, we should make sure the micro:bit script displays a blinking script on screen. We want to plot the x and y coordinates to 2, 2. Additionally, you will pause by 100 milliseconds then you will clear the screen of the micro:bit. Let's give it a go! + +``` +while (true) { + led.plot(2, 2) + basic.pause(200) + basic.clearScreen() + basic.pause(200) + +} +``` + +### Challenge 1 + +Use `basic->show string`  to display text after the blink. You will be writing a series of letters to display a series of letters. Try to unravel this secret code word: HELP. This line of code is within the  while  scope + +Make sure to add this line of code within the `while` scope! + +``` +while (true) { + led1.plot(2, 2) + basic1.pause(200) + basic1.clearScreen() + basic1.pause(200) + basic1.showString("HELP", 150) // *** +} +``` + +* run the code and see that it works as expected + +### Challenge 2 + +You can also display a number on screen using `basic‐>show number`. Add code under `basic‐>show string` to display the emergency number to call in the United Kingdom. (NOTE: 999 is the historic emergency number for the United Kingdom. All calls are answered by 999 operators. Calls are always free.) + +``` +while (true) { + led2.plot(2, 2) + basic2.pause(200) + basic2.clearScreen() + basic2.pause(200) + basic2.showString("HELP", 150) + basic2.showNumber(999, 150) // *** +} +``` + +Awesome! You have designed your message and a number to call in case of an emergency. + +### Challenge 3 + +* tap the `run` button to view the updated script on the simulator + +Add an associated animation after the emergency number . You can also create a cool animation on screen using `basic->show animation`. Add code under `basic->show number` to display an animation. + +``` +while (true) { + led3.plot(2, 2) + basic3.pause(200) + basic3.clearScreen() + basic3.pause(200) + basic3.showString("HELP", 150) + basic3.showNumber(999, 150) + basic3.showAnimation(` +# # . # # +. # . # . +. . # . . +# . . . # +# # # # # +`, 400) // *** +} +``` + +Awesome! We have implemented a string, number, and animation + +* run the code and see that it works as expected. + +### Challenge 4 + +Use the same logic `basic->string`, `basic->number`, or `basic->animation` to turn on the LEDs and display information!!! + +* run the code and see that it works as expected diff --git a/docs/reference/js/guides/blink-symbols.md b/docs/reference/js/guides/blink-symbols.md new file mode 100644 index 00000000..d428c6fd --- /dev/null +++ b/docs/reference/js/guides/blink-symbols.md @@ -0,0 +1,111 @@ +# blink symbols + +#tutorial #docs + +### Challenge 0 + +You have successfully following the [blink tutorial](/microbit/hcwxud). If not, then let's start the tutorial now. Your micro:bit script should start by displaying a blinking script on screen. We want to plot the x and y coordinates to 2, 2. Additionally, you will pause by 100 milliseconds then clear the screen of the micro:bit. + +Let's give it a go! + +``` +while (true) { + led.plot(2, 2) + basic.pause(200) + basic.clearScreen() + basic.pause(200) + +} +``` + +### Challenge 1 + +Make a `>` greater than symbol. Start in the upper left corner of the simulator when you plot coordinates. Make sure to add the line of code `led->plot (0,0)` under the last line of code + +``` +while (true) { + led1.plot(2, 2) + basic1.pause(200) + basic1.clearScreen() + basic1.pause(200) + led1.plot(0, 0) // *** +} +``` + +Design the top half of the `>` symbol by connecting a LED to the original center coordinate `2,2` and the upper left coordinate `0,0` Make sure to add the line of code `led->plot (1,1)` under the last line of code + +``` +while (true) { + led2.plot(2, 2) + basic2.pause(200) + basic2.clearScreen() + basic2.pause(200) + led2.plot(0, 0) + led2.plot(1, 1) // *** +} +``` + +Awesome! You have designed half of the `>` symbol. Now we should finish the lower half of the `>` symbol + +* tap the `run` button to view the updated script on the simulator + +Add the bottom half of the `>` symbol by plotting the most bottom - left LED first. Make sure to add the line of code `led->plot (0,5)` + +``` +while (true) { + led3.plot(2, 2) + basic3.pause(200) + basic3.clearScreen() + basic3.pause(200) + led3.plot(0, 0) + led3.plot(1, 1) + led3.plot(0, 4) // *** +} +``` + +Awesome! Now we must connect a LED to the original center coordinate `2,2` and the lower left coordinate `0,5` Make sure to add the line of code `led->plot (1,4)` + +Your `main` function should look like this: + +``` +while (true) { + led4.plot(2, 2) + basic4.pause(200) + basic4.clearScreen() + basic4.pause(200) + led4.plot(0, 0) + led4.plot(1, 1) + led4.plot(0, 4) + led4.plot(1, 3) // *** +} +``` + +* `run` the script and see that the program works as expected + +Congratulations! You made a `>` symbol. + +### Challenge 2 + +Use `led->plot` to create a exclamation design `!` Your `main` function should look like this. (notice the notation of `...` represents previous code in **Challenge 0** and **Challenge 1** + +Make sure to add these lines of code within the `while` loop + +Your `main` function should look like this: + +``` +while (true) { + // ... + led5.plot(4, 0) // *** + led5.plot(4, 1) // *** + led5.plot(4, 2) // *** + led5.plot(4, 4) // *** +} +``` + +* run the code and see that it works as expected. + +### Challenge 3 + +Use the same logic `led->plot` to turn on all the LED lights!!! + +* run the code and see that it works as expected diff --git a/docs/reference/js/guides/light-column-cascade-activity.md b/docs/reference/js/guides/light-column-cascade-activity.md new file mode 100644 index 00000000..d2437b04 --- /dev/null +++ b/docs/reference/js/guides/light-column-cascade-activity.md @@ -0,0 +1,43 @@ +# Light Column Cascade Worksheet + +My script. #docs + +**Challenge 0** + +Great Job! You have completed the Light Column Cascade tutorial having a nested for loop that plots each individual LED by column adding a delay between lighting each LED. + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + basic.pause(200) + } +} +``` + +**Challenge 1** + +Make the board light up faster by making the pause less time. + +``` +for (let i1 = 0; i1 < 5; i1++) { + for (let j1 = 0; j1 < 5; j1++) { + led1.plot(i1, j1) + basic1.pause(100) // *** + } +} +``` + +**Challenge 2** + +Make the board light up by rows instead of by columns by changing the i to the y position and j to the x position. + +``` +for (let i2 = 0; i2 < 5; i2++) { + for (let j2 = 0; j2 < 5; j2++) { + led2.plot(j2, i2) // *** + basic2.pause(100) + } +} +``` + diff --git a/docs/reference/js/guides/light-column-cascade.md b/docs/reference/js/guides/light-column-cascade.md new file mode 100644 index 00000000..b4100ffc --- /dev/null +++ b/docs/reference/js/guides/light-column-cascade.md @@ -0,0 +1,43 @@ +# Light Column Cascade Activity + +My script. #docs + +**Challenge 0** + +Great Job! You have completed the Light Column Cascade tutorial having a nested for loop that plots each individual LED by column adding a delay between lighting each LED. + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + basic.pause(200) + } +} +``` + +**Challenge 1** + +Make the board light up faster by making the pause less time. + +``` +for (let i1 = 0; i1 < 5; i1++) { + for (let j1 = 0; j1 < 5; j1++) { + led1.plot(i1, j1) + basic1.pause(100) // *** + } +} +``` + +**Challenge 2** + +Make the board light up by rows instead of by columns by changing the i to the y position and j to the x position. + +``` +for (let i2 = 0; i2 < 5; i2++) { + for (let j2 = 0; j2 < 5; j2++) { + led2.plot(j2, i2) // *** + basic2.pause(100) + } +} +``` + diff --git a/docs/reference/js/guides/scroll-image-docs.md b/docs/reference/js/guides/scroll-image-docs.md new file mode 100644 index 00000000..119b2f94 --- /dev/null +++ b/docs/reference/js/guides/scroll-image-docs.md @@ -0,0 +1,22 @@ +# Scroll Image Docs + +My script. #docs + +**Challenge 0** + +This [guided tutorial](/microbit/xuhkviyyxa) introduces how to make an image look like it's scrolling across the micro:bit! + +We can use an animation to make an image look like its moving! + +``` +basic.forever() +``` + +**Challenge 1** + +Now, let's reverse the animation so it looks like the bar is bouncing off the right edge of the display. + +``` +basic1.forever() +``` + diff --git a/docs/reference/js/guides/touchdevelop-lessons.md b/docs/reference/js/guides/touchdevelop-lessons.md new file mode 100644 index 00000000..380ec5a1 --- /dev/null +++ b/docs/reference/js/guides/touchdevelop-lessons.md @@ -0,0 +1,140 @@ +# TouchDevelop Lessons + +Overview of TouchDevelop lessons for the micro:bit. #docs #contents + +### @section full + +### ~column + +### LED screen + +* [plot guided](/microbit/hcwxud) `guided tutorial ` `video available` +* [plots an LED](/microbit/njuzbvocit) [guided tutorial] +* [blink symbols](/microbit/rfchtfjmag) `docs` +* [clear screen](/microbit/jwqywu) +* [point](/microbit/reference/led/point) +* [set brightness](/microbit/tfrmcgdtxk) + +## micro:bit + +## functions + +### Basic + +* [show number](/microbit/doxhko) +* [show string](/microbit/hgsfxg) +* [forever - show image](/microbit/bniyze) `guided tutorial` +* [forever - show animation - two frames 1a](/microbit/rwsjmubtaa) +* [forever - show animation - two frames 1c](/microbit/fomtaxxdkk) +* [forever - show animation - two frames 1 d](/microbit/huguhgjmmn) +* [forever - show animation - multliple frames](/microbit/tweyhx) + +## Language {#pconst} + +### Variables + +* [global variables ](/microbit/nkecii) `guided tutorial` +* [local variable - create image, show image](/microbit/dcvnwv) +* data types: [number](/microbit/reference/types/number), [boolean](/microbit/reference/types/boolean), [string](/microbit/reference/types/string), [image](/microbit/reference/image/image) + +### Statements and control structures + +* [if](/microbit/reference/logic/if) +* [for](/microbit/reference/loops/for) +* [for loop nested - plot](/microbit/vpvhdnaqfm) **script** +* [while](/microbit/js/while) +* [while - show string, show number, show animation](/microbit/bidtzqdips) `docs` +* [while - create image ](/microbit/bnqbom) +* [return](/microbit/js/return) +* [break](/microbit/js/break) +* [function](/microbit/js/function) +* [assignment operation](/microbit/reference/variables/assign) `:=` + +### Maths + +* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [numbers](/microbit/reference/types/number) +* comparison operators (such as `>`, `=`) on [numbers](/microbit/reference/types/number) +* the [math](/microbit/js/math) library +* the [bits](/microbit/js/bits) library + +### Logical + +* boolean operators (`not`, `or`, `and`) on [booleans](/microbit/reference/types/boolean) + +### Strings + +* concat operator combines [strings](/microbit/reference/types/string) + +### ~ + +### ~column + +### Input + +* [button is pressed](/microbit/reference/input/button-is-pressed) +* [on button pressed](/microbit/reference/input/on-button-pressed) +* [acceleration](/microbit/reference/input/acceleration) +* [compass heading](/microbit/reference/input/compass-heading) +* [calibrate](/microbit/functions/calibrate) +* [running time](/microbit/reference/input/running-time) +* [on shake](/microbit/reference/input/on-gesture) +* [on screen up](/microbit/functions/on-screen-up) +* [on screen down](/microbit/functions/on-screen-down) +* [on logo up](/microbit/functions/on-logo-up) +* [on logo down](/microbit/functions/on-logo-down) + +### ~ + +### ~column + +### Authoring & Other Bits + +* [TouchDevelop editor](/microbit/js/editor) +* [markdown](/microbit/js/markdown) +* [creating interactive tutorials](/microbit/js/creatinginteractivetutorials) +* [run scripts in a web browser](/microbit/js/simulator) +* [run scripts on your micro:bit](/microbit/usb) +* [libraries](/microbit/js/libraries) + +### Functions and libraries + +* [creating functions](/microbit/js/function) +* [function parameters](/microbit/js/functionparameters) +* [calling functions](/microbit/js/call) +* [libraries](/microbit/js/libraries) + +### Images + +* [create image](/microbit/reference/images/create-image) +* [clear](/microbit/reference/basic/clear-screen) +* [set pixel](/microbit/reference/images/set-pixel) +* [pixel](/microbit/reference/images/pixel) +* [show image](/microbit/reference/images/show-image) +* [scroll image](/microbit/reference/images/scroll-image) +* [width](/microbit/functions/width) +* [show animation](/microbit/reference/basic/show-animation) + +### Pins + +* [analog read pin](/microbit/reference/pins/analog-read-pin) +* [analog write pin](/microbit/reference/pins/analog-write-pin) +* [digital read pin](/microbit/reference/pins/digital-read-pin) +* [digital write pin](/microbit/reference/pins/digital-write-pin) + +### Accessories + +* [forever](/microbit/reference/basic/forever) +* [in background](/microbit/reference/control/in-background) + +## Tutorials + +* [Blink](/script:hcwxud) +* [Button](/script:rxqgzy) +* [Compass](/script:fhhhwl) +* [Counter](/script:bqrria) +* [Digital pet](/script:lsqwsk) +* [Flashing heart](/script:bniyze) +* [Glowing image](/script:hydyrp) + +### ~ + diff --git a/docs/reference/js/hourofcode.md b/docs/reference/js/hourofcode.md new file mode 100644 index 00000000..01691a33 --- /dev/null +++ b/docs/reference/js/hourofcode.md @@ -0,0 +1,60 @@ +# Hour of Code + +learn how to run an Hour Of Code with the BBC micro:bit. #docs + +The BBC micro:bit can be used to run an Hour Of Code™ events for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school. + +## preparing the room + +1) Computers + +* Ensure that each participant will have **a computer connected to a BBC micro:bit board via a micro-USB cable**. + +2) Internet + +* Ensure that each computer has access to **internet**. + +3) Website Access + +* [https://www.microbit.co.uk](https://www.microbit.co.uk) + +4) Raffle tickets and prizes (optional) + +* Reward students with raffle tickets to keep them engaged. Finishing an activity or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice). + +5) Music (optional) + +* We recommend playing the latest hits (loudly) while the students are coding. It creates a playful atmosphere and makes the entire experience more enjoyable. Many web sites offer streaming music, but be sure to try it in advance as certain sites may be blocked on your network. + +## preparing the student handouts + +Print the following **activities** (1 handout per student): + +* [answering machine](/microbit/lessons/answering-machine/activity) +* [happy birthday](/microbit/lessons/happy-birthday/activity) +* [love meter](/microbit/lessons/love-meter/activity) + +Print the following **challenges** (1 handout per student): + +* [answering machine](/microbit/lessons/answering-machine/challenges) +* [happy birthday](/microbit/lessons/happy-birthday/challenges) +* [love meter](/microbit/lessons/love-meter/challenges) + +## Timeline + +* ``00:00`` students enter the website address (see step 3) +* ``10:00`` [answering machine](/microbit/lessons/answering-machine/activity) +* ``25:00`` [happy birthday](/microbit/lessons/happy-birthday/activity) +* ``35:00`` [love meter](/microbit/lessons/love-meter/activity) +* ``55:00`` raffle +* ``60:00`` that's it! + +## Follow up + +After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start: + +* [more challenges](/microbit/js/games) are available with BBC micro:bit Tutorials +* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within BBC micro:bit + +The 'Hour of Code™' is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming. + diff --git a/docs/reference/js/hourofcode/notes.md b/docs/reference/js/hourofcode/notes.md new file mode 100644 index 00000000..06152642 --- /dev/null +++ b/docs/reference/js/hourofcode/notes.md @@ -0,0 +1,48 @@ +# Hour of Code notes + +learn how to run an Hour Of Code with the BBC micro:bit. #docs + +The BBC micro:bit can be used to run an Hour Of Code™ event for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school. + +## Preparation + +1) Computers + +Each participant has **a computer connected to a BBC micro:bit via micro-USB**. + +2) Internet + +Ensure that each computer has access to **internet**. + +3) Accounts + +Create a classroom in https://www.microbit.co.uk and pre-populate the classroom with student accounts. **Print the student passwords** and cut out each password. + +4) Print the activity challenges (1 copy per participant): + +* [hour of code](/microbit/js/hourofcode/challenges) + +4) (optional) Raffle tickets and prizes + +Reward students with raffle tickets to keep them engaged. Finishing a tutorial or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice). + +5) (optional) Music + +Bring more energy in the room by playing music. + +## Timeline + +* ``00:00`` student sign in using **printed passwords** (see step 3) +* ``10:00`` [hour of code tutorial](/microbit/js/hourofcode) +* ``40:00`` raffle and demoes +* ``50:00`` that's it! + +## Follow up + +After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start: + +* [more challenges](/microbit/lessonss) are available for BBC micro:bit +* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within BBC micro:bit + +_The Hour of Code™ is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming._ + diff --git a/docs/reference/js/if.md b/docs/reference/js/if.md new file mode 100644 index 00000000..63eadf96 --- /dev/null +++ b/docs/reference/js/if.md @@ -0,0 +1,101 @@ +# If + +Run code based on a condition. #docs #if #then #else #endif #language #elseif + +### @parent js/language + + +Conditionally run code depending on whether a [Boolean](/microbit/reference/types/boolean) condition is true or false. + +### Block Editor + +![](/static/mb/hourofcode-0.png) + +In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block. + +### Touch Develop + +### ~hide + +``` +let condition = true +``` + +### ~ + +``` +if (condition) { + // this code runs if `condition` is `true` +} else { + // this code runs if `condition` is `false` +} +``` + +### Example: adjusting screen brightness + +If the screen [brightness](/microbit/reference/led/brightness) is `< 100`, this code sets the brightness to `255`: + +``` +if (led.brightness() < 100) { + led.setBrightness(255) +} +``` + +You can leave the `then` or `else` blocks empty if they aren't needed. + +### Else if: multiple if statements + +You can chain together if statements by using `else if`. Like this: + +### ~hide + +``` +let otherCondition = true +``` + +### ~ + +``` +if (condition) { + // this code runs if `condition` is `true` +} else if (otherCondition) { + // this code runs if `other condition` is `true` +} +else { + // this code runs if neither `condition` or `other condition` are `true` +} +``` + +### Example: compass heading + +The following example gets the [compass heading](/microbit/reference/input/compass-heading) and then uses ``if-then-else`` statements to display a letter on the screen (N for north, E for East, S for South, and W for West). + +``` +while (true) { + let degrees = input.compassHeading() + if (degrees < 45) { + basic.showString("N", 100) + } else if (degrees < 135) { + basic.showString("E", 100) + } + else if (degrees < 225) { + basic.showString("S", 100) + } + else { + basic.showString("W", 100) + } +} +``` + +### Drag and drop + +You can move an entire ``if`` block by clicking the ``if`` keyword and dragging and dropping. + +### Lessons + +[love meter](/microbit/lessons/love-meter), [zoomer](/microbit/lessons/zoomer), [offset image](/microbit/lessons/offset-image) + +### See also + +[while loop](/microbit/js/while), [for](/microbit/reference/loops/for), [boolean](/microbit/reference/types/boolean) + diff --git a/docs/reference/js/image.md b/docs/reference/js/image.md new file mode 100644 index 00000000..5ad4f0bf --- /dev/null +++ b/docs/reference/js/image.md @@ -0,0 +1,71 @@ +# Image + +An image for the micro:bit screen. #docs #image #screen #LED + +### @parent js/language + +An *Image* is a matrix of pixels to show on the [LED screen](/microbit/device/screen) + +### Touch Develop editor: plot an image + +To display an image using the [Touch Develop editor](/microbit/js/editor): + +* click `image` , `plot image`, and then `edit` +* click the rectangles to create an image +* when you're done, click **ok** to return to your code + +![](/static/mb/plot-leds-0.png) + +You should see code similar to this: + +``` +basic.plotImage(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`) +``` + +### Creating an image + +To create an image that you can later modify, see the [create image](/microbit/reference/images/create-image) function. + +### Block editor: create and show images + +To create images using the [Block editor](/microbit/blocks/editor): + +1. Click the **Images** category on the left. + +2. Drag and drop the **show image** block into your code. + +3. Drag and drop the **create image** or **create big image** block onto the **show image** block so that they connect. + +4. Make an image on the **create image** block by clicking on the squares. + +### Global image variables + +Images that you create in the [Touch Develop editor](/microbit/js/editor) are [local variables](/microbit/reference/variables/var). To promote a local image variable to a global variable, select the local image variable and click `promote to data`. The *var* keyword changes to the [data](/microbit/js/data) symbol `data->`. + +### Image functions + +* [create image](/microbit/reference/images/create-image): create an image from a series of on/off LED states +* [clear](/microbit/reference/basic/clear-screen): turn off all the pixels in an image +* [set pixel](/microbit/reference/images/set-pixel): set the state of a pixel in an image +* [pixel](/microbit/reference/images/pixel): get the state of a pixel in an image +* [plot-image](/microbit/reference/led/plot-image): show a single-frame image on the LED screen +* [show animation](/microbit/reference/basic/show-animation): show a series of image frames +* [show image](/microbit/reference/images/show-image): show an image on the screen +* [scroll image](/microbit/reference/images/scroll-image): scroll an image on the screen +* [width](/microbit/functions/width): get the width of an image + +### Lessons + +* [bounce image ](/microbit/lessons/bounce-image) +* [offset image](/microbit/lessons/offset-image) + +### See also + +[plot image](/microbit/reference/led/plot-image), [create image](/microbit/reference/images/create-image), [show image](/microbit/reference/images/show-image), [LED screen](/microbit/device/screen) + diff --git a/docs/reference/js/lessons.md b/docs/reference/js/lessons.md new file mode 100644 index 00000000..127d98c9 --- /dev/null +++ b/docs/reference/js/lessons.md @@ -0,0 +1,97 @@ +# Touch Develop Lessons + +Overview of Touch Develop lessons for the BBC micro:bit. #docs #contents + +### @short Lessons + +### ~column + +## Maker + +* [The Watch](/microbit/lessons/the-watch), design and create The Watch +* [Hack your Headphones](/microbit/lessons/hack-your-headphones), create music on the BBC micro:bit by hacking your headphones +* [Banana Keyboard](/microbit/lessons/banana-keyboard), create music with fruits +* [Telegraph](/microbit/lessons/telegraph), play the telegraph game between 2 BBC micro:bits +* [Ornament Chain](/microbit/lessons/ornament-chain), play the ornament chain game between 2 BBC micro:bits + +## Beginner + +* [Beautiful Image](/microbit/lessons/beautiful-image), show a beautiful image with show LEDs +* [Smiley,](/microbit/lessons/smiley) smiley and frowney with show animation +* [Lucky 7](/microbit/lessons/lucky-7), show a number on the LED screen with show number +* [Answering Machine](/microbit/lessons/answering-machine), show a text message with show string +* [Snowflake Fall](/microbit/lessons/snowflake-fall), repeat an animation with forever + +### ~hide + +* [Bounce Image](/microbit/lessons/bounce-image), scroll an image across the screen on shake + +### ~ + +* [Magic Logo](/microbit/lessons/magic-logo), show an image on logo up +* [Screen Wipe](/microbit/lessons/screen-wipe), turn off the LEDs with clear screen +* [Flashing Heart](/microbit/lessons/flashing-heart), display images with a pause +* [Blink](/microbit/lessons/blink), turn an LED on and off with plot +* [Night Light](/microbit/lessons/night-light), dim the LEDs with set brightness +* [Glowing Sword](/microbit/lessons/glowing-sword), make a glowing sword with fade in and fade out + +### ~column + +## Intermediate + +* [Magic 8](/microbit/lessons/magic-8), a fortune teller game with the BBC micro:bit +* [Guess the Number](/microbit/lessons/guess-the-number), guess a random number with random +* [Rock Paper Scissors](/microbit/lessons/rock-paper-scissors), use image offsets with local variables +* [Counter](/microbit/lessons/counter), display a number with a variable +* [Love meter](/microbit/lessons/love-meter), create a love meter with on pin pressed +* [Zoomer](/microbit/lessons/zoomer), measure the force with acceleration +* [Glowing Pendulum](/microbit/lessons/glowing-pendulum), construct a pendulum that glows using acceleration +* [Truth or Dare](/microbit/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement +* [Spinner](/microbit/lessons/spinner), spin the arrow with multiple if statements +* [Die Roll](/microbit/lessons/die-roll), spin with more if statements +* [Looper](/microbit/lessons/looper), display a series of numbers with a for loop index +* [Strobe Light](/microbit/lessons/strobe-light), develop shapes with a nested for loops +* [Digi Yoyo](/microbit/lessons/digi-yoyo), create a counter with a while loop +* [Rotation Animation](/microbit/lessons/rotation-animation), control an animation with a boolean variable +* [Offset Image](/microbit/lessons/offset-image), shift an image horizontally with image offset +* [Compass](/microbit/lessons/compass), displays the direction the BBC micro:bit is pointing + +### ~ + +### ~column + +## Advanced + +* [Digital Pet](/microbit/lessons/digital-pet), a display of pet images with sub-functions +* [Transformers](/microbit/lessons/transformers), use functions to return values +* [Speed Button](/microbit/lessons/speed-button), code a speed game with running time +* [Catch the Egg](/microbit/lessons/catch-the-egg-game), catch falling eggs in a basket with an acceleration controller +* [Headbands](/microbit/lessons/headbands), create a charades game with a collection of strings that hold the words +* [Prank WiFi](/microbit/lessons/prank-wifi), create fake WiFi to trick your friends +* [Jailbreak](/microbit/lessons/jailbreak), break out of a counting loop by pressing button "A" +* [Flipping Bird](/microbit/lessons/flipping-bird), use modulo with a conditional +* [Runaway Pac Man](/microbit/lessons/runaway-pacman), construct the game pac man with the BBC micro:bit +* [Line of Fire](/microbit/lessons/line-of-fire), make a game to test hand-eye coordination +* [The Hat Game](/microbit/lessons/the-hat-game), make a game to test your focus on the moving ball +* [2 Player Pong](/microbit/lessons/2-player-pong), collaborate with a classmate to develop Pong on multiple BBC micro:bits + +### Games + +* [Pong](/microbit/lessons/pong), a light bouncing from left to right +* [Meteorite](/microbit/lessons/meteorite), a game where meteorites are coming for you one by one +* [Minesweeper](/microbit/lessons/minesweeper), make a game to test your memory for placing a LED mine then finding the hidden LED mine +* [Bop it](/microbit/lessons/bop-it), a game where you have to keep up with the commands +* [Letter up](/microbit/lessons/letter-up), a guessing game with string operators with string at + +### ~ + +### ~hide + +* [Number Psych](/microbit/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple BBC micro:bits and a breadboard + +### ~ + +### @section full + +The lessons promote computational thinking and computer science literacy[ read more...](/microbit/lessons/teach) + diff --git a/docs/reference/js/lessons/2-player-pong.md b/docs/reference/js/lessons/2-player-pong.md new file mode 100644 index 00000000..94c74ab6 --- /dev/null +++ b/docs/reference/js/lessons/2-player-pong.md @@ -0,0 +1,103 @@ +# 2 player pong lesson + +make a game to test your focus on the moving ball #function #on-button-pressed #if #show-animation #mod #random #Boolean #docs + +## Topic + +Functions + +## Quick Links + +* [tutorial](/microbit/lessons/2-player-pong/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, `function()` as a unit of code that performs a specific task and returns a result. We will be learning how to create the hat game app using functions, global variables, input on button pressed, if (conditionals), mod, random, Boolean, as well as simple commands such as show animation. + +## What the teacher needs to know/QuickStart Computing Glossary + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Hardware: The physical systems and components of digital devices; see also software. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Repetition: Executing a section of computer code a number of times as part of the program. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +## Documentation + +* **functions** : [read more...](/microbit/js/function) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **for** : [read more...](/microbit/reference/loops/for) +* **if** : [read more...](/microbit/reference/logic/if) +* **show animation** : [read more...](/microbit/reference/basic/show-animation) + +## Resources + +* Activity: [tutorial](/microbit/lessons/2-player-pong/tutorial) + +## Objectives + +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how to learn how to conditionally run code depending on whether a condition is true or no +* learn how to show a series of image frames on the LED screen +* learn how to run code when an input button is pressed + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) +* Defines data types: real numbers and Boolean (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/2-player-pong/tutorial) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/2-player-pong/quiz-answers.md b/docs/reference/js/lessons/2-player-pong/quiz-answers.md new file mode 100644 index 00000000..e704fefa --- /dev/null +++ b/docs/reference/js/lessons/2-player-pong/quiz-answers.md @@ -0,0 +1,91 @@ +# 2 player pong quiz answers + +a two-player game of Pong using TWO BBC micro:bits! #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [2 player pong tutorial](/microbit/lessons/2-player-pong/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the two global variables that record if the player has the ball and if the game is running, and assign these variables to their initial values. + +
+ +``` +hasBall = false +gameRunning = false +``` + +## 2. Write the global variable that keeps track of the game state in which whoever presses button A first will get to start the ball. Assign this variable to its initial value. + +
+ +``` +claimBall = true +``` + +## 3. Write the code that creates a condition to know when Button A is pressed. Then write the 'If statement' to ensure that 'claim ball' is true. If the claim ball is true, then write the code that sets P0 to 1 to signal to the other device that the player has claimed the ball. + +
+ +``` +input.onButtonPressed("A", () => { + if (claimBall) { + pins.digitalWritePin("P0", 1) + } +}) +``` + +## 4. Write the code to move the paddle right when button B is pressed. Be sure to check if the game is running and if the paddle is not already on the rightmost edge. + +
+ +``` +if (gameRunning) { + if (paddleX != 0) { + led.unplot(paddleX, 4) + paddleX = paddleX - 1 + led.plot(paddleX, 4) + } +} +``` + +## 5. What are the three pieces of information that we send to the other device when transferring the ball? (Hint: look in your "transfer ball" function, and look for any places that contain "transfer byte"). + +
+ +The device first transfers a bit of 1 to indicate that the device is going to transfer the data of the ball. After that, the device transfers the x-coordinate of the ball, and then the x-velocity of the ball. + +## 6. Using the function "read velocity", write the code that reads the x-coordinate and the x-velocity of the ball. (Hint: look at the function "read ball".) + +
+ +``` +ballX = micro_bitTransfer.readByte() +ballXVelocity = readVelocity() +``` + +## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.) + +
+ +``` +if (ballX == 0 || ballX == 4) { + ballXVelocity = ballXVelocity * (-1) +} +``` + +## 8. Write the code to move the ball. To move the ball, unplot the ball's original position, update its position variables, and then plot the ball's new position. + +
+ +``` +led.unplot(ballX, 0) +ballX = ballX + ballXVelocity +ballY = ballY + ballYVelocity +led.plot(ballX, ballY) +``` + diff --git a/docs/reference/js/lessons/2-player-pong/quiz.md b/docs/reference/js/lessons/2-player-pong/quiz.md new file mode 100644 index 00000000..c8b923cb --- /dev/null +++ b/docs/reference/js/lessons/2-player-pong/quiz.md @@ -0,0 +1,70 @@ +# 2 player pong quiz + +a two-player game of Pong using TWO BBC micro:bits! #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [2 player pong tutorial](/microbit/lessons/2-player-pong/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the two global variables that record if the player has the ball and if the game is running, and assign these variables to their initial values. + +
+ +
+ +## 2. Write the global variable that keeps track of the game state in which whoever presses button A first will get to start the ball. Assign this variable to its initial value. + +
+ +## 3. Write the code that creates a condition to know when Button A is pressed. Then write the 'If statement' to ensure that 'claim ball' is true. If the 'claim ball' is true, then write the code that sets P0 to 1 to signal to the other device that the player has claimed the ball. + +
+ +
+ +
+ +
+ +## 4. Write the code to move the paddle right when button B is pressed. Be sure to check if the game is running and if the paddle is not already on the rightmost edge. + +
+ +
+ +
+ +
+ +## 5. What are the three pieces of information that we send to the other device when transferring the ball? (Hint: look in your "transfer ball" function, and look for any places that contain "transfer byte"). + +
+ +
+ +## 6. Using the function "read velocity", write the code that reads the x-coordinate and the x-velocity of the ball. (Hint: look at the function "read ball".) + +
+ +
+ +
+ +## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.) + +
+ +
+ +## 8. Write the code to move the ball. To move the ball, unplot the ball's original position, update its position variables, and then plot the ball's new position. + +
+ +
+ +
+ diff --git a/docs/reference/js/lessons/accelerometer/challenges.md b/docs/reference/js/lessons/accelerometer/challenges.md new file mode 100644 index 00000000..67fadb39 --- /dev/null +++ b/docs/reference/js/lessons/accelerometer/challenges.md @@ -0,0 +1,59 @@ +# zoomer challenges + +The acceleration function. #acceleration #docs #input + +**Challenge 0** + +Great job! You have successfully completed the [zoomer tutorial](https://test.microbit.co.uk/td/lessons/zoomer/challenges) . You have created a script that measures the acceleration on the micro:bit in the "z" direction of a 3D world. + +``` +basic.forever(() => { + let millig = input.acceleration("z") + basic.showNumber(millig, 150) + basic.pause(100) +}) +``` + +**Challenge 1** + +Create a new variable called milliX that holds the acceleration in the "x" direction or the horizontal direction. + +``` +basic.forever(() => { + let millig1 = input.acceleration("z") + basic.showNumber(millig1, 150) + basic.pause(100) + let milliX = input.acceleration("x") // *** +}) +``` + +* Run the code to see if it works as expected. + +**Challenge 2** + +If Button `A` is pressed, we want to show the acceleration in the "x" direction by adding an if statement that checks to see if Button `A` is pressed and then calling the show number method passing in milliX as the number. + +``` +basic.forever(() => { + let millig2 = input.acceleration("z") + basic.showNumber(millig2, 150) + basic.pause(100) + let milliX1 = input.acceleration("x") + if (input.buttonIsPressed("A")) { + basic.showNumber(milliX1, 150) // *** + } +}) +``` + +* Run the code to see if it works as expected. + +### Challenge 3 + +If Button `B` is pressed, program the micro:bit to display the acceleration in the "y" direction. + +You can do this by storing the acceleration in a variable: `var milliY := input->acceleration("y")`. + +Then add an `if` statement that checks if Button `B` is pressed: `if input-> button is pressed ("B") then`. + +Inside of the `if` statement, add `basic->show number(milliY, 150)`, which will display the acceleration in the "y" direction. + diff --git a/docs/reference/js/lessons/answering-machine.md b/docs/reference/js/lessons/answering-machine.md new file mode 100644 index 00000000..6523b2f8 --- /dev/null +++ b/docs/reference/js/lessons/answering-machine.md @@ -0,0 +1,81 @@ +# answering machine lesson + +create an answering machine on the BBC micro:bit #docs + +### @video td/videos/answering-machine-0 + +## Topic + +Show String + +## Quick Links + +* [activity](/microbit/lessons/answering-machine/activity) +* [quiz](/microbit/lessons/answering-machine/quiz) +* [quiz answers](/microbit/lessons/answering-machine/quiz-answers) +* [challenges](/microbit/lessons/answering-machine/challenges) +* [tutorial](/microbit/lessons/answering-machine/tutorial) + +## Class + +Year 7 + +## Prior learning / place of lesson in scheme of work + +Learn how to creating a message with a **string**, `basic->show string` to write your message. We will be learning how to create a message using simple commands, such as show string and on button pressed. + +## Documentation + +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) + +## Objectives + +* learn how to show a string on the LED screen one character at a time +* learn how to use to register an event handler that will execute whenever an input button is pressed + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV) +* Evaluates the appropriatness of digital devices, internet services and application software to achieve given goals (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/answering-machine/activity) +* [quiz](/microbit/lessons/answering-machine/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/answering-machine/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/answering-machine/challenges) + diff --git a/docs/reference/js/lessons/banana-keyboard.md b/docs/reference/js/lessons/banana-keyboard.md new file mode 100644 index 00000000..8cb81bab --- /dev/null +++ b/docs/reference/js/lessons/banana-keyboard.md @@ -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 + diff --git a/docs/reference/js/lessons/beautiful-image.md b/docs/reference/js/lessons/beautiful-image.md new file mode 100644 index 00000000..673fb24b --- /dev/null +++ b/docs/reference/js/lessons/beautiful-image.md @@ -0,0 +1,76 @@ +# beautiful image lesson + +display beautiful images on the BBC micro:bit #var #pause #docs + +### @video td/videos/beautiful-image-0 + +## Topic + +Show LEDs + +## Quick Links + +* [activity](/microbit/lessons/beautiful-image/activity) +* [quiz](/microbit/lessons/beautiful-image/quiz) +* [quiz answers](/microbit/lessons/beautiful-image/quiz-answers) +* [challenges](/microbit/lessons/beautiful-image/challenges) +* [tutorial](/microbit/lessons/beautiful-image/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to **show LEDs**, to show an image on the BBC micro:bit's LED screen. We will be learning how to Show LEDs using simple commands such as Show LEDs and pause. + +## Documentation + +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to display an image on the micro:bit's LED screen +* learn how to pause your code for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses diagrams to express solutions.(AB) +* Represents solutions using a structured notation (AL) (AB) +* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Selects the appropriate data types(AL) (AB + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/beautiful-image/tutorial) +* [quiz](/microbit/lessons/beautiful-image/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/beautiful-image/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/beautiful-image/challenges) + diff --git a/docs/reference/js/lessons/blink.md b/docs/reference/js/lessons/blink.md new file mode 100644 index 00000000..ca3ae4f4 --- /dev/null +++ b/docs/reference/js/lessons/blink.md @@ -0,0 +1,97 @@ +# blink lesson + +Learn how to create a blinking LED. #LED #screen #plot #docs #lesson + +### @video td/videos/blink-0 + +## Topic + +Plot + +## Quick links + +* [activity](/microbit/lessons/blink/activity) +* [quiz](/microbit/lessons/blink/quiz) +* [quiz answers](/microbit/lessons/blink/quiz-answers) +* [challenges](/microbit/lessons/blink/challenges) +* [tutorial](/microbit/lessons/blink/tutorial) + +## Class + +Year 7 + +## Prior learning / place of lesson in scheme of work + +Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, unplot and pause. + +## What the teacher needs to know / QuickStart Computing Glossary + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. The forever loop repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language. + +## Documentation + +* **plot**: [read more...](/microbit/reference/led/plot) +* **unplot**: [read more...](/microbit/reference/led/unplot) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **forever**: [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [tutorial](/microbit/lessons/blink/tutorial) +* Activity: [quiz](/microbit/lessons/blink/quiz) +* Extended Activity: [challenges](/microbit/lessons/blink/challenges) + +## Objectives + +* learn how to turn on LED lights on the LED screen +* learn how to turn off LED lights on the LED screen +* learn how to pause program execution for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/blink/tutorial) +* [quiz](/microbit/lessons/blink/quiz) +* [quiz answers](/microbit/lessons/blink/quiz-answers) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/blink/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/blink/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/blink/activity.md b/docs/reference/js/lessons/blink/activity.md new file mode 100644 index 00000000..42994f44 --- /dev/null +++ b/docs/reference/js/lessons/blink/activity.md @@ -0,0 +1,55 @@ +# blink activity + +Turn an LED on and off with forever + +### ~avatar avatar + +### @video td/videos/blink-0 + +Let's learn how to blink an LED. + +### ~ + +Have you ever tried to blink a flashlight at night? The concept is fairly simply: turn on the light, wait for a little, turn off the light, wait again, and repeat. That's exactly what we need to code to get a blinking LED. + +Let's start by adding a line of code that turns on the LED at position ``2, 2``. + +``` +led.plot(2, 2) +``` + +Run your script to make sure it's correct. Then, let's add code to **pause** `500` milliseconds and turn off the LED. + +``` +led.plot(2, 2) +basic.pause(500) +led.unplot(2, 2) +``` + +We've got the LED blinking once. Let's add another pause and turn on the LED again. + +``` +led.plot(2, 2) +basic.pause(500) +led.unplot(2, 2) +basic.pause(500) +led.plot(2, 2) +``` + +The current code works but it only blinks once! We are going to use a `basic->forever` loop and move the code inside it to repeat it forever. We've dropped the second `led-plot` line since we don't need it in the loop. + +``` +basic.forever(() => { + led.plot(2, 2) + basic.pause(500) + led.unplot(2, 2) + basic.pause(500) +}) +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/blink/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/blink/challenges.md b/docs/reference/js/lessons/blink/challenges.md new file mode 100644 index 00000000..656f775e --- /dev/null +++ b/docs/reference/js/lessons/blink/challenges.md @@ -0,0 +1,85 @@ +# blink challenges + +Coding challenges for the blink tutorial #docs #challenges + +## Before we get started + +Complete the [blink](/microbit/lessons/blink/activity) activity and your code will look like this: + +``` +basic.forever(() => { + led.plot(2, 2) + basic.pause(200) + led.unplot(2, 2) + basic.pause(200) +}) +``` + +### Challenge 1 + +### @video td/videos/blink-1 + +Let's display a "smiley face" on the screen! We'll start by plotting the eyes. + +Add `led->plot (1,1)` and `led->plot(3,1)` under `led->plot(2,2)` ; then add `led->unplot(1,1)` and `led->unplot(3,1)` after pause. When you're ready, don't forget to run your code to try it out! + +``` +basic.forever(() => { + led.plot(2, 2) + led.plot(1, 1) + led.plot(3, 1) + basic.pause(200) + led.unplot(2, 2) + led.unplot(1, 1) + led.unplot(3, 1) + basic.pause(200) +}) +``` + +### Challenge 2 + +### @video td/videos/blink-2 + +Let's add the code to plot the mouth by plotting and unplotting `(1,4)`, `(2,4)` and `(3,4)`. + +``` +basic.forever(() => { + led.plot(2, 2) + led.plot(1, 1) + led.plot(3, 1) + led.plot(1, 4) + led.plot(2, 4) + led.plot(3, 4) + basic.pause(200) + led.unplot(2, 2) + led.unplot(1, 1) + led.unplot(3, 1) + led.unplot(1, 4) + led.unplot(2, 4) + led.unplot(3, 4) + basic.pause(200) +}) +``` + +### Challenge 3 + +### @video td/videos/blink-3 + +Let's keep using `led->plot` to convert the mouth into a smiley face. + +```` bitmatrix +0 0 0 0 0 +0 1 0 1 0 +0 0 1 0 0 +1 0 0 0 1 +0 1 1 1 0 +```` + +### Challenge 4 + +Let's make it blink a bit faster. To do so, we need to reduce the amount of time used in ``basic->pause`` to ``100`` milliseconds. + +### Challenge 5 + +Create your own image by changing the coordinates in `led->plot`! + diff --git a/docs/reference/js/lessons/blink/lesson-plan.md b/docs/reference/js/lessons/blink/lesson-plan.md new file mode 100644 index 00000000..8f62d6e7 --- /dev/null +++ b/docs/reference/js/lessons/blink/lesson-plan.md @@ -0,0 +1,101 @@ +# blink lesson plan + +Learn how to create a blinking LED script. + +### @video vimeo/133778417 + +## Topic + +Plot - Blinking LED + +## Quick links + +* [tutorial](/microbit/lessons/blink/tutorial) +* [quiz](/microbit/js/blink/quiz) +* [quiz answers](/microbit/lessons/blink/quiz-answers) +* [challenges](/microbit/lessons/blink/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to control a blinking LED. We will be learning how to create a blinking app using forever as well as simple commands, such as plot, pause, and clear screen. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **plot**: [read more...](/microbit/reference/led/plot) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **clear screen**: [read more...](/microbit/reference/basic/clear-screen) +* **forever**: [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [tutorial](/microbit/lessons/blink/tutorial) +* Activity: [quiz](/microbit/lessons/blink/quiz) +* Extended Activity: [challenges](/microbit/lessons/blink/challenges) + +## Objectives + +* learn how to blink a light +* learn how to turn the light on and off +* learn how to repeat turning on and off the light + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/blink/tutorial) +* [quiz](/microbit/lessons/blink/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/blink/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/blink/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/blink/quiz-answers.md b/docs/reference/js/lessons/blink/quiz-answers.md new file mode 100644 index 00000000..a6a830ee --- /dev/null +++ b/docs/reference/js/lessons/blink/quiz-answers.md @@ -0,0 +1,46 @@ +# blink quiz answers + +Learn how to create a blinking LED script. + +This is the answer key for the [blink quiz](/microbit/lessons/blink/quiz). + +## 1. Describe what `led->plot` does? + +Answers will vary. In general, plot refers to the code that turns on a specific LED. We specify the LED using x, y coordinates. + +## 2. Draw which LED is ON after running this code + +``` +led.plot(2, 2) +``` + +![](/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 + +``` +led.plot(0, 0) +``` + +![](/static/mb/lessons/blink-1.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +* ``x`` - the x coordinate or horizontal position (0) +* ``y`` - the y coordinate or vertical position (0) + +## 4. Draw which LED is ON after running this code + +``` +led.plot(4, 4) +``` + +![](/static/mb/lessons/blink-2.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using ``x``, ``y`` coordinates. + +* ``x`` - the x coordinate or horizontal position (4) +* ``y`` - the y coordinate or vertical position (4) + diff --git a/docs/reference/js/lessons/blink/quiz.md b/docs/reference/js/lessons/blink/quiz.md new file mode 100644 index 00000000..bf6eaa1f --- /dev/null +++ b/docs/reference/js/lessons/blink/quiz.md @@ -0,0 +1,40 @@ +# blink quiz + +Learn how to create a blinking LED script. + +## Name + +## Directions + +Use this activity document to guide your work in the [blink tutorial](/microbit/lessons/blink/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what `led->plot` does? + +
+ +## 2. Draw which LED is ON after running this code + +``` +led.plot(2, 2) +``` + +![](/static/mb/empty-microbit.png) + +## 3. Draw which LED is ON after running this code + +``` +led.plot(0, 0) +``` + +![](/static/mb/empty-microbit.png) + +## 4. Draw which LED is ON after running this code + +``` +led.plot(4, 4) +``` + +![](/static/mb/empty-microbit.png) + diff --git a/docs/reference/js/lessons/blinks-rectangle/challenges.md b/docs/reference/js/lessons/blinks-rectangle/challenges.md new file mode 100644 index 00000000..d676e6dc --- /dev/null +++ b/docs/reference/js/lessons/blinks-rectangle/challenges.md @@ -0,0 +1,79 @@ +# rectangle explosion challenges + +These challenges will allow you to make an exploding rectangle. #docs + +**Challenge 0** + +This [guided tutorial](https://test.microbit.co.uk/td/lessons/blinks-rectangle/tutorial) will help you show an animation forever! + +First, let's make a small rectangle blink forever. + +```blocks +basic.forever(() => { + basic.showAnimation(` +. . . . . . . . . . +. # # # . . . . . . +. # # # . . . . . . +. . . . . . . . . . +. . . . . . . . . . +`, 400) +}) +``` + +**Challenge 1** + +Let's begin creating our explosion effect by adding another rectangle animation that displays a slightly larger rectangle after the first one. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . . . . . . +. # # # . . . . . . +. # # # . . . . . . +. . . . . . . . . . +. . . . . . . . . . +`, 400) + basic.showAnimation(` +. . . . . . . . . . +# # # # # . . . . . +# # # # # . . . . . +# # # # # . . . . . +. . . . . . . . . . +`, 400) +}) +``` + +**Challenge 2** + +To finalize our explosion effect, let's add a rectangle that is bigger than the last two we have created. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . . . . . . +. # # # . . . . . . +. # # # . . . . . . +. . . . . . . . . . +. . . . . . . . . . +`, 400) + basic.showAnimation(` +. . . . . . . . . . +# # # # # . . . . . +# # # # # . . . . . +# # # # # . . . . . +. . . . . . . . . . +`, 400) + basic.showAnimation(` +# # # # # . . . . . +# # # # # . . . . . +# # # # # . . . . . +# # # # # . . . . . +# # # # # . . . . . +`, 400) +}) +``` + +**Challenge 3** + +If you notice, the rectangle explodes fairly slow. Let's make it explode faster by decreasing the intervals of the animation from 400 to 200. + diff --git a/docs/reference/js/lessons/boolean-fun/challenges.md b/docs/reference/js/lessons/boolean-fun/challenges.md new file mode 100644 index 00000000..8e9668f3 --- /dev/null +++ b/docs/reference/js/lessons/boolean-fun/challenges.md @@ -0,0 +1,91 @@ +# speed button challenges + +This challenging script will create a game in which the user needs to press button A fast enough. You will get practice with using booleans in "if" statements. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/speed-button/tutorial) will help you begin creating this game! + +``` +counter = 0 +fastPress = false +input.onButtonPressed("A", () => { + counter = counter + 1 +}) +``` + +### Challenge 1 + +We need to know when the user has hit button `A` 15 times. The user wins when he/she is able to accomplish this in less than 3500 milliseconds (3.5 seconds). We can check for both conditions by using an `and` operator. When using an `and` operator, both conditions need to be true in order for the condition to be true. + +``` +counter = 0 +fastPress = false +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 15 && input.runningTime() < 3500) { + } +}) +``` + +Next, if the user has won, let's set our boolean to true. This indicates that he or she has won. + +``` +counter = 0 +fastPress = false +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 15 && input.runningTime() < 3500) { + fastPress = true // *** + } +}) +``` + +### Challenge 2 + +We want to set `fastPress` to false if the user was too slow. To do so, we need another condition to see if the user took more than 3500 milliseconds (3.5 seconds). In the `if` statement, set `fastPress` to false. + +``` +counter = 0 +fastPress = false +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 15 && input.runningTime() < 3500) { + fastPress = true + } + if (counter == 15 && input.runningTime() > 3499) { + fastPress = false // *** + } +}) +``` + +### Challenge 3 + +Now let's display if the user won or lost. To do so, we need to check the status of `fastPress` when the game is finished, and then show the correct message. + +``` +counter = 0 +fastPress = false +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 15 && input.runningTime() < 3500) { + fastPress = true + } + if (counter == 15 && input.runningTime() > 3499) { + fastPress = false + } + if (counter == 15 && fastPress) { + basic.showString("YOU WIN!", 150) // *** + } + if (counter == 15 && ! fastPress) { + basic.showString("TOO SLOW!", 150) // *** + } +}) +``` + +* Click the `run` button to see if the code runs properly. + +### Challenge 4 + +Modify the code to change the difficulty level. Increasing the time will make it easier, while decreasing the time will make it harder. For example, changing the 3500 milliseconds to 4500 milliseconds will make the difficulty easier. + diff --git a/docs/reference/js/lessons/bop-it.md b/docs/reference/js/lessons/bop-it.md new file mode 100644 index 00000000..d3c7f696 --- /dev/null +++ b/docs/reference/js/lessons/bop-it.md @@ -0,0 +1,97 @@ +# bop it lesson + +a game where you have to keep up with the commands #var #data #if #random #min #max #mod #plot #unplot #pause #accceleration #docs + +## Topic + +Game Library + +## Quick Links + +* [tutorial](/microbit/lessons/bop-it/tutorial) +* [quiz](/microbit/lessons/bop-it/quiz) +* [quiz answers](/microbit/lessons/bop-it/quiz-answers) +* [challenges](/microbit/lessons/bop-it/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a minesweeper game with **if**, `if condition do` , **global variables** to keep track of the action that the player is asked to perform. We will be learning how to create a bop it game using functions, global variables, if (conditionals), input on button pressed, math random, logo down, add score, as well as simple commands such as show string. + +## Documentation + +* **game library** : [read more...](/microbit/js/game-library) +* **global variables** : [read more...](/microbit/js/data) +* **assignment operator** : [read more...](/microbit/reference/variables/assignment) +* **functions** : [read more...](/microbit/js/function) +* **call** : [read more...](/microbit/js/call) +* **math random number** : [read more...](/microbit/js/math) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **on logo down** : [read more...](/microbit/functions/on-logo-down) +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **if** : [read more...](/microbit/reference/logic/if) +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **show string** : [read more...](/microbit/reference/basic/show-string) + +## Objectives + +* learn how the game library supports single-player, time-based games: a game library supports setting a number of lives, score, countdown clock, and levels. +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how the assignment operator is used to declare a new variable or update the value of a variable +* learn how to create a function as a unit of code that performs a specific task and returns a result to make the code easier to read, debug, and update +* learn how to call an existing function in the script +* learn how to return a random number +* learn how to run code when an input button is pressed +* learn how to run code when the BBC micro:bit is oriented perpendicularly to the floor with the logo down +* learn how to run code when the BBC micro:bit is shaken; when running code in the web browser, moving the mouse quickly simulates shaking +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to show a string of the LED screen one character at a time (scrolling left to right) +* learn how to show a number on the LED screen one digit at a time (scrolling left to right) + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/bop-it/tutorial) +* [quiz](/microbit/lessons/bop-it/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/bop-it/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/bop-it/challenges) + diff --git a/docs/reference/js/lessons/bop-it/challenges.md b/docs/reference/js/lessons/bop-it/challenges.md new file mode 100644 index 00000000..97554e43 --- /dev/null +++ b/docs/reference/js/lessons/bop-it/challenges.md @@ -0,0 +1,87 @@ +# bop it challenges + +a game similar to "Simon Says" with the BBC micro:bit. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/bop-it/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +newAction() // *** +input.onButtonPressed("A", () => { + if (action == 0) { + game.addScore(1) // *** + newAction() // *** + } +}) // *** +input.onLogoDown(() => { + if (action == 1) { + game.addScore(1) // *** + newAction() // *** + } +}) // *** +input.onGesture(Gesture.Shake, () => { + if (action == 2) { + game.addScore(1) // *** + newAction() // *** + } +}) // *** +input.onButtonPressed("B", () => { + basic.showNumber(game.score(), 150) // *** + basic.pause(2000) // *** + newAction() // *** +}) // *** +``` + +### Challenge 1 + +Now let's add some more types of instructions for the player to follow. Let's add `PRESS PIN 0`. Change the global variable `action` to `math->random(4)` so that we can add a new **IF** statement that checks if `action=3`. If it does, display instructions to press pin 0. + +``` +/** + * {highlight} + */ +export function newAction_() { + action = Math.random(4) // *** + if (action == 0) { + basic.showString("PUSH A", 150) // *** + } + if (action == 1) { + basic.showString("LOGO DOWN", 150) // *** + } + if (action == 2) { + basic.showString("SHAKE", 150) // *** + } + if (action == 3) { + basic.showString("PRESS PIN 0", 150) // *** + } +} +``` + +### Challenge 2 + +Now let's implement `PRESS PIN 0` in the main. Create a condition of `input->on pin pressed("P0")` that will add one to the score and calls the method `new action`. + +``` +// **. . .** +input.onButtonPressed("B", () => { + basic.showNumber(game.score(), 150) // *** + basic.pause(2000) // *** + newAction() // *** +}) // *** +input.onPinPressed("P0", () => { + if (action == 3) { + game.addScore(1) // *** + newAction() // *** + } +}) // *** +``` + +### Challenge 3 + +Add `POINT ME NORTH` to the list of possible commands. + diff --git a/docs/reference/js/lessons/bop-it/quiz-answers.md b/docs/reference/js/lessons/bop-it/quiz-answers.md new file mode 100644 index 00000000..f569b53a --- /dev/null +++ b/docs/reference/js/lessons/bop-it/quiz-answers.md @@ -0,0 +1,86 @@ +# bop it quiz answers + +a game where you have to keep up with the commands #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [bop it tutorial](/microbit/lessons/bop-it/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2 + +
+ +``` +action = Math.random(3) +``` + +## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0 + +
+ +``` +if (action == 0) { + basic.showString("PUSH A", 150) +} +``` + +## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1 + +
+ +``` +input.onButtonPressed("A", () => { + if (action == 0) { + game.addScore(1) + } +}) +``` + +## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1 + +
+ +``` +if (action == 1) { + basic.showString("LOGO DOWN", 150) +} +``` + +## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1 + +
+ +``` +input.onLogoDown(() => { + if (action == 1) { + game.addScore(1) + } +}) +``` + +## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2 + +
+ +``` +if (action == 2) { + basic.showString("SHAKE", 150) +} +``` + +## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2 + +
+ +``` +input.onLogoDown(() => { + if (action == 1) { + game.addScore(1) + } +}) +``` + diff --git a/docs/reference/js/lessons/bop-it/quiz.md b/docs/reference/js/lessons/bop-it/quiz.md new file mode 100644 index 00000000..1bf328c6 --- /dev/null +++ b/docs/reference/js/lessons/bop-it/quiz.md @@ -0,0 +1,40 @@ +# bop it quiz + +a game where you have to keep up with the commands #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [bop it tutorial](/microbit/lessons/bop-it/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that will store the global variable named 'action' and returns a random number between 0 and 2 + +
+ +## 2. Write the code that will display the string, "PUSH A" if the global variable called 'action' is equal to 0 + +
+ +## 3. Write the code that increments the score if button A is pressed when the global variable called 'action' is equal to 1 + +
+ +## 4. Write the code that will display the string "LOGO DOWN" if the global variable called 'action' is equal to 1 + +
+ +## 5. Write the code that increments the score if the BBC micro:bit logo is tilted down when the global variable called 'action' is equal to 1 + +
+ +
+ +## 6. Write the code that will display the string "SHAKE" if the global variable called 'action' is equal to 2 + +
+ +## 7. Write the code that increments the score if the BBC micro:bit is shaken when the global variable called 'action' is equal to 2 + diff --git a/docs/reference/js/lessons/bounce-image.md b/docs/reference/js/lessons/bounce-image.md new file mode 100644 index 00000000..26221140 --- /dev/null +++ b/docs/reference/js/lessons/bounce-image.md @@ -0,0 +1,108 @@ +# bounce image lesson + +scroll an image across the screen #animation #docs + +### @video td/videos/bounce-image-0 + +## Topic + +Basic- Show Animation + +## Quick Links + +* [tutorial](/microbit/lessons/bounce-image/tutorial) +* [quiz](/microbit/lessons/bounce-image/quiz) +* [quiz answers](/microbit/lessons/bounce-image/quiz-answers) +* [challenges](/microbit/lessons/bounce-image/challenges) + +## Class + +Year 7 + +## Prior learning / place of lesson in scheme of work + +Learn how to creating an **animation**, `basic->show animation` to display a series of images. We will be learning how to create a counter app using a forever loop, the input on shake, and show animation. + +## What the teacher needs to know / QuickStart Computing Glossary + +* Algorithm: An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Hardware: The physical systems and components of digital devices; see also software. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Loop: A block of code repeated automatically under the program’s control. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. + +## Documentation + +* **forever** : [read more...](/microbit/reference/basic/forever) +* **show animation** : [read more...](/microbit/reference/basic/show-animation) +* **on shake** : [read more...](/microbit/reference/input/on-gesture) + +## Resources + +* Activity: [tutorial](/microbit/lessons/bounce-image/tutorial) +* Activity: [quiz](/microbit/lessons/bounce-image/quiz) +* Extended Activity: [challenges](/microbit/lessons/bounce-image/challenges) + +## Objectives + +* learn how to repeat code in the background forever +* learn how to show a series of image frames on the LED screen, pausing the specified time after each frame +* learn how to run code when the micro:bit is shaken; when running code in the web browser, moving the mouse quickly simulates shaking + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Understands that iteration is the repetition of a process such as a loop (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Selects the appropriate data types(AL) (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/bounce-image/tutorial) +* [quiz](/microbit/lessons/bounce-image/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/bounce-image/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/bounce-image/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/bounce-image/challenges.md b/docs/reference/js/lessons/bounce-image/challenges.md new file mode 100644 index 00000000..2fad0f7d --- /dev/null +++ b/docs/reference/js/lessons/bounce-image/challenges.md @@ -0,0 +1,90 @@ +# bounce image challenges + +Coding challenges for the bounce image tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/bounce-image/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.forever(() => { + basic.showAnimation(` +# . . . . . # . . . . . # . . . . . # . . . . . # +# . . . . . # . . . . . # . . . . . # . . . . . # +# . . . . . # . . . . . # . . . . . # . . . . . # +# . . . . . # . . . . . # . . . . . # . . . . . # +# . . . . . # . . . . . # . . . . . # . . . . . # +`, 200) +}) +``` + +### Challenge 1 + +### @video td/videos/bounce-image-1 + +Now, let's add frames to reverse the animation so it looks like the bar is bouncing off the right edge of the display. + +``` +basic.forever(() => { + basic.showAnimation(` +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +`, 200) // *** +}) +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +Let's add a condition for on shake! + +``` +basic.forever(() => { + basic.showAnimation(` +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +`, 200) +}) +input.onGesture(Gesture.Shake, () => { +}) // *** +``` + +**Challenge 3** + +### @video td/videos/bounce-image-2-3 + +When the BBC micro:bit is shaken we want to show a new animation. Here is an example, but you can create your own. Be creative! + +``` +basic.forever(() => { + basic.showAnimation(` +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . . +`, 200) +}) +input.onGesture(Gesture.Shake, () => { + basic.showAnimation(` +. . . . . . . . . . # # # # # . . . . . . . . . . +. . . . . . # # # . # # # # # . # # # . . . . . . +. . # . . . # # # . # # # # # . # # # . . . # . . +. . . . . . # # # . # # # # # . # # # . . . . . . +. . . . . . . . . . # # # # # . . . . . . . . . . +`, 200) // *** +}) +``` + +* Run the code to see if it works as expected. diff --git a/docs/reference/js/lessons/bounce-image/quiz-answers.md b/docs/reference/js/lessons/bounce-image/quiz-answers.md new file mode 100644 index 00000000..5ff5ab05 --- /dev/null +++ b/docs/reference/js/lessons/bounce-image/quiz-answers.md @@ -0,0 +1,60 @@ +# bounce image quiz answers + +scroll an image on the BBC micro:bit #LED #screen #animation #docs + +This is the answer key for the [bounce image quiz](/microbit/lessons/bounce-image/quiz). + +## 1. What does it mean to 'add frames' ? + +Adding frames modifies the animation by including more still images in each animation. + +## 2. Write the code that will display this animation. + +![](/static/mb/lessons/bounce-image-0.png) + +
+ +``` +basic.showAnimation(` +# . . . . +# . . . . +# . . . . +# . . . . +# . . . . +`, 400) +``` + +## 3. Write the code that will display this animation with two frames. + +![](/static/mb/lessons/bounce-image-1.png) + +
+ +``` +basic.showAnimation(` +# . . . . . # . . . +# . . . . . # . . . +# . . . . . # . . . +# . . . . . # . . . +# . . . . . # . . . +`, 400) +``` + +## 4. Write the code that will display this animation with three frames. + +![](/static/mb/lessons/bounce-image-2.png) + +
+ +``` +basic.showAnimation(` +# . . . . . # . . . . . # . . +# . . . . . # . . . . . # . . +# . . . . . # . . . . . # . . +# . . . . . # . . . . . # . . +# . . . . . # . . . . . # . . +`, 400) +``` + +
+ diff --git a/docs/reference/js/lessons/bounce-image/quiz.md b/docs/reference/js/lessons/bounce-image/quiz.md new file mode 100644 index 00000000..d5f391ee --- /dev/null +++ b/docs/reference/js/lessons/bounce-image/quiz.md @@ -0,0 +1,40 @@ +# bounce image quiz + +scroll an image on the BBC micro:bit #LED #screen #animation #docs + +## Name + +## Directions + +Use this document to guide your work in the [bounce image tutorial](/microbit/lessons/bounce-image/tutorial) ! + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What does it mean to 'add frames' ? + +
+ +
+ +## 2. Write the code that will display this animation. + +![](/static/mb/lessons/bounce-image-0.png) + +
+ +## 3. Write the code that will display this animation with two frames. + +![](/static/mb/lessons/bounce-image-1.png) + +
+ +
+ +## 4. Write the code that will display this animation with three frames. + +![](/static/mb/lessons/bounce-image-2.png) + +
+ +
+ diff --git a/docs/reference/js/lessons/boxer-mania/challenges.md b/docs/reference/js/lessons/boxer-mania/challenges.md new file mode 100644 index 00000000..049dff47 --- /dev/null +++ b/docs/reference/js/lessons/boxer-mania/challenges.md @@ -0,0 +1,85 @@ +# boxer mania challenges + +My script. #docs + +This [guided tutorial](/microbit/lessons/boxer-mania/tutorial) will help you create an animation! + +**Challenge 0** + +Let's create and show a series of frames on the LED screen; this is an animation! + +We will use multiple frames to make it look like a square is rotating on the micro:bit screen! + +``` +basic.showAnimation(` +. # . . . +# . . . . +. # . . . +. . # . # +. . . # . +`, 400) +``` + +**Challenge 1** + +Let's create the next frame to make it look like the square is spinning clock-wise! + +``` +basic.showAnimation(` +. # . . . +# . . . . +. # . . . +. . # . # +. . . # . +`, 400) +basic.showAnimation(` +# # # # # +# . . . # +# . . . # +# . . . # +# # # # # +`, 400) // *** +``` + +**Challenge 2** + +Add the next two frames to show a complete rotation for the square! + +``` +basic.showAnimation(` +. # . . . +# . . . . +. # . . . +. . # . # +. . . # . +`, 400) +basic.showAnimation(` +# # # # # +# . . . # +# . . . # +# . . . # +# # # # # +`, 400) +basic.showAnimation(` +. # . . . # # # # # +# . # . . # . . . # +. . . # . # . . . # +. . . . # # . . . # +. . . # . # # # # # +`, 400) // *** +``` + +**Challenge 3** + +Do you want to show the same animation with fewer lines of codes? We can do this by combining all the frames into one show animation function call! + +``` +basic.showAnimation(` +. # . . . # # # # # . # . . . # # # # # +# . . . . # . . . # # . # . . # . . . # +. # . . . # . . . # . . . # . # . . . # +. . # . # # . . . # . . . . # # . . . # +. . . # . # # # # # . . . # . # # # # # +`, 400) // *** +``` + diff --git a/docs/reference/js/lessons/break/challenges.md b/docs/reference/js/lessons/break/challenges.md new file mode 100644 index 00000000..e942374e --- /dev/null +++ b/docs/reference/js/lessons/break/challenges.md @@ -0,0 +1,86 @@ +# break challenges + +This guide will show you how to use a break statement within a while loop. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](/microbit/lessons/break/tutorial) will assist you with this activity. + +``` +count = 0 +shouldBreak = false +input.onButtonPressed("A", () => { + shouldBreak = true +}) +while (true) { + if (shouldBreak) { + basic.showString("I'M OUT!", 150) + images.createImage(` +# . . . # +# . . . # +. . # . . +# . . . # +. # # # . +`).showImage(0) + break + } + count = count + 1 + basic.showNumber(count, 150) + basic.pause(1000) +} +``` + +### Challenge 1 + +Try to remove the `break` in the `if` loop. What problem does this create? + +### Challenge 2 + +Now let's resume the timer again once button `B` is pressed! To do so, begin by creating a condition to know when button `B` is pressed. + +``` +// **. . .** +while (true) { + if (shouldBreak) { + basic.showString("I'M OUT!", 150) + break + } + count = count + 1 + basic.showNumber(count, 150) + basic.pause(1000) +} +input.onButtonPressed("B", () => { +}) // *** +``` + +Next, set `shouldBreak` back to false to indicate we want to run the `while` loop again. + +``` +// **. . .** +input.onButtonPressed("B", () => { + shouldBreak = false // *** +}) +``` + +And now copy the code from the previous while loop into the condition of `input->on button pressed("B")`. This will resume the counter. + +``` +// **. . .** +input.onButtonPressed("B", () => { + shouldBreak = false + while (true) { + if (shouldBreak) { + basic.showString("I'M OUT!", 150) // *** + break // *** + } + count = count + 1 // *** + basic.showNumber(count, 150) // *** + basic.pause(1000) // *** + } +}) +``` + +### Challenge 3 + +Notice that the two `while` loops are identical. Clean up this redundancy in your code by creating another method and then placing the `while` loop in the method. + diff --git a/docs/reference/js/lessons/button/challenges.md b/docs/reference/js/lessons/button/challenges.md new file mode 100644 index 00000000..c619303d --- /dev/null +++ b/docs/reference/js/lessons/button/challenges.md @@ -0,0 +1,52 @@ +# button challenges + +My script. #docs + +### Challenge 0 + +Howdy! This [guided tutorial](/microbit/rxqgzy) will help you complete this activity! + +In this guide, you will learn how to use buttons and show text on the screen. Let's start by adding to respond **when the left button is pressed**. + +``` +input.onButtonPressed("A", () => { +}) +``` + +All the code inside `input->on button pressed` runs when the button is pressed. Let's add the code to show some text. + +``` +input.onButtonPressed("A", () => { + basic.showString("hello", 150) +}) +``` + +### Challenge 1 + +Let's add an event handler for Button `B`. + +``` +input.onButtonPressed("A", () => { + basic.showString("hello", 150) +}) +input.onButtonPressed("B", () => { +}) +``` + +### Challenge 2 + +Display `bye` when the `B` button is pressed. + +``` +input.onButtonPressed("A", () => { + basic.showString("hello", 150) +}) +input.onButtonPressed("B", () => { + basic.showString("bye", 150) +}) +``` + +### Challenge 3 + +Change the strings so that they display some other text. In order to do so, you will need to edit what is inside the quotation marks in `basic->show string`. + diff --git a/docs/reference/js/lessons/cascade/quiz.md b/docs/reference/js/lessons/cascade/quiz.md new file mode 100644 index 00000000..e2aa61a4 --- /dev/null +++ b/docs/reference/js/lessons/cascade/quiz.md @@ -0,0 +1,128 @@ +# strobe lightquiz + +Learn how to create a blinking LED script with a for loop. #LED #screen #plot #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [light column cascade tutorial](/microbit/js/light-column-cascade/tutorial). + +Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs! + +## 1. What is a for loop? + +## 2. Consider the following code + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +## 3. Consider the following code + +``` +for (let i1 = 0; i1 < 3; i1++) { + for (let j1 = 0; j1 < 3; j1++) { + led.plot(i1, j1) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +## 4. Consider the following code + +``` +for (let i2 = 0; i2 < 2; i2++) { + for (let j2 = 0; j2 < 2; j2++) { + led.plot(i2, j2) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +****************************** + +## ANSWER KEY + +## Directions + +Answer the questions below while working on or after you finish the tutorial. + +## 1. What is a for loop? + +Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates. + +## 2. Consider the following code + +``` +for (let i3 = 0; i3 < 5; i3++) { + for (let j3 = 0; j3 < 5; j3++) { + led.plot(i3, j3) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-0.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs + +x - the x coordinate or horizontal position (0,1,2,3,4) + +y - the y coordinate or vertical position (0,1,2,3,4) + +## 3. Consider the following code + +``` +for (let i4 = 0; i4 < 3; i4++) { + for (let j4 = 0; j4 < 3; j4++) { + led.plot(i4, j4) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-1.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +x - the x coordinate or horizontal position (0,1,2) + +y - the y coordinate or vertical position (0,1,2) + +## 4. Consider the following code + +``` +for (let i5 = 0; i5 < 2; i5++) { + for (let j5 = 0; j5 < 2; j5++) { + led.plot(i5, j5) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-2.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +x - the x coordinate or horizontal position (0,1) + +y - the y coordinate or vertical position (0,1) + diff --git a/docs/reference/js/lessons/catch-the-egg-game.md b/docs/reference/js/lessons/catch-the-egg-game.md new file mode 100644 index 00000000..fb7a00e5 --- /dev/null +++ b/docs/reference/js/lessons/catch-the-egg-game.md @@ -0,0 +1,91 @@ +# catch the egg game lesson + +a game to catch eggs in a basket #var #data #if #random #min #max #mod #plot #unplot #pause #accceleration #docs + +### @video td/videos/catch-the-egg-game-0 + +## Topic + +Variables + +## Quick Links + +* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial) +* [quiz](/microbit/lessons/catch-the-egg-game/quiz) +* [quiz answers](/microbit/lessons/catch-the-egg-game/quiz-answers) +* [challenges](/microbit/lessons/catch-the-egg-game/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a catch the egg game game with **plot**, `led->plot` , **unplot**, `led->unplot`, and **acceleration** `input -> acceleration` to turn on and off LED lights on the LED screen. We will be learning how to create a catch the egg game app using global variables, forever loop, local variable, input acceleration, math min, math max, math random, math mod, if (conditionals), game library as well as simple commands, such as led plot, led unplot, and pause. + +## Documentation + +* **variables** : [read more...](/microbit/reference/variables/var) +* **forever** : [read more...](/microbit/reference/basic/forever) +* **unplot** : [read more...](/microbit/reference/led/unplot) +* **plot** : [read more...](/microbit/reference/led/plot) +* **if** : [read more...](/microbit/reference/logic/if) +* **acceleration** : [read more...](/microbit/reference/input/acceleration) +* **math minimum number** : [read more...](/microbit/js/math) +* **math maximum number** : [read more...](/microbit/js/math) +* **math random number** : [read more...](/microbit/js/math) +* **math modulus** : [read more...](/microbit/js/math) +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how to repeat code in the background forever +* learn how to turn off a LED light on the LED screen +* learn how to turn on a LED light on the LED screen +* learn how to learn how to conditionally run code depending on whether a condition is true or not +* learn how to learn how to get the acceleration value (g-force), in one of three specified dimensions +* learn how to return the smaller of two numbers +* learn how to return the larger of two numbers +* learn how to return a random number +* learn how to return the modulus +* learn how to show a number of the BBC micro:bit screen +* learn how to pause your code for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial) +* [quiz](/microbit/lessons/catch-the-egg-game/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/catch-the-egg-game/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/catch-the-egg-game/challenges) + diff --git a/docs/reference/js/lessons/catch-the-egg-game/challenges.md b/docs/reference/js/lessons/catch-the-egg-game/challenges.md new file mode 100644 index 00000000..29aa3fba --- /dev/null +++ b/docs/reference/js/lessons/catch-the-egg-game/challenges.md @@ -0,0 +1,163 @@ +# catch the egg game challenges + +Coding challenges for catch the egg game. + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +let basketX = 2 +let eggX = 2 +let eggY = 0 +basic.forever(() => { + led.unplot(basketX, 4) + led.unplot(eggX, eggY) + eggY = eggY + 1 + led.plot(eggX, eggY) + basic.pause(300) + let accX = input.acceleration("x") + basketX = 2 + Math.min(2, Math.max(-2, accX / 200)) + led.plot(basketX, 4) + if (eggY > 4) { + eggY = -1 + eggX = Math.random(5) + } + basic.pause(300) +}) +``` + +### ~avatar avatar impressed + +### Challenge 1 + +Let's start by adding the **game** library. + +### ~ + +### ~avatar avatar improvised + +### Challenge 2 + +Let's use an **IF** statement to detect if the egg and the basket are lined up. + +Now that we know when an egg is caught, we can keep track of the score! We need to use the `add score` function built into the game library to add `1` point for every egg that is caught. However, let's not forget to `remove life` if an egg falls off the display before it's caught! + +### ~ + +``` +let basketX1 = 2 +let eggX1 = 2 +let eggY1 = 0 +basic.forever(() => { + led.unplot(basketX1, 4) + led.unplot(eggX1, eggY1) + eggY1 = eggY1 + 1 + led.plot(eggX1, eggY1) + basic.pause(300) + let accX1 = input.acceleration("x") + basketX1 = 2 + Math.min(2, Math.max(-2, accX1 / 200)) + led.plot(basketX1, 4) + if (eggY1 > 4) { + eggY1 = -1 + eggX1 = Math.random(5) + } + if (eggY1 == 4) { + if (basketX1 == eggX1) { + game.addScore(1) // *** + } else { + game.removeLife(1) // *** + } + } + basic.pause(300) +}) +``` + +* Press the `run` button to test out your game. + +### ~avatar avatar encourage + +### Challenge 3 + +Catching eggs gets easier with practice so let's make the eggs fall faster every 5 catches. We can do this by tracking how long the egg pauses in each position while falling with a global variable called **falling pause**. Let's create this variable and set it to `300` initially. Don't forget to also create a condition that will be true every 5 catches. + +### ~ + +``` +let basketX2 = 2 +let eggX2 = 2 +let eggY2 = 0 +let fallingPause = 300 // *** +basic.forever(() => { + led.unplot(basketX2, 4) + led.unplot(eggX2, eggY2) + eggY2 = eggY2 + 1 + led.plot(eggX2, eggY2) + basic.pause(300) + let accX2 = input.acceleration("x") + basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200)) + led.plot(basketX2, 4) + if (eggY2 > 4) { + eggY2 = -1 + eggX2 = Math.random(5) + } + if (eggY2 == 4) { + if (basketX2 == eggX2) { + game.addScore(1) + if (math.mod(game.score(), 5) == 0) { + } + } else { + game.removeLife(1) + } + } + basic.pause(300) +}) +``` + +### ~avatar avatar surprised + +### Challenge 4 + +### @video td/videos/catch-the-egg-game-4 + +Let's make the egg fall faster by decreasing the amount of time it pauses in each position by decreasing **falling pause** by `25` every 5 catches. Now, instead of pausing for 300 milliseconds we can pause for the value of **falling pause**. + +``` +let basketX3 = 2 +let eggX3 = 2 +let eggY3 = 0 +let fallingPause1 = 300 +basic.forever(() => { + led.unplot(basketX3, 4) + led.unplot(eggX3, eggY3) + eggY3 = eggY3 + 1 + led.plot(eggX3, eggY3) + basic.pause(300) + let accX3 = input.acceleration("x") + basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200)) + led.plot(basketX3, 4) + if (eggY3 > 4) { + eggY3 = -1 + eggX3 = Math.random(5) + } + if (eggY3 == 4) { + if (basketX3 == eggX3) { + game.addScore(1) + if (math.mod(game.score(), 5) == 0) { + fallingPause1 = fallingPause1 - 25 // *** + } + } else { + game.removeLife(1) + } + } + basic.pause(fallingPause1) // *** +}) +``` + +Fantastic! Your game is now ready to show off. + +* Press the `run` button to see your finished game! diff --git a/docs/reference/js/lessons/catch-the-egg-game/quiz-answers.md b/docs/reference/js/lessons/catch-the-egg-game/quiz-answers.md new file mode 100644 index 00000000..38da8ba0 --- /dev/null +++ b/docs/reference/js/lessons/catch-the-egg-game/quiz-answers.md @@ -0,0 +1,61 @@ +# catch the egg game quiz answers + +Programming a game of catch the egg using the accelerometer + +## Name + +## Directions + +Use this activity document to guide your work in the [catch the egg tutorial](/microbit/lessons/catch-the-egg-game/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the data type for the global variables 'basket' and 'egg'. + +
+ +'Basket' and 'egg' are stored as **Number**. + +## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below. + +![](/static/mb/lessons/catch-the-egg-game-0.png) + +
+ +``` +led.plot(eggX, eggY) +led.plot(basketX, 4) +``` + +## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position. + +
+ +``` +led.unplot(eggX, eggY) +eggY = eggY + 1 +led.plot(eggX, eggY) +``` + +## 4. Write the code that calculates 'basket x' given the variable 'acc x'. + +
+ +``` +let accX = input.acceleration("x") +basketX = 2 + Math.min(2, Math.max(-2, accX / 200)) +``` + +Note: the first line of code in this answer is optional. + +## 5. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit. + +
+ +``` +if (eggY > 4) { + eggY = -1 + eggX = Math.random(5) +} +``` + diff --git a/docs/reference/js/lessons/catch-the-egg-game/quiz.md b/docs/reference/js/lessons/catch-the-egg-game/quiz.md new file mode 100644 index 00000000..28125f26 --- /dev/null +++ b/docs/reference/js/lessons/catch-the-egg-game/quiz.md @@ -0,0 +1,34 @@ +# catch the egg game quiz + +Programming a game of catch the egg using the accelerometer. + +## Name + +## Directions + +Use this activity document to guide your work in the [catch the egg tutorial](/microbit/lessons/catch-the-egg-game/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the data type for the global variables 'basket' and 'egg'. + +
+ +## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below. + +![](/static/mb/lessons/catch-the-egg-game-0.png) + +
+ +## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position. + +
+ +## 4. Write the code that calculates 'basket x' given the variable 'acc x'. + +
+ +## 5. Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit. + +
+ diff --git a/docs/reference/js/lessons/catch-the-egg.md b/docs/reference/js/lessons/catch-the-egg.md new file mode 100644 index 00000000..6b0a9d84 --- /dev/null +++ b/docs/reference/js/lessons/catch-the-egg.md @@ -0,0 +1,8 @@ +# catch the egg + +Programming a game of 'catch the egg' using the accelerometer in Touch Develop #docs #functions #var + +Programming a game of 'catch the egg' using the accelerometer + +* [tutorial](/microbit/lessons/catch-the-egg-game/tutorial) +* [challenges](/microbit/lessons/catch-the-egg/challenges) diff --git a/docs/reference/js/lessons/clear-screen/challenges.md b/docs/reference/js/lessons/clear-screen/challenges.md new file mode 100644 index 00000000..c4649671 --- /dev/null +++ b/docs/reference/js/lessons/clear-screen/challenges.md @@ -0,0 +1,77 @@ +# clear screen challenges + +My script. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](/microbit/hzckbb) will help you create the script to clear the screen! + +Your goal is to clear the screen after displaying an animation. Begin by showing and displaying an animation. Remember that the `show animation` is in the `basic` namespace. We then need to detect when the "A" button is pressed. Finally, clear the screen by typing in `basic->clear screen`. + +Your main function should look like this: + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() +}) +``` + +* tap the `run` button to view the script on the monitor. + +### Challenge 1 + +Create an event handler for Button "B". + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() +}) +input.onButtonPressed("B", () => { +}) +``` + +### Challenge 2 + +Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`. + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() +}) +input.onButtonPressed("B", () => { + basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) // *** +}) +``` + +### Challenge 3 + +Show an animation that scrolls back up when you press button "B". + +* tap the `run` button to view your final product! diff --git a/docs/reference/js/lessons/column/quiz.md b/docs/reference/js/lessons/column/quiz.md new file mode 100644 index 00000000..2935840f --- /dev/null +++ b/docs/reference/js/lessons/column/quiz.md @@ -0,0 +1,128 @@ +# cascade quiz + +Learn how to create a blinking LED script with a for loop. #LED #screen #plot #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [light column cascade tutorial](/microbit/js/light-column-cascade/tutorial). + +Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs! + +## 1. What is a for loop? + +## 2. Consider the following code + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +## 3. Consider the following code + +``` +for (let i1 = 0; i1 < 3; i1++) { + for (let j1 = 0; j1 < 3; j1++) { + led.plot(i1, j1) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +## 4. Consider the following code + +``` +for (let i2 = 0; i2 < 2; i2++) { + for (let j2 = 0; j2 < 2; j2++) { + led.plot(i2, j2) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +****************************** + +## KEY + +## Directions + +Answer the questions below while working on or after you finish the tutorial. + +## 1. What is a for loop? + +Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates. + +## 2. Consider the following code + +``` +for (let i3 = 0; i3 < 5; i3++) { + for (let j3 = 0; j3 < 5; j3++) { + led.plot(i3, j3) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-0.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs + +x - the x coordinate or horizontal position (0,1,2,3,4) + +y - the y coordinate or vertical position (0,1,2,3,4) + +## 3. Consider the following code + +``` +for (let i4 = 0; i4 < 3; i4++) { + for (let j4 = 0; j4 < 3; j4++) { + led.plot(i4, j4) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/column-0.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +x - the x coordinate or horizontal position (0,1,2) + +y - the y coordinate or vertical position (0,1,2) + +## 4. Consider the following code + +``` +for (let i5 = 0; i5 < 1; i5++) { + for (let j5 = 0; j5 < 1; j5++) { + led.plot(i5, j5) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/column-1.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +x - the x coordinate or horizontal position (0,1) + +y - the y coordinate or vertical position (0,1) + diff --git a/docs/reference/js/lessons/compare-machine/challenges.md b/docs/reference/js/lessons/compare-machine/challenges.md new file mode 100644 index 00000000..6012430b --- /dev/null +++ b/docs/reference/js/lessons/compare-machine/challenges.md @@ -0,0 +1,79 @@ +# compare machine challenges + +These challenges allow you to set the value of a counter to 1 when button B is pressed. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](/microbit/lessons/comparison/tutorial) will assist you with using the comparison operator. + +``` +counter = 0 +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 10) { + counter = 1 + } + basic.showNumber(counter, 150) +}) +``` + +### Challenge 1 + +Now let's do something special when the micro:bit reaches the number `5`. Instead of just showing the number `5`, let's show the string `HALF WAY!`. Begin by setting an if statement to know when `counter = 5`. + +``` +counter = 0 +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 10) { + counter = 1 + } + if (counter == 5) { + } + basic.showNumber(counter, 150) +}) +``` + +### Challenge 2 + +Let's continue our plan of displaying `HALF WAY!` when `counter = 5`. To do so, add the following line of code inside the if statement. + +``` +counter = 0 +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 10) { + counter = 1 + } + if (counter == 5) { + basic.showString("HALF WAY!", 150) // *** + } + basic.showNumber(counter, 150) +}) +``` + +* Run your code to see if it works as expected. + +### Challenge 3 + +You may notice a problem right now. When `counter = 5`, the micro:bit will show both the message `HALF WAY!` and the number `5`. In order to fix this problem, let's take advantage of the `else` at the end of the if statement. + +``` +counter = 0 +input.onButtonPressed("A", () => { + counter = counter + 1 + if (counter == 10) { + counter = 1 + } + if (counter == 5) { + basic.showString("HALF WAY!", 150) + } else { + basic.showNumber(counter, 150) // *** + } +}) +``` + +### Challenge 4 + +When `counter = 8`, display the message `ALMOST THERE!` on the micro:bit. You will need to add an `else if` after the if statement of `counter = 5`. + diff --git a/docs/reference/js/lessons/compass.md b/docs/reference/js/lessons/compass.md new file mode 100644 index 00000000..2980cde5 --- /dev/null +++ b/docs/reference/js/lessons/compass.md @@ -0,0 +1,8 @@ +# compass lesson + +build a compass app that applies the BBC micro:bit magnetic sensor (magnetometer) #functions #var #docs + +build a compass app that applies the BBC micro:bit magnetic sensor (magnetometer) + +* [tutorial](/microbit/lessons/compass/tutorial) +* [challenges](/microbit/lessons/compass/challenges) diff --git a/docs/reference/js/lessons/compass/challenges.md b/docs/reference/js/lessons/compass/challenges.md new file mode 100644 index 00000000..5a001be5 --- /dev/null +++ b/docs/reference/js/lessons/compass/challenges.md @@ -0,0 +1,88 @@ +# compass challenges + +Display the direction that the BBC micro:bit is facing using the compass + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/compass/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +input.calibrate() +basic.forever(() => { + let degrees = input.compassHeading() + if (degrees < 45) { + basic.showString("N", 100) + } else if (degrees < 135) { + basic.showString("E", 100) + } + else if (degrees < 225) { + basic.showString("S", 100) + } + else { + basic.showString("W", 100) + } +}) +``` + +### Challenge 1 + +Instead of displaying `N` when the BBC micro:bit is pointing North, display a star to indicate the north star. + +``` +input.calibrate() +basic.forever(() => { + let degrees1 = input.compassHeading() + if (degrees1 < 45) { + basic.plotImage(` +# . # . # +. # # # . +# # # # # +. # # # . +# . # . # +`) // *** + } else if (degrees1 < 135) { + basic.showString("E", 100) + } + else if (degrees1 < 225) { + basic.showString("S", 100) + } + else { + basic.showString("W", 100) + } +}) +``` + +* Run your code to see if it works as expected + +### Challenge 2 + +Instead of displaying just `N`, `W`, `S`, or `E`, display the full word. + +``` +input.calibrate() +basic.forever(() => { + let degrees2 = input.compassHeading() + if (degrees2 < 45) { + basic.showString("NORTH", 100) // *** + } else if (degrees2 < 135) { + basic.showString("EAST", 100) // *** + } + else if (degrees2 < 225) { + basic.showString("SOUTH", 100) // *** + } + else { + basic.showString("WEST", 100) // *** + } +}) +``` + +* Run your code to see if it works as expected + +### Challenge 3 + +Display your own unique message for each direction. + diff --git a/docs/reference/js/lessons/compass/quiz-answers.md b/docs/reference/js/lessons/compass/quiz-answers.md new file mode 100644 index 00000000..0748971f --- /dev/null +++ b/docs/reference/js/lessons/compass/quiz-answers.md @@ -0,0 +1,56 @@ +# compass quiz answers + +Create an actual compass to show your direction: North, South, East, or West + +## Name + +## Directions + +Use this activity document to guide your work in the [compass tutorial](/microbit/lessons/compass/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is the purpose of the 'compass heading' block? + +Gets the compass heading of the BBC micro:bit in degrees + +
+ +## 2. Write the code that stores the compass heading into a local variable called 'degrees'. + +
+ +``` +let degrees = input.compassHeading() +``` + +## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the BBC micro:bit + +
+ +``` +if (degrees < 45) { + basic.showString("N", 150) +} +``` + +## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the BBC micro:bit + +
+ +``` +if (degrees < 135) { + basic.showString("E", 150) +} +``` + +## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the BBC micro:bit + +
+ +``` +if (degrees < 225) { + basic.showString("S", 150) +} +``` + diff --git a/docs/reference/js/lessons/compass/quiz.md b/docs/reference/js/lessons/compass/quiz.md new file mode 100644 index 00000000..7b8c4e08 --- /dev/null +++ b/docs/reference/js/lessons/compass/quiz.md @@ -0,0 +1,32 @@ +# compass quiz + +Create an actual compass to show your direction: North, South, East, or West + +## Name + +## Directions + +Use this activity document to guide your work in the [compass tutorial](/microbit/lessons/compass/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is the purpose of the 'compass heading' block? + +
+ +## 2. Write the code that stores the compass heading into a local variable called 'degrees'. + +
+ +## 3. Write the 'If statement' that will check if the device is mostly pointing North. Display 'N' on the BBC micro:bit + +
+ +## 3. Write the 'If statement' that will check if the device is mostly pointing East. Display 'E' on the BBC micro:bit + +
+ +## 3. Write the 'If statement' that will check if the device is mostly pointing South. Display 'S' on the BBC micro:bit + +
+ diff --git a/docs/reference/js/lessons/counter.md b/docs/reference/js/lessons/counter.md new file mode 100644 index 00000000..c470aca8 --- /dev/null +++ b/docs/reference/js/lessons/counter.md @@ -0,0 +1,80 @@ +# counter lesson + +Learn how to create a counter with with on button pressed. #show #number #screen #number #math #docs + +### @video td/videos/counter-0 + +## Topic + +Variables + +## Quick Links + +* [activity](/microbit/lessons/counter/activity) +* [challenges](/microbit/lessons/counter/challenges) +* [quiz](/microbit/lessons/counter/quiz) +* [quiz answers](/microbit/lessons/counter/quiz-answers) +* [tutorial](/microbit/lessons/counter/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using a variable as well as simple commands, such as on button pressed, and show number. + +## Documentation + +* **variable**: [read more...](/microbit/reference/variables/var) +* **arithmetic operators**: [read more...](/microbit/reference/types/number) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Objectives + +* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across all functions, and in nested code blocks +* learn how arithmetic operators operate on numbers and return a number +* learn how to run code when an input button is pressed +* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right) + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/counter/activity) +* [tutorial](/microbit/lessons/counter/tutorial) +* [quiz](/microbit/lessons/counter/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/counter/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/counter/challenges) + diff --git a/docs/reference/js/lessons/counter/activity.md b/docs/reference/js/lessons/counter/activity.md new file mode 100644 index 00000000..94abadb6 --- /dev/null +++ b/docs/reference/js/lessons/counter/activity.md @@ -0,0 +1,45 @@ +# counter activity + +Display a number with a variable. + +### ~avatar avatar + +### @video td/videos/counter-0 + +Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. Let's get started! + +### ~ + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**. + +Let's start by creating a **local variable** `count` to keep track of the current count. + +``` +let count = 0 +``` + +The code under ``on button pressed("A")`` will run each time the user presses A. Let's add a line of code that increments `count` by `1`. + +``` +let count_ = 0 +input.onButtonPressed("A", () => { + count = count + 1 +}) +``` + +Since the count has changed, it's time to refresh the screen display. Let's add a line of code to display the count on screen. + +``` +let count_1 = 0 +input.onButtonPressed("A", () => { + count = count + 1 + basic.showNumber(count, 150) +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/counter/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/counter/challenges.md b/docs/reference/js/lessons/counter/challenges.md new file mode 100644 index 00000000..20698c41 --- /dev/null +++ b/docs/reference/js/lessons/counter/challenges.md @@ -0,0 +1,38 @@ +# counter challenges + +Coding challenges for the counter tutorial. + +## Before we get started + +Complete the following [guided tutorial](/microbit/lessons/counter/activity) At the end of the tutorial, your code should look like this: + +``` +let count = 0 +input.onButtonPressed("A", () => { + count = count + 1 + basic.showNumber(count, 150) +}) +``` + +### Challenge 1 + +### @video td/videos/counter-1-2 + +Let's add the code to `count` when `B` is pressed. Add an event handler with `input->on button pressed(B)` then add the code to `count`. + +``` +let count1 = 0 +input.onButtonPressed("A", () => { + count1 = count1 + 1 + basic.showNumber(count1, 150) +}) +input.onButtonPressed("B", () => { + count1 = count1 - 1 // *** + basic.showNumber(count1, 150) // *** +}) // *** +``` + +### Challenge 3 + +Now let's try to reset the counter when the BBC micro:bit is shaken. You will need to register an event handler with `input->on shake`. + diff --git a/docs/reference/js/lessons/counter/lesson-plan.md b/docs/reference/js/lessons/counter/lesson-plan.md new file mode 100644 index 00000000..1f1d7397 --- /dev/null +++ b/docs/reference/js/lessons/counter/lesson-plan.md @@ -0,0 +1,91 @@ +# counter lesson plan + +Learn how to create a counter with with on button pressed. + +### @video vimeo/134118661 + +## Topic + +Variable - Counter + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using global variables as well as simple commands, such as on button pressed, and show number. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **variables**: [read more...](/microbit/reference/variables/var) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Resources + +* Activity: [tutorial](/microbit/lessons/counter/tutorial) +* Activity: [quiz](/microbit/lessons/counter/quiz) +* Extended Activity: [challenges](/microbit/lessons/counter/challenges) + +## Objectives + +* learn how to create a variable +* learn how to blink a light +* learn how to repeat turning on and off the light + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/counter/tutorial) +* [quiz](/microbit/lessons/counter/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/counter/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/counter/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/counter/quiz-answers.md b/docs/reference/js/lessons/counter/quiz-answers.md new file mode 100644 index 00000000..0d56e96c --- /dev/null +++ b/docs/reference/js/lessons/counter/quiz-answers.md @@ -0,0 +1,54 @@ +# counter quiz answers + +Learn how to create a counter with the BBC micro:bit button. + +This is the answer key for the [counter quiz](/microbit/lessons/counter/quiz). + +## 1. What is a variable? + +Answers may vary but a variable is a place where you can store and retrieve data + +## 2. Draw the stored value for the variable called count + +``` +let count = 0 +``` + +![](/static/mb/lessons/counter-0.png) + +We create a **variable**, `count` to keep track of the current count. The number 0 is stored into memory of the variable. + +
+ +## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number + +``` +let count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count, 150) +}) +``` + +![](/static/mb/lessons/counter-1.png) + +We are only pressing on button pressed once. So the number to display on the micro:bit is also one. + +
+ +## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number + +``` +count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +![](/static/mb/lessons/counter-2.png) + +We included the code ``on button pressed("A")`` that runs each time the user presses A. The code increments `count` by `1`. We increase `count` by 1 whenever the user presses the button. So the third time the A button is pressed on the BBC micro:bit, the number 3 is displayed + +
+ diff --git a/docs/reference/js/lessons/counter/quiz.md b/docs/reference/js/lessons/counter/quiz.md new file mode 100644 index 00000000..eb7dfdf6 --- /dev/null +++ b/docs/reference/js/lessons/counter/quiz.md @@ -0,0 +1,54 @@ +# counter quiz + +Learn how to create a counter with the BBC micro:bit button. + +## Name + +## Directions + +Use this activity document to guide your work in the [counter tutorial](/microbit/lessons/counter/activity). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a variable? + +
+ +## 2. Draw the stored value for the variable called count + +``` +let count = 0 +``` + +![](/static/mb/empty-microbit.png) + +
+ +## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number + +``` +let count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +![](/static/mb/empty-microbit.png) + +
+ +## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number + +``` +count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +![](/static/mb/empty-microbit.png) + +
+ diff --git a/docs/reference/js/lessons/die-roll.md b/docs/reference/js/lessons/die-roll.md new file mode 100644 index 00000000..36cb5487 --- /dev/null +++ b/docs/reference/js/lessons/die-roll.md @@ -0,0 +1,91 @@ +# die roll lesson + +create a die on the BBC micro:bit #button #pressed #math #random #var #string #if #docs + +## Topic + +If (Conditionals) + +## Quick Links + +* [activity](/microbit/lessons/die-roll/activity) +* [challenges](/microbit/lessons/die-roll/challenges) +* [quiz](/microbit/lessons/die-roll/quiz) +* [quiz answers](/microbit/lessons/die-roll/quiz-answers) +* [tutorial](/microbit/lessons/die-roll/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use an if statements to run code run code depending on whether a condition is true or not. We will be learning how to create a die with If statements, On Shake, Variables, Assignment Operator, Pick Random and Show LEDs + +## Documentation + +* **Variables** : [read more...](/microbit/reference/variables/var) +* **If** : [read more...](/microbit/reference/logic/if) +* **On Shake** : [read more...](/microbit/reference/input/on-gesture) +* **Assignment Operator** : [read more...](/microbit/reference/variables/assign) +* **Math Random** : [read more...](/microbit/js/math) +* **Show LEDs** : [read more...](/microbit/reference/basic/show-leds) + +## Objectives + +* learn how to run code when the BBC micro:bit is shaken, when running code in the web browser, moving the mouse quickly simulates shaking +* learn how to create a local variable as a place where you can store and retrieve data +* learn how the assignment operator is used to declare a new local variable +* learn how to declare a new local variable or update the value of a variable +* learn how to return a random number +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to show an image on the LED screen + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Uses filters or can perform single criteria searches for information.(AL) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) +* Defines data types: real numbers and Boolean (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/die-roll/activity) +* [tutorial](/microbit/lessons/die-roll/tutorial) +* [quiz](/microbit/lessons/die-roll/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/die-roll/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/die-roll/challenges) + diff --git a/docs/reference/js/lessons/die-roll/activity.md b/docs/reference/js/lessons/die-roll/activity.md new file mode 100644 index 00000000..b2b1c558 --- /dev/null +++ b/docs/reference/js/lessons/die-roll/activity.md @@ -0,0 +1,130 @@ +# die roll activity + +Create a die on the BBC micro:bit + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **KindScript**. + +Let's create a condition for when the BBC micro:bit is shaken. + +``` +input.onGesture(Gesture.Shake, () => { +}) +``` + +We need to show a random value from 1 to 6 on our die. So let's make a local variable called **roll**. + +``` +input.onGesture(Gesture.Shake, () => { + let roll = Math.random(6) +}) +``` + +We need a condition for if **roll** is 5. We will show a `6` if **roll** is 5 because **roll** has a range from 0 to 5. We can use `Show LEDs` to display the side of a die that shows 6. + +``` +input.onGesture(Gesture.Shake, () => { + let roll1 = Math.random(6) + if (roll1 == 5) { + basic.showLeds(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`, 400) + } +}) +``` + +Let's use an `else if` condition for if **roll** is 4. If **roll** is 4 we can show 5 dots on the die. + +``` +input.onGesture(Gesture.Shake, () => { + let roll2 = Math.random(6) + if (roll2 == 5) { + basic.showLeds(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`, 400) + } else if (roll2 == 4) { + basic.showLeds(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`, 400) + } +}) +``` + +Now we need to repeat the same steps for if **roll** is 3. If **roll** is 3 we will show `4` on the die. Let's also repeat these steps to show the 3, 2, and 1 on the die. We are almost done with our die! + +``` +input.onGesture(Gesture.Shake, () => { + let roll3 = Math.random(6) + if (roll3 == 5) { + basic.showLeds(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`, 400) + } else if (roll3 == 4) { + basic.showLeds(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`, 400) + } + else if (roll3 == 3) { + basic.showLeds(` +. . . . . +. # . # . +. . . . . +. # . # . +. . . . . +`, 400) + } + else if (roll3 == 2) { + basic.showLeds(` +# . . . . +. . . . . +. . # . . +. . . . . +. . . . # +`, 400) + } + else if (roll3 == 1) { + basic.showLeds(` +. . . . . +. # . . . +. . . . . +. . . # . +. . . . . +`, 400) + } + else { + basic.showLeds(` +. . . . . +. . . . . +. . # . . +. . . . . +. . . . . +`, 400) + } +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/die-roll/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/die-roll/challenges.md b/docs/reference/js/lessons/die-roll/challenges.md new file mode 100644 index 00000000..e1f245fc --- /dev/null +++ b/docs/reference/js/lessons/die-roll/challenges.md @@ -0,0 +1,201 @@ +# die roll challenges + +Create a die on the BBC micro:bit. + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/die-roll/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +input.onGesture(Gesture.Shake, () => { + let roll = Math.random(6) // *** + if (roll == 5) { + basic.plotImage(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`) + } else if (roll == 4) { + basic.plotImage(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`) + } + else if (roll == 3) { + basic.plotImage(` +. . . . . +. # . # . +. . . . . +. # . # . +. . . . . +`) + } + else if (roll == 2) { + basic.plotImage(` +# . . . . +. . . . . +. . # . . +. . . . . +. . . . # +`) + } + else if (roll == 1) { + basic.plotImage(` +. . . . . +. # . . . +. . . . . +. . . # . +. . . . . +`) + } + else { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. . . . . +. . . . . +`) + } +}) +``` + +### Challenge 1 + +Modify the line of code with `math->random` so that only number 1-4 can appear on the die. + +``` +input.onGesture(Gesture.Shake, () => { + let roll1 = Math.random(4) // *** + if (roll1 == 5) { + basic.plotImage(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`) + } else if (roll1 == 4) { + basic.plotImage(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`) + } + else if (roll1 == 3) { + basic.plotImage(` +. . . . . +. # . # . +. . . . . +. # . # . +. . . . . +`) + } + else if (roll1 == 2) { + basic.plotImage(` +# . . . . +. . . . . +. . # . . +. . . . . +. . . . # +`) + } + else if (roll1 == 1) { + basic.plotImage(` +. . . . . +. # . . . +. . . . . +. . . # . +. . . . . +`) + } + else { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. . . . . +. . . . . +`) + } +}) +``` + +### Challenge 2 + +Let's make a trick die! Modify the line of code with `math->random` so that only numbers 3-6 can appear on the die. Also note that we need to ensure `roll = 0` when only 1 dot is shown on the BBC micro:bit. + +``` +input.onGesture(Gesture.Shake, () => { + let roll2 = Math.random(4) + 2 // *** + if (roll2 == 5) { + basic.plotImage(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`) + } else if (roll2 == 4) { + basic.plotImage(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`) + } + else if (roll2 == 3) { + basic.plotImage(` +. . . . . +. # . # . +. . . . . +. # . # . +. . . . . +`) + } + else if (roll2 == 2) { + basic.plotImage(` +# . . . . +. . . . . +. . # . . +. . . . . +. . . . # +`) + } + else if (roll2 == 1) { + basic.plotImage(` +. . . . . +. # . . . +. . . . . +. . . # . +. . . . . +`) + } + else if (roll2 == 0) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. . . . . +. . . . . +`) + } +}) +``` + +### Challenge 3 + +Add a couple more conditions so that the BBC micro:bit randomly chooses a number between 1 and 8. + diff --git a/docs/reference/js/lessons/die-roll/quiz-answers.md b/docs/reference/js/lessons/die-roll/quiz-answers.md new file mode 100644 index 00000000..c13aac55 --- /dev/null +++ b/docs/reference/js/lessons/die-roll/quiz-answers.md @@ -0,0 +1,116 @@ +# die roll quiz answers + +Create a die when the BBC micro:bit is shaken + +These are the answers to the [die roll quiz](/microbit/lessons/die-roll/quiz). + +## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5. + +
+ +``` +let roll = Math.random(6) +``` + +## 2. If the variable "roll" equals 5, write the code that will plot the image below + +![](/static/mb/lessons/die-roll-0.png) + +
+ +``` +if (roll == 5) { + basic.plotImage(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`) +} +``` + +## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below + +![](/static/mb/lessons/die-roll-1.png) + +
+ +``` +if (roll == 5) { + basic.plotImage(` +. # . # . +. . . . . +. # . # . +. . . . . +. # . # . +`) +} else if (roll == 4) { + basic.plotImage(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`) +} +``` + +Note: students are only required to write the bottom half of this answer, starting with "else if". + +## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below + +![](/static/mb/lessons/die-roll-2.png) + +
+ +``` +if (roll == 4) { + basic.plotImage(` +. . . . . +. # . # . +. . # . . +. # . # . +. . . . . +`) +} else if (roll == 3) { + basic.plotImage(` +. . . . . +. # . # . +. . . . . +. # . # . +. . . . . +`) +} +``` + +Note: students are only required to write the bottom half of this answer, starting with "else if". + +## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below + +![](/static/mb/lessons/die-roll-3.png) + +
+ +``` +if (roll == 3) { + basic.plotImage(` +. . . . . +. # . # . +. . . . . +. # . # . +. . . . . +`) +} else if (roll == 2) { + basic.plotImage(` +# . . . . +. . . . . +. . # . . +. . . . . +. . . . # +`) +} +``` + +Note: students are only required to write the bottom half of this answer, starting with "else if". + diff --git a/docs/reference/js/lessons/die-roll/quiz.md b/docs/reference/js/lessons/die-roll/quiz.md new file mode 100644 index 00000000..2592c6a2 --- /dev/null +++ b/docs/reference/js/lessons/die-roll/quiz.md @@ -0,0 +1,42 @@ +# die roll quiz + +Create a die when the BBC micro:bit is shaken + +## Name + +## Directions + +Use this activity document to guide your work in the [die roll tutorial](/microbit/lessons/die-roll/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5. + +
+ +## 2. If the variable "roll" equals 5, write the code that will plot the image below + +![](/static/mb/lessons/die-roll-0.png) + +
+ +## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below + +![](/static/mb/lessons/die-roll-1.png) + +
+ +
+ +## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below + +![](/static/mb/lessons/die-roll-2.png) + +
+ +## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below + +![](/static/mb/lessons/die-roll-3.png) + +
+ diff --git a/docs/reference/js/lessons/digi-yoyo.md b/docs/reference/js/lessons/digi-yoyo.md new file mode 100644 index 00000000..defe623a --- /dev/null +++ b/docs/reference/js/lessons/digi-yoyo.md @@ -0,0 +1,91 @@ +# digi yoyo lesson + +create a counter with a while loop #while #loop #counter #docs + +### @video td/videos/digi-yoyo-0 + +## Topic + +While Loop + +## Quick Links + +* [tutorial](/microbit/lessons/digi-yoyo/tutorial) +* [quiz](/microbit/lessons/digi-yoyo/quiz) +* [quiz answers](/microbit/lessons/digi-yoyo/quiz-answers) +* [challenges](/microbit/lessons/digi-yoyo/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to creating a **while loop**, `while condition do` to repeat code while a condition is true. We will be learning how to create a digi yoyo app using a while loop, a variable, as well as basic commands, such as pause and show number. + +## Documentation + +* **local variables** : [read more...](/microbit/reference/variables/var) +* **assignment operator** : [read more...](/microbit/reference/variables/assign) +* **while loop** : [read more...](/microbit/js/while) +* **relational operator ** : [read more...](/microbit/reference/types/number) +* **pause** : [read more...](/microbit/reference/basic/pause) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Objectives + +* learn how to create a local variables to store data and use it in your code +* learn how to set or change the value of a local variable +* learn how to repeat code while a condition is true +* learn how a relational comparison (<) of numbers will yield a Boolean +* learn how to pause your code for the specified number of milliseconds +* learn how to show a number on the LED screen + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses diagrams to express solutions.(AB) +* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL) +* Recognises that different algorithms exist for the same problem (AL) (GE) +* Represents solutions using a structured notation (AL) (AB) +* Can identify similarities and differences in situations and can use these to solve problems (pattern recognition)(GE) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Uses filters or can perform single criteria searches for information.(AL) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/digi-yoyo/tutorial) +* [quiz](/microbit/lessons/digi-yoyo/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/digi-yoyo/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/digi-yoyo/challenges) + diff --git a/docs/reference/js/lessons/digi-yoyo/challenges.md b/docs/reference/js/lessons/digi-yoyo/challenges.md new file mode 100644 index 00000000..1c383c67 --- /dev/null +++ b/docs/reference/js/lessons/digi-yoyo/challenges.md @@ -0,0 +1,65 @@ +# digi yoyo challenges + +Coding challenges for the digi yoyo. + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/digi-yoyo/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +let count = 0 +while (count < 10) { + basic.pause(1000) + basic.showNumber(count, 150) + count = count + 1 +} +``` + +### Challenge 1 + +How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0. + +``` +let count1 = 0 +while (count1 < 10) { + basic.pause(1000) + basic.showNumber(count1, 150) + count1 = count1 + 1 +} +while (count1 > 0) { +} +``` + +### Challenge 2 + +### @video td/videos/digi-yoyo-1-2 + +Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`! + +``` +let count2 = 0 +while (count2 < 10) { + basic.pause(1000) + basic.showNumber(count2, 150) + count2 = count2 + 1 +} +while (count2 > 0) { + basic.pause(1000) // *** + basic.showNumber(count2, 150) // *** +} +``` + +* Run the code to see if it works as expected. + +### Challenge 3 + +Now, we need `count` to decrease by one after the BBC micro:bit has displayed the value of `count`. + +We can do this by adding this line: + +`count := count - 1` + diff --git a/docs/reference/js/lessons/digi-yoyo/quiz-answers.md b/docs/reference/js/lessons/digi-yoyo/quiz-answers.md new file mode 100644 index 00000000..7df40bf9 --- /dev/null +++ b/docs/reference/js/lessons/digi-yoyo/quiz-answers.md @@ -0,0 +1,34 @@ +# digi yoyo quiz answers + +Answers for digi yoyo quiz. + +This is the answer key for the [digi yoyo quiz](/microbit/lessons/digi-yoyo/quiz). + +## 1. Describe what a "while loop" does? + +
+ +A loop that repeats code while a condition is true. + +## 2. Write the code that will create a **variable** called `count` and set the variable to 0. + +![](/static/mb/lessons/counter-0.png) + +
+ +``` +let count = 0 +``` + +## 3. Create a `while loop` that will loop until the **variable** `count` equals 4. + +![](/static/mb/lessons/digi-yoyo-0.png) + +
+ +``` +while (count < 5) { + count = count + 1 +} +``` + diff --git a/docs/reference/js/lessons/digi-yoyo/quiz.md b/docs/reference/js/lessons/digi-yoyo/quiz.md new file mode 100644 index 00000000..de9aecf2 --- /dev/null +++ b/docs/reference/js/lessons/digi-yoyo/quiz.md @@ -0,0 +1,28 @@ +# digi yoyo quiz + +Create a counter with a while loop + +## Name + +## Directions + +Use this activity document to guide your work in the [digi yoyo tutorial](/microbit/lessons/digi-yoyo/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what a "while loop" does? + +
+ +## 2. Write the code that will create a variable called count and set the variable to 0. + +![](/static/mb/lessons/counter-0.png) + +
+ +## 3. Write the code for a while loop that will loop until the variable count equals 4. + +![](/static/mb/lessons/digi-yoyo-0.png) + +
+ diff --git a/docs/reference/js/lessons/digital-pet.md b/docs/reference/js/lessons/digital-pet.md new file mode 100644 index 00000000..45024580 --- /dev/null +++ b/docs/reference/js/lessons/digital-pet.md @@ -0,0 +1,133 @@ +# digital pet lesson + +a display of pet images for the BBC micro:bit #functions #number #forever #button #string #pause #data #shake #docs + +### @video td/videos/digital-pet-0 + +## Topic + +Functions + +## Quick Links + +* [tutorial](/microbit/lessons/digital-pet/tutorial) +* [quiz](/microbit/lessons/digital-pet/quiz) +* [quiz answers](/microbit/lessons/digital-pet/quiz-answers) +* [challenges](/microbit/lessons/digital-pet/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a digital pet app using functions, global variables, forever loop, input button in pressed, input on shake as well as simple commands, such as show string, show number, and pause. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Hardware: The physical systems and components of digital devices; see also software. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **function** : [read more...](/microbit/js/function) +* **call** : [read more...](/microbit/js/call) +* **global variable** : [read more...](/microbit/js/data) +* **assignment operator** : [read more...](/microbit/reference/variables/assign) +* **forever** : [read more...](/microbit/reference/basic/forever) +* **button is pressed** : [read more...](/microbit/reference/input/button-is-pressed) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **create image** : [read more...](/microbit/reference/images/create-image) +* **show image** : [read more...](/microbit/reference/images/show-image) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Resources + +* Activity: [tutorial](/microbit/lessons/digital-pet/tutorial) +* Activity: [quiz](/microbit/lessons/digital-pet/quiz) +* Extended Activity: [challenges](/microbit/lessons/digital-pet/challenges) + +## Objectives + +* learn how to create a function as a unit of code that performs a specific task and returns a result +* learn how to call an existing function in your script +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how to set or change the value of a global variable +* learn how to repeat code in the background forever +* learn how to get the state of an input button +* learn how to show a number on the micro:bit's LED screen +* learn how to show a string on the micro:bit's LED screen +* learn how to create an image to show on the micro:bit's LED screen +* learn how to show an image on the micro:bit's LED screen +* learn how to pause your code for the specified number of milliseconds + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Defines data types: real numbers and Boolean (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/digital-pet/tutorial) +* [quiz](/microbit/lessons/digital-pet/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/digital-pet/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/digital-pet/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/digital-pet/challenges.md b/docs/reference/js/lessons/digital-pet/challenges.md new file mode 100644 index 00000000..f63ae4df --- /dev/null +++ b/docs/reference/js/lessons/digital-pet/challenges.md @@ -0,0 +1,129 @@ +# digital pet challenges + +Coding challenges for the digital pet tutorial. + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/digital-pet/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.forever(() => { + if (input.buttonIsPressed("A")) { + setSleep() + basic.pause(5000) + } else { + setAwake() + } +}) +``` + +### Challenge 1 + +Now let's feed the pet! Add an **ELSE IF** statement that checks if button `B` is pressed. Click on the **ELSE** and type **IF** next to it to get the **ELSE IF**. + +``` +basic.forever(() => { + if (input.buttonIsPressed("A")) { + setSleep() + basic.pause(5000) + } else if (input.buttonIsPressed("B")) { + + } + else { + setAwake() + } +}) +``` + +### Challenge 2 + +### @video td/videos/digital-pet-2 + +Now we want to show your eating pet! Let's create a function called `set eat` that will do create an image. Store that image in a variable and then show it. + +``` +export function setEat() { + let img = images.createImage(` +. # . # . +. . # . . +. . # . . +. # . # . +. . # . . +`) + img.showImage(0) +} +``` + +Once you create the function `set eat`, call it in the **ELSE IF** statement that checks if button `B` is pressed. + +``` +basic.forever(() => { + if (input.buttonIsPressed("A")) { + setSleep() + basic.pause(5000) + } else if (input.buttonIsPressed("B")) { + setEat() + } + else { + setAwake() + } +}) +``` + +### Challenge 3 + +### @video td/videos/digital-pet-3 + +Have your pet tell you when it is going to sleep! Do this inside of the **IF** statement that checks if button `A` is pressed before you call the function `set sleep`. + +``` +basic.forever(() => { + if (input.buttonIsPressed("A")) { + basic.showString("I am going to sleep.", 150) // *** + setSleep() + basic.pause(5000) + } else if (input.buttonIsPressed("B")) { + setEat() + } + else { + setAwake() + } +}) +``` + +### Challenge 4 + +### @video td/videos/digital-pet-4 + +Now, how about we keep track of how many times our pet eats? Add a global variable called `feed` that keeps track of how many times you feed your pet. If button `B` is pressed, increment `feed` by one. Add a condition `on shake` to check your total. + +``` +feed = 0 // *** +basic.forever(() => { + if (input.buttonIsPressed("A")) { + basic.showString("I am going to sleep.", 150) + setSleep() + basic.pause(5000) + } else if (input.buttonIsPressed("B")) { + feed = feed + 1 // *** + setEat() + } + else { + setAwake() + } +}) +input.onGesture(Gesture.Shake, () => { + basic.showNumber(feed, 150) // *** +}) // *** +``` + +### Challenge 5 + +Program your pet to say that it is hungry after 60 seconds. + +**Hint**: use `input->running time` + diff --git a/docs/reference/js/lessons/digital-pet/quiz-answers.md b/docs/reference/js/lessons/digital-pet/quiz-answers.md new file mode 100644 index 00000000..02d0b87a --- /dev/null +++ b/docs/reference/js/lessons/digital-pet/quiz-answers.md @@ -0,0 +1,60 @@ +# digital pet quiz answers + +A display of pet images for the BBC micro:bit + +## Name + +## Directions + +Use this activity document to guide your work in the [digital pet tutorial](/microbit/lessons/digital-pet/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a 'function'? + +
+ +A function is a unit of code that performs a specific task and may return a result. + +## 2. Write the steps to create the function called set awake() + +
+ +Click on "+ add new" and then "function". Click on the function name (by default it is "set awake"), and rename it to "set awake()". + +## 3. Write the code inside the function "set awake()" that shows an image of the pet awake + +
+ +``` +let img = images.createImage(` +. # . # . +. . # . . +. . . . . +. # # # . +. . . . . +`) +img.showImage(0) +``` + +## 4. Write the steps to create the function called set sleep, function set sleep() + +
+ +Click on "+ add new" and then "function". Click on the function name (by default it is "set sleep"), and rename it to "set sleep()". + +## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep + +
+ +``` +img = images.createImage(` +# # . # # +. . # . . +. . . . . +. # # # . +. . . . . +`) +img.showImage(0) +``` + diff --git a/docs/reference/js/lessons/digital-pet/quiz.md b/docs/reference/js/lessons/digital-pet/quiz.md new file mode 100644 index 00000000..1f637101 --- /dev/null +++ b/docs/reference/js/lessons/digital-pet/quiz.md @@ -0,0 +1,32 @@ +# digital pet quiz + +A display of pet images for the BBC micro:bit + +## Name + +## Directions + +Use this activity document to guide your work in the [digital pet tutorial](/microbit/lessons/digital-pet/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a 'function'? + +
+ +## 2. Write the steps to create the function called set awake() + +
+ +## 3. Write the code inside the function "set awake()" that shows an image of the pet awake + +
+ +## 4. Write the steps to create the function called set sleep, function set sleep() + +
+ +## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep + +
+ diff --git a/docs/reference/js/lessons/flashing-heart.md b/docs/reference/js/lessons/flashing-heart.md new file mode 100644 index 00000000..ae270a25 --- /dev/null +++ b/docs/reference/js/lessons/flashing-heart.md @@ -0,0 +1,93 @@ +# flashing heart lesson + +Learn how to create LED images with a global variable. #LED #screen #plot #docs + +### @video td/videos/flashing-heart-0 + +## Topic + +Pause + +## Quick links + +* [activity](/microbit/lessons/flashing-heart/activity) +* [quiz](/microbit/lessons/flashing-heart/quiz) +* [quiz answers](/microbit/lessons/flashing-heart/quiz-answers) +* [challenges](/microbit/lessons/flashing-heart/challenges) +* [tutorial](/microbit/lessons/flashing-heart/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to **plot image** by turning on a series of LED lights on the LED screen. We will be learning how to create a blinking app using a forever loop as well as simple commands, such as plot image, pause, and clear screen. + +## What the teacher needs to know / QuickStart Computing Glossary + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +## Documentation + +* **forever**: [read more...](/microbit/reference/basic/forever) +* **plot image** : [read more...](/microbit/reference/led/plot-image) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **clear screen**: [read more...](/microbit/reference/basic/clear-screen) + +## Objectives + +* learn how to repeat code in the background forever +* learn how to turn on a series of LED lights on the LED screen +* learn how to pause your code for the specified number of milliseconds +* learn how to turn off all the LED lights on the LED screen + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Exercise + +* time: 20 min. +* [activity](/microbit/lessons/flashing-heart/activity) or [tutorial](/microbit/lessons/flashing-heart/tutorial) +* [quiz](/microbit/lessons/flashing-heart/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/flashing-heart/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/flashing-heart/activity.md b/docs/reference/js/lessons/flashing-heart/activity.md new file mode 100644 index 00000000..f96e0d1f --- /dev/null +++ b/docs/reference/js/lessons/flashing-heart/activity.md @@ -0,0 +1,63 @@ +# flashing heart activity + +Ccontrol images with variables. + +### ~avatar avatar + +### @video td/videos/flashing-heart-0 + +In this activity, you will learn how to blink an image on the LED screen. + +### ~ + +To create a new script, go to the [Create Code](https://www.microbit.co.uk/create-code) page and tap `New Project` under **KindScript**. + +Let's start by adding code that plots a heart image on the screen using `basic->plot image`. Once you are done coding, don't forget to run your code in the simulator or the BBC micro:bit. + +``` +basic.plotImage(` +. # . # . +# # # # # +# # # # # +. # # # . +. . # . . +`) // *** +``` + +We want to leave the image on the screen for 0.5 seconds (500 milliseconds), then clear the screen. We can use `basic->pause` to wait and `basic->clear screen` to turn off the LEDs. + +``` +basic.plotImage(` +. # . # . +# # # # # +# # # # # +. # # # . +. . # . . +`) +basic.pause(500) // *** +basic.clearScreen() // *** +``` + +Finally, we can surround this code with a `basic->forever` loop to repeat it and add a pause after `basic->clear screen` to keep the screen off for a little while. Modify your code so that your code looks like this. + +``` +basic.forever(() => { + basic.plotImage(` +. # . # . +# # # # # +# # # # # +. # # # . +. . # . . +`) + basic.pause(500) + basic.clearScreen() + basic.pause(500) +}) +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/flashing-heart/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/flashing-heart/challenges.md b/docs/reference/js/lessons/flashing-heart/challenges.md new file mode 100644 index 00000000..640cf368 --- /dev/null +++ b/docs/reference/js/lessons/flashing-heart/challenges.md @@ -0,0 +1,93 @@ +# flashing heart challenges + +Coding challenges for flashing heart. + +## Before we get started + +Complete the [flashing heart](/microbit/lessons/flashing-heart/activity) activity and your code will look like this: + +``` +basic.forever(() => { + basic.plotImage(` +. # . # . +# # # # # +# # # # # +. # # # . +. . # . . +`) + basic.pause(500) + basic.clearScreen() + basic.pause(500) +}) +``` + +### Challenge 1 + +### @video td/videos/flashing-heart-1 + +Let's plot a different image. Let's display a broken heart! + +To do this, you need to **add a line** between the last line and the end loop. Plot the image of the broken heart and then add a pause of 500 milliseconds. + +``` +basic.forever(() => { + basic.plotImage(` +# # . # # +# # # # # +# # # # # +. # # # . +. . # . . +`) + basic.pause(500) + basic.clearScreen() + basic.pause(500) + basic.plotImage(` +. # . # . +# . # # # +# . . # # +. # # # . +. . # . . +`) // *** + basic.pause(500) // *** +}) +``` + +* click `run main` to see if the code works as expected. + +### Challenge 2 + +### @video td/videos/flashing-heart-2 + +Now let's alternate flashing the heart and the broken heart. To do this, we need to clear the screen and then add a pause of 500 milliseconds under the new code we added in Challenge 1. + +``` +basic.forever(() => { + basic.plotImage(` +# # . # # +# # # # # +# # # # # +. # # # . +. . # . . +`) + basic.pause(500) + basic.clearScreen() + basic.pause(500) + basic.plotImage(` +. # . # . +# . # # # +# . . # # +. # # # . +. . # . . +`) + basic.pause(500) + basic.clearScreen() // *** + basic.pause(500) // *** +}) +``` + +* click `run main` to see if the code works as expected. + +### Challenge 3 + +You now have a heart and broken heart flashing! Now plot a new image to alternate in with the heart and broken heart. + diff --git a/docs/reference/js/lessons/flashing-heart/lesson-plan.md b/docs/reference/js/lessons/flashing-heart/lesson-plan.md new file mode 100644 index 00000000..d260a094 --- /dev/null +++ b/docs/reference/js/lessons/flashing-heart/lesson-plan.md @@ -0,0 +1,102 @@ +# flashing heart lesson plan + +Learn how to create LED images with a variable. + +### @video vimeo/134118661 + +## Topic + +Global Variable - Blinking Images + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to control a blinking LED image. We will be learning how to create a blinking app using global variables, forever as well as simple commands, such as create image, show image, pause, and clear screen. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **global variables**: [read more...](/microbit/js/data) +* **create image** : [read more...](/microbit/reference/images/create-image) +* **show image** : [read more...](/microbit/reference/images/show-image) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **clear screen**: [read more...](/microbit/reference/basic/clear-screen) +* **forever**: [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [tutorial](/microbit/lessons/flashing-heart/tutorial) +* Activity: [quiz](/microbit/lessons/flashing-heart/quiz) +* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges) + +## Objectives + +* learn how to create a global variable +* learn how to blink a light +* learn how to repeat turning on and off the light + +## Links to the National Curriculum Programmes of Study for Computing + +## Assessment + +### Progression Pathways + +### Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/flashing-heart/tutorial) +* [quiz](/microbit/lessons/flashing-heart/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/flashing-heart/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/flashing-heart/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/flashing-heart/quiz-answers.md b/docs/reference/js/lessons/flashing-heart/quiz-answers.md new file mode 100644 index 00000000..2111d41a --- /dev/null +++ b/docs/reference/js/lessons/flashing-heart/quiz-answers.md @@ -0,0 +1,38 @@ +# flashing heart quiz answers + +Learn how to create images with global variables. + +This is the answer key for the [flashing heart quiz](/microbit/lessons/flashing-heart/quiz). + +## 1. Describe what `basic->show leds` does + +Show LEDs displays an Image on the BBC micro:bit's LED screen + +## 2. Draw the areas being displayed on the BBC micro:bit + +``` +basic.showLeds(` +# # . # # +# # # # # +# # # # # +. # # # . +. . # . . +`, 400) +``` + +![](/static/mb/lessons/flashing-heart-0.png) + +## 3. Write the code to show LEDs of a broken heart forever. + +``` +basic.forever(() => { + basic.showLeds(` +# # . # # +# . # # # +# # . # # +. # . # . +. . # . . +`, 400) +}) +``` + diff --git a/docs/reference/js/lessons/flashing-heart/quiz.md b/docs/reference/js/lessons/flashing-heart/quiz.md new file mode 100644 index 00000000..5332c411 --- /dev/null +++ b/docs/reference/js/lessons/flashing-heart/quiz.md @@ -0,0 +1,36 @@ +# flashing heart quiz + +Learn how to create a blinking LED script 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? + +
+ +## 2. Draw the image being displayed using the BBC micro:bit image. + +``` +basic.showLeds(` +. # . # . +# # # # # +# # # # # +. # # # . +. . # . . +`, 400) +``` + +![](/static/mb/empty-microbit.png) + +
+ +## 3. Write the code to show LEDs of a broken heart forever. + +
+ diff --git a/docs/reference/js/lessons/flipping-bird.md b/docs/reference/js/lessons/flipping-bird.md new file mode 100644 index 00000000..48876dd3 --- /dev/null +++ b/docs/reference/js/lessons/flipping-bird.md @@ -0,0 +1,124 @@ +# flipping bird lesson + +count the number of times the BBC micro:bit has been shaken #var #shake #mod #math #plot #docs + +### @video td/videos/flipping-bird-0 + +## Topic + +Math - Modulo + +## Quick Links + +* [tutorial](/microbit/lessons/flipping-bird/tutorial) +* [quiz](/microbit/lessons/flipping-bird/quiz) +* [quiz answers](/microbit/lessons/flipping-bird/quiz-answers) +* [challenges](/microbit/lessons/flipping-bird/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to return the **modulus**, `math->mod` to determine if you will plot image. We will be learning how to return the modulus by using a local variable, input on shake, if (conditional), modulo, as well as simple commands such as plot image. + +## 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. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Repetition: Executing a section of computer code a number of times as part of the 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. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +## Documentation + +* **global variables** : [read more...](/microbit/js/data) +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **if** : [read more...](/microbit/reference/logic/if) +* **math modulo** : [read more...](/microbit/js/math) +* **plot image** : [read more...](/microbit/reference/led/plot-image) + +## Resources + +* Activity: [tutorial](/microbit/lessons/flipping-bird/tutorial) +* Activity: [quiz](/microbit/lessons/flipping-bird/quiz) +* Extended Activity: [challenges](/microbit/lessons/flipping-bird/challenges) + +## Objectives + +* learn how to create a local variable as a place where you can store data, so that you can use it in your code, across functions, and in nested code blocks +* learn how to run code when the micro:bit is shaken; when running code in the browser, moving the mouse quickly simulates shaking +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to return the modulus +* learn how to display an image on the BBC micro:bit's LED screen + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Shows an awareness of tasks best completed by humans or computers (EV) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (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 post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* 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) + +#### 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) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/flipping-bird/tutorial) +* [quiz](/microbit/lessons/flipping-bird/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/flipping-bird/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/flipping-bird/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/flipping-bird/challenges.md b/docs/reference/js/lessons/flipping-bird/challenges.md new file mode 100644 index 00000000..d989aafe --- /dev/null +++ b/docs/reference/js/lessons/flipping-bird/challenges.md @@ -0,0 +1,87 @@ +# flipping bird challenges + +Coding challenges for flipping bird. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/flipping-bird/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +counter = 0 +input.onGesture(Gesture.Shake, () => { + counter = counter + 1 + if (math.mod(counter, 2) == 1) { + basic.plotImage(` +# # . # # +. . # . . +. . . . . +. . . . . +. . . . . +`) + } +}) +``` + +### Challenge 1 + +We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case. + +``` +counter = 0 +input.onGesture(Gesture.Shake, () => { + counter = counter + 1 + if (math.mod(counter, 2) == 1) { + basic.plotImage(` +# # . # # +. . # . . +. . . . . +. . . . . +. . . . . +`) + } + if (math.mod(counter, 2) == 0) { + } +}) +``` + +### Challenge 2 + +### @video td/videos/flipping-bird-2 + +Inside of that `if` statement you created in challenge 1, add `basic->plot image()` and display an upside down flying bird. + +``` +counter = 0 +input.onGesture(Gesture.Shake, () => { + counter = counter + 1 + if (math.mod(counter, 2) == 1) { + basic.plotImage(` +# # . # # +. . # . . +. . . . . +. . . . . +. . . . . +`) + } + if (math.mod(counter, 2) == 0) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . # . . +# # . # # +`) // *** + } +}) +``` + +* `Run` the code to see if it works as expected. + +**Challenge 3** + +Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display! + diff --git a/docs/reference/js/lessons/flipping-bird/quiz-answers.md b/docs/reference/js/lessons/flipping-bird/quiz-answers.md new file mode 100644 index 00000000..948384ac --- /dev/null +++ b/docs/reference/js/lessons/flipping-bird/quiz-answers.md @@ -0,0 +1,50 @@ +# flipping bird quiz answers + +use modulo with a conditional #mod #shake #variables #docs #input #mod + +This is the answer key for the [flipping bird quiz](/microbit/lessons/flipping-bird/quiz). + +## 1. What does "modulo" mean in math? + +
+ +Modulo (or Mod) is the remainder of a division problem. + +## 2. Consider the following code + +If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded. + +``` +count = 1 +count_ = count_ + 2 +``` + +
+ +
+ +![](/static/mb/lessons/flipping-bird-0.png) + +The variable `count` is now equal to 3. + +
+ +## 3. Consider the following directions + +Modulo (Mod) tells us what the remainder of a division is. For example, `15 mod 4 is 3` since 15 divided by 4 has a remainder of 3. + +``` +count = 12 +count = math.mod(count, 5) +``` + +If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded. + +
+ +
+ +![](/static/mb/lessons/flipping-bird-1.png) + +The display will show `2` because the remainder of 12 divided by 5 is 2. + diff --git a/docs/reference/js/lessons/flipping-bird/quiz.md b/docs/reference/js/lessons/flipping-bird/quiz.md new file mode 100644 index 00000000..960ef23c --- /dev/null +++ b/docs/reference/js/lessons/flipping-bird/quiz.md @@ -0,0 +1,60 @@ +# flipping bird quiz + +use modulo with a conditional #mod #shake #variables #docs #input #mod + +## Name + +## Directions + +Use this activity document to guide your work in the [flipping bird tutorial](/microbit/lessons/flipping-bird/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What does "modulo" mean in math? + +## 2. Consider the following directions + +If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. + +``` +count = 1 +``` + +![](/static/mb/empty-microbit.png) + +
+ +
+ +## 3. Consider the following code + +If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded. + +``` +count = 1 +count_ = count_ + 2 +``` + +![](/static/mb/empty-microbit.png) + +
+ +
+ +## 4. Consider the following directions + +Modulo (Mod) tells us what the remainder of a division is. For example, `15 mod 4 is 3` since 15 divided by 4 has a remainder of 3. + +``` +count = 12 +count = math.mod(count, 5) +``` + +If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded. + +![](/static/mb/empty-microbit.png) + +
+ +
+ diff --git a/docs/reference/js/lessons/foo.md b/docs/reference/js/lessons/foo.md new file mode 100644 index 00000000..9b9f830d --- /dev/null +++ b/docs/reference/js/lessons/foo.md @@ -0,0 +1,191 @@ +# foo + +blank lesson #docs + +### ~screen TODO + +### @video vimeo/134121040 + +### ~ + +## Topic TODO: + +Basic - Show Number + +## Quick Links TODO: + +* [tutorial](/microbit/lessons/lucky-7/tutorial) +* [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 TODO: + +Learn how to creating a **global number variable**, `data->count` to keep track of the current count. We will be learning how to create a counter app using global variables as well as simple commands, such as on button pressed, and show number. + +## What the teacher needs to know TODO: + +* Acceptable Use Policy (AUP): An Acceptable Use Policy comprises a set of rules applied by the owner/manager of a network, website or large computer system that defines the ways in which the network, site or system may be used. +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Computational thinking: Thinking about systems or problems in a way that allows computer systems to be used to model or solve these. +* Computer networks: The computers and the connecting hardware (wifi access points, cables, fibres, switches and routers) that make it possible to transfer data using an agreed method (‘protocol’). +* Creative Commons: A licensing scheme where the creator of an original work allows others to use it without seeking further permission, subject to a number of agreed conditions: www. creativecommons.org. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Debug: To fix the errors in a program. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Domain Name Service (DNS): The distributed automatic system that converts domain names into the IP addresses which are used for routing packets via the internet. +* Encrypt: To securely encode information so that it can only be read by those knowing both the system used and a secret, private key. +* E-safety: Used to describe behaviours and policies intended to minimise the risks to a user of using digital technology, particularly the internet. +* Generalisation: A computational thinking process in which general solutions or models are preferred to or derived from particular cases. +* Hardware: The physical systems and components of digital devices; see also software. +* Hypertext mark-up language (HTML): HTML is the language in which web pages are composed. +* Hypertext transfer protocol (HTTP): HTTP is the standard protocol for the request and transmission of HTML web pages between browser and web server. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Interface: The boundary between one system and another – often used to describe how a person interacts with a computer. +* Internet Protocol (IP) addresses: Numeric addresses uniquely specifying computers directly connected to the internet, also used on private networks to uniquely identify computers on that network. +* Loop: A block of code repeated automatically under the program’s control. +* Network server: A computer connected to a local area network providing services – such as file storage, printing, authentication, web access or email – automatically to other computers on the network. +* Open source software: Software in which the source code is made available for others to study, and typically adapt, usually with few if any restrictions. +* Operating system: The programs on a computer which deal with internal management of memory, input/output, security and so on, such as Windows 8 or iOS. +* 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. +* Packets of data: A small set of numbers that get transmitted together via the internet, typically enough for 1000 or 1500 characters. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Repetition: Executing a section of computer code a number of times as part of the program. +* Router: Network hardware which forwards packets of data onwards to the most appropriate hardware to which it is connected. +* Screencast: A recording of on-screen action that is often accompanied by an audio narration. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Sprite: A computer graphics object that can be controlled (programmed) independently of other objects or the background. +* Uniform Resource Locator (URL): A standard for specifying the location on the internet of certain files. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. +* Web server: A service running on a computer (or sometimes for the computer itself) that returns HTML data for a web page when it receives an HTTP request via the local network or the internet. +* World Wide Web: A service provided by computers connected to the internet (web servers), in which pages of hypertext (web pages) are transmitted to users. + +**QuickStart Computing Glossary + +## Documentation TODO: + +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Resources TODO: + +* Activity: [tutorial](/microbit/lessons/lucky-7/tutorial) +* Activity: [quiz](/microbit/lessons/lucky-7/quiz) +* Extended Activity: [challenges](/microbit/lessons/lucky-7/challenges) + +## Objectives TODO: + +* learn how to create a global variable +* learn how to blink a light +* learn how to repeat turning on and off the light + +## Links to the National Curriculum Programmes of Study for Computing TODO: + +## Progression Pathways / Computational Thinking Framework TODO: + +#### 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) +* Shows an awareness of tasks best completed by humans or computers (EV) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (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 post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Designs, writes and debugs modular programs using procedures(AL) (DE) (AB) (GE) +* Knows that a procedure can be used to hide the detail with sub-solution(AL) (DE) (AB) (GE) +* Understands that programming bridges the gap between algorithmic solutions and computers(AB) +* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Knows why sorting data in a flat file can improve searching for information (EV) +* 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) +* Analyses and evaluates data and information, and recognises that poor quality data leads to unreliable re sults,and inaccurate conclusions (AL) (EV) +* Knows that digital computers use binary to represent all data (AB) +* Understands how bit patterns represent numbers and images (AB) +* Knows that computers transfer data in binary (AB) +* Understands the relationship between binary and file size (uncompressed) (AB) +* Defines data types: real numbers and Boolean (AB) +* Queries data on one table using a typical query language (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) +* Understands the difference between hardware and application software, and their roles within a computer system (AB) +* Understands why and when computers are used (EV) +* Understands the main functions of the operating system (DE) (AB) +* Knows the difference between physical, wireless and mobile networks (AB) +* Recognises and understands the function of the main internal parts of basic computer architecture (AB) +* Understands the concepts behind the fetch-execute cycle (AB) (AL) +* Knows that there is a range of operating systems and application software for the same hardware (AB) + +#### Communication Networks + +* Understands the difference between the internet and internet service e.g. world wide web (AB) +* Shows an awareness of, and can use a range of internet services e.g. VOIP. +* Understands why and when computers are used (EV) +* Selects, combines and uses internet services (EV) +* 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) +* Understands how to construct static web pages using HTML and CSS (AL) (AB) +* Understands data transmission between digital computers over networks, including the internet i.e. IP addresses and packet switching. (AL) (AB) + +#### Information Technology + +Collects, organizes, and presents data and information in digital content (AB) + +* Creates digital content to achieve a given goal through combining software packages and internet services to communicate with a wider audience e.g. blogging (AL) +* 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 the audience when designing and creating digital content (EV) +* Understands the potential of information technology for collaboration when computers are networked (GE) +* 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. +* Designs criteria to critically evaluate the quality of solutions, uses the criteria to identify improvements and can make appropriate refinements to the solution (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity TODO: + +* time: 20 min. +* [tutorial](/microbit/lessons/lucky-7/tutorial) +* [quiz](/microbit/lessons/lucky-7/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity TODO: + +* time: 20 min. +* [challenges](/microbit/lessons/lucky-7/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework TODO: + +* Extended Activity: [challenges](/microbit/lessons/lucky-7/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/for-loop/challenges.md b/docs/reference/js/lessons/for-loop/challenges.md new file mode 100644 index 00000000..aad3db23 --- /dev/null +++ b/docs/reference/js/lessons/for-loop/challenges.md @@ -0,0 +1,41 @@ +# looper challenges + +These challenges will allow you to create a counter from 0-5 and then from 5-0. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](/microbit/bcvgkf) will assist you with the following activity: + +``` +for (let i = 0; i < 6; i++) { + led.showNumber(i, 150) + basic.pause(2000) +} +``` + +### Challenge 1 + +Go through the loop faster by changing the length of the pause. This is the line you will be editing: `basic->pause(2000)` + +``` +for (let i1 = 0; i1 < 6; i1++) { + basic.showNumber(i1, 150) + basic.pause(500) // *** +} +``` + +### Challenge 2 + +Now, let's count down from 5 instead of counting up to 5. Change the line `basic->show number(i, 150)` to `basic->show number(5 - i, 150)`. + +``` +for (let i2 = 0; i2 < 6; i2++) { + basic.showNumber(5 - i2, 150) // *** + basic.pause(2000) +} +``` + +### Challenge 3 + +Have the number count up in 2's from zero. It should go: 0, 2, 4, 6, 8, 10. + diff --git a/docs/reference/js/lessons/glowing-image/challenges.md b/docs/reference/js/lessons/glowing-image/challenges.md new file mode 100644 index 00000000..fb62fd4d --- /dev/null +++ b/docs/reference/js/lessons/glowing-image/challenges.md @@ -0,0 +1,56 @@ +# glowing mountain challenges + +These challenges will help you display a glowing image that fades in and out at different speeds. #docs + +**Challenge 0** + +[This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out. + +``` +images.createImage(` +. . . . . +. . # . . +. # # # . +# # # # # +# # # # # +`).showImage(0) +led.fadeOut(700) +``` + +**Challenge 1** + +Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond delay after the fade out. + +``` +images.createImage(` +. . . . . +. . # . . +. # # # . +# # # # # +# # # # # +`).showImage(0) +led.fadeOut(700) +basic.pause(1000) // *** +``` + +**Challenge 2** + +After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect. + +``` +images.createImage(` +. . . . . +. . # . . +. # # # . +# # # # # +# # # # # +`).showImage(0) +led.fadeOut(700) +basic.pause(1000) +led.fadeIn(2000) // *** +``` + +**Challenge 3** + +Now add another `basic->pause(1000)` and `led->fade out(900)` so that the mountain can fade out again. + diff --git a/docs/reference/js/lessons/glowing-mountain/challenges.md b/docs/reference/js/lessons/glowing-mountain/challenges.md new file mode 100644 index 00000000..1d51e651 --- /dev/null +++ b/docs/reference/js/lessons/glowing-mountain/challenges.md @@ -0,0 +1,64 @@ +# glowing sword challenges + +These challenges will help you display a glowing image that fades in and out at different speeds. #docs + +**Challenge 0** + +### @video vimeo/134649269 + +[This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out. + +``` +images.createImage(` +. . . . # +# . . # . +# # # . . +. # # . . +# . # # . +`).showImage(0) +led.fadeOut(700) +``` + +**Challenge 1** + +Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond delay after the fade out. + +``` +images.createImage(` +. . . . # +# . . # . +# # # . . +. # # . . +# . # # . +`).showImage(0) +led.fadeOut(700) +basic.pause(1000) // *** +``` + +* Run the code to see if it works as expected. + +**Challenge 2** + +### @video vimeo/134674595 + +After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect. + +``` +images.createImage(` +. . . . # +# . . # . +# # # . . +. # # . . +# . # # . +`).showImage(0) +led.fadeOut(700) +basic.pause(1000) +led.fadeIn(2000) // *** +``` + +* Run the code to see if it works as expected. + +**Challenge 3** + +Now add another `basic->pause(1000)` and `led->fade out(900)` so that the mountain can fade out again. + diff --git a/docs/reference/js/lessons/glowing-pendulum.md b/docs/reference/js/lessons/glowing-pendulum.md new file mode 100644 index 00000000..244dad51 --- /dev/null +++ b/docs/reference/js/lessons/glowing-pendulum.md @@ -0,0 +1,90 @@ +# glowing pendulum 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) +* [quiz](/microbit/lessons/glowing-pendulum/quiz) +* [quiz answers](/microbit/lessons/glowing-pendulum/quiz-answers) +* [tutorial](/microbit/lessons/glowing-pendulum/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to get the acceleration **acceleration**, `input->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) +* **plot** : [read more...](/microbit/reference/led/set-brightness) + +## 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) +* [tutorial](/microbit/lessons/glowing-pendulum/tutorial) +* [quiz](/microbit/lessons/glowing-pendulum/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/glowing-pendulum/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/glowing-pendulum/challenges) + diff --git a/docs/reference/js/lessons/glowing-pendulum/activity.md b/docs/reference/js/lessons/glowing-pendulum/activity.md new file mode 100644 index 00000000..2aed3212 --- /dev/null +++ b/docs/reference/js/lessons/glowing-pendulum/activity.md @@ -0,0 +1,75 @@ +# glowing pendulum activity + +construct a pendulum that glows using acceleration. #docs + +### ~avatar avatar + +Welcome! This guided activity will teach how to construct a pendulum that glows using acceleration. Let's get started! + +### ~ + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**. + +Create a **forever** loop that will constantly display the appropriate brightness on the LED display. + +``` +basic.forever(() => { +}) +``` + +Now let's measure the acceleration on the `y` axis and store that value in a variable. The `input->acceleration("y")` function will provide the value. + +``` +basic.forever(() => { + let acceleration = input.acceleration("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. + +``` +basic.forever(() => { + let acceleration1 = input.acceleration("y") + acceleration1 = math.abs(acceleration1) +}) +``` + +The function `input->acceleration("y")` returns a number between 0 and 1024. We want to use this value for the brightness of the micro:bit, but the `led->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. + +``` +basic.forever(() => { + let acceleration2 = input.acceleration("y") + acceleration2 = math.abs(acceleration2) + acceleration2 = acceleration2 / 4 +}) +``` + +Now let's use our acceleration value to set the brightness on the BBC micro:bit. + +``` +basic.forever(() => { + let acceleration3 = input.acceleration("y") + acceleration3 = math.abs(acceleration3) + acceleration3 = acceleration3 / 4 + led.setBrightness(acceleration3) +}) +``` + +Let's show what the brightness of the micro:bit is by turning all the LEDs on! + +``` +basic.forever(() => { + let acceleration4 = input.acceleration("y") + acceleration4 = math.abs(acceleration4) + acceleration4 = acceleration4 / 4 + led.setBrightness(acceleration4) + led.plotAll() +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/glowing-pendulum/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/glowing-pendulum/challenges.md b/docs/reference/js/lessons/glowing-pendulum/challenges.md new file mode 100644 index 00000000..b670b774 --- /dev/null +++ b/docs/reference/js/lessons/glowing-pendulum/challenges.md @@ -0,0 +1,32 @@ +# glowing pendulum challenges + +Coding challenges for the glowing pendulum tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/glowing-pendulum/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.forever(() => { + let acceleration = input.acceleration("y") + acceleration = math.abs(acceleration) + acceleration = acceleration / 4 + led.setBrightness(acceleration) + led.plotAll() +}) +``` + +**Challenge 1** + +![](/static/mb/lessons/glowing-pendulum-0.jpg) + +Hold the BBC micro:bit in your hand in a dark room. Move the BBC micro:bit like a pendulum, and produce a slow image that captures the pattern of the BBC micro:bit LEDs. + +**Challenge 2** + +Replace "y" in `[input->acceleration("y")] with "x" or "z". Changing the axis will cause the BBC micro:bit to measure the force in a different direction. What differences in the resulting pattern does this replacement make? + diff --git a/docs/reference/js/lessons/glowing-pendulum/quiz-answers.md b/docs/reference/js/lessons/glowing-pendulum/quiz-answers.md new file mode 100644 index 00000000..3d3dfd85 --- /dev/null +++ b/docs/reference/js/lessons/glowing-pendulum/quiz-answers.md @@ -0,0 +1,53 @@ +# glowing pendulum quiz answers + +construct a pendulum that glows using acceleration #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [glowing pendulum tutorial](/microbit/lessons/glowing-pendulum/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Why are you creating a 'forever' loop? + +
+ +We are creating a forever loop to constantly display the appropriate brightness on the LED display. + +## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'. + +
+ +``` +let acceleration = input.acceleration("y") +``` + +## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'. + +
+ +``` +acceleration = math.abs(acceleration) +``` + +## 4. Write the code that uses the acceleration value from question #3 to set the brightness on the BBC micro:bit. + +
+ +``` +acceleration = acceleration / 4 +led.setBrightness(acceleration) +``` + +## 5. Write the code that tuns all the LEDs on (as the image displays below) + +![](/static/mb/lessons/glowing-pendulum-1.png) + +
+ +``` +led.plotAll() +``` + diff --git a/docs/reference/js/lessons/glowing-pendulum/quiz.md b/docs/reference/js/lessons/glowing-pendulum/quiz.md new file mode 100644 index 00000000..f2dc9a7d --- /dev/null +++ b/docs/reference/js/lessons/glowing-pendulum/quiz.md @@ -0,0 +1,34 @@ +# glowing pendulum quiz + +construct a pendulum that glows using acceleration #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [glowing pendulum tutorial](/microbit/lessons/glowing-pendulum/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Why are you creating a 'forever' loop? + +
+ +## 2. Write the line of code to measure the acceleration with respect to the "y" axis and store this value in a local variable called 'acceleration'. + +
+ +## 3. After storing the acceleration in a variable, write the code to take the absolute value of the acceleration, and store this value inside 'acceleration'. + +
+ +## 4. Write the code that uses the acceleration value from question #3 to set the brightness on the BBC micro:bit. + +
+ +## 5. Write the code that tuns all the LEDs on (as the image displays below) + +![](/static/mb/lessons/glowing-pendulum-1.png) + +
+ diff --git a/docs/reference/js/lessons/glowing-sword.md b/docs/reference/js/lessons/glowing-sword.md new file mode 100644 index 00000000..57521006 --- /dev/null +++ b/docs/reference/js/lessons/glowing-sword.md @@ -0,0 +1,97 @@ +# glowing sword 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) +* [tutorial](/microbit/lessons/glowing-sword/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to manipulate an image through **fade out**, `led->fade out` to gradually decrease the LED screen brightness until the LED lights are turned off. We will be learning how to fade an image using simple commands, such as plot image, fade out, pause, and fade in. + +## What the teacher needs to know/QuickStart Computing Glossary + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Computational thinking: Thinking about systems or problems in a way that allows computer systems to be used to model or solve these. +* Hardware: The physical systems and components of digital devices; see also software. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. + +## Documentation + +* **plot image** : [read more...](/microbit/reference/led/plot-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: [tutorial](/microbit/lessons/glowing-sword/tutorial) +* 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. +* [tutorial](/microbit/lessons/glowing-sword/tutorial) +* [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. + diff --git a/docs/reference/js/lessons/glowing-sword/activity.md b/docs/reference/js/lessons/glowing-sword/activity.md new file mode 100644 index 00000000..d9f0a377 --- /dev/null +++ b/docs/reference/js/lessons/glowing-sword/activity.md @@ -0,0 +1,63 @@ +# glowing sword activity + +Make glowing sword. #docs #microbit + +### ~avatar avatar + +### @video td/videos/glowing-sword-0 + +In this activity, we will learn how to fade in and out the screen to create a glowing animation. Let's get started! + +### ~ + +Let's start by adding the code to display an image. Use `basic->plot image` to draw your favorite image. + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) // *** +``` + +We can control the brightness of the LED screen with code. That's just what we need to create a **glowing** animation: first we **fade out**, then **fade in**. Add a new line of code to **fade out** the screen. + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) // *** +``` + +Run your script to make sure it works as expected then add another line of code to **fade in** the screen. + +``` +led.fadeIn(700) +``` + +Finally, add a `basic->forever` loop and move the fade out and fade in code into the forever to repeat the glow pattern. + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) // *** +led.fadeIn(700) // *** +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/glowing-sword/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/glowing-sword/challenges.md b/docs/reference/js/lessons/glowing-sword/challenges.md new file mode 100644 index 00000000..cad6ce01 --- /dev/null +++ b/docs/reference/js/lessons/glowing-sword/challenges.md @@ -0,0 +1,62 @@ +# glowing sword challenges + +Coding challenges for the glowing sword tutorial. #docs + +## Before we get started + +Complete the [glowing sword](/microbit/lessons/glowing-sword/activity) activity and your code will look like this: + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) +``` + +### Challenge 1 + +Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond (1 second) delay after the fade out. + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) +basic.pause(1000) // *** +``` + +* `run main` the code to see if it works as expected. + +### Challenge 2 + +### @video td/videos/glowing-sword-2 + +After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect. + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) +basic.pause(1000) +led.fadeIn(2000) // *** +``` + +* `run main` the code to see if it works as expected. + +### Challenge 3 + +Now add another `basic->pause(1000)` and `led->fade out(900)` so that the sword can fade out again. + diff --git a/docs/reference/js/lessons/glowing-sword/quiz-answers.md b/docs/reference/js/lessons/glowing-sword/quiz-answers.md new file mode 100644 index 00000000..6fac4cab --- /dev/null +++ b/docs/reference/js/lessons/glowing-sword/quiz-answers.md @@ -0,0 +1,48 @@ +# glowing sword quiz answers + +The answers for the glowing sword quiz. #LED #image #fade #docs + +This is the answer key for the [glowing sword quiz](/microbit/lessons/glowing-sword/quiz). + +## 1. What is "fade out" ? + +Fade out is a method that gradually decreases the LED screen brightness until the LED lights are turned off. + +## 2. Consider the following code + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) +``` + +Rewrite the second line of code to decrease the speed of the fade out for the longest amount of time (Hint: 1000 milliseconds is longest amount of time for a fade out). + +
+ +led->fade out(1000) + +## 4. Consider the following code + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(1000) +``` + +What will cause the image to fade back in twice as fast as it faded out? + +
+ +led->fade in(500) + diff --git a/docs/reference/js/lessons/glowing-sword/quiz.md b/docs/reference/js/lessons/glowing-sword/quiz.md new file mode 100644 index 00000000..7ff2a6fe --- /dev/null +++ b/docs/reference/js/lessons/glowing-sword/quiz.md @@ -0,0 +1,46 @@ +# glowing sword quiz + +make a glowing sword. #LED #image #fade #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [glowing sword tutorial](/microbit/lessons/glowing-sword/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what "led -> fade out" does? + +
+ +## 2. Rewrite the second line of code to decrease the speed of the fade out for the longest amount of time Hint: 1000 milliseconds is longest amount of time for a fade out. + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(700) +``` + +
+ +## 3. What will cause the image to fade back in twice as fast as it faded out? + +``` +basic.plotImage(` +. . . . # +# . . # . +. # # . . +. # # . . +# . . # . +`) +led.fadeOut(1000) +``` + +
+ diff --git a/docs/reference/js/lessons/guess-the-number.md b/docs/reference/js/lessons/guess-the-number.md new file mode 100644 index 00000000..85fe2e54 --- /dev/null +++ b/docs/reference/js/lessons/guess-the-number.md @@ -0,0 +1,84 @@ +# 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 - Random Numbers + +## Quick links + +* [activity](/microbit/lessons/guess-the-number/activity) +* [challenges](/microbit/lessons/guess-the-number/challenges) +* [quiz](/microbit/lessons/guess-the-number/quiz) +* [quiz answers](/microbit/lessons/guess-the-number/quiz-answers) +* [tutorial](/microbit/lessons/guess-the-number/tutorial) + +## 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 math->random, 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) +* **random numbers**: [read more...](/microbit/js/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) +* [tutorial](/microbit/lessons/guess-the-number/tutorial) +* [quiz](/microbit/lessons/guess-the-number/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/guess-the-number/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/guess-the-number/challenges) + diff --git a/docs/reference/js/lessons/guess-the-number/activity.md b/docs/reference/js/lessons/guess-the-number/activity.md new file mode 100644 index 00000000..75210043 --- /dev/null +++ b/docs/reference/js/lessons/guess-the-number/activity.md @@ -0,0 +1,44 @@ +# guess the number activity + +guess the number with math random. #microbit #docs + +### ~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! + +### ~ + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap New Project under **Touch Develop**. + +Add an event handler when button `A` is pressed. + +``` +input.onButtonPressed("A", () => { +}) +``` + +Create a local variable of type number `x` and set it to a random number using `math->random`. `math->random(10)` generates a random number between `0` and `10` **excluded**. + +``` +input.onButtonPressed("A", () => { + let x = Math.random(10) +}) +``` + +Show the random number on the screen. + +``` +input.onButtonPressed("A", () => { + let x1 = Math.random(10) + basic.showNumber(x1, 150) +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/guess-the-number/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/guess-the-number/challenges.md b/docs/reference/js/lessons/guess-the-number/challenges.md new file mode 100644 index 00000000..00b6445d --- /dev/null +++ b/docs/reference/js/lessons/guess-the-number/challenges.md @@ -0,0 +1,39 @@ +# guess the number challenges + +Coding challenges for the guess the number tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/guess-the-number/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +input.onButtonPressed("A", () => { + let x = Math.random(10) + basic.showNumber(x, 150) +}) +``` + +### 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. + +``` +input.onButtonPressed("A", () => { + let x1 = Math.random(10) + basic.showNumber(x1, 150) +}) +input.onButtonPressed("B", () => { + basic.clearScreen() // *** +}) +``` + +### Challenge 2 + +Show an animation when you clear the screen! Choose what animation makes most sense to you. Be creative! + diff --git a/docs/reference/js/lessons/guess-the-number/lesson-plan.md b/docs/reference/js/lessons/guess-the-number/lesson-plan.md new file mode 100644 index 00000000..efc4d436 --- /dev/null +++ b/docs/reference/js/lessons/guess-the-number/lesson-plan.md @@ -0,0 +1,99 @@ +# guess the number lesson plan + +Learn how to create a random number with input from button A. #input #screen #math #docs + +### @video vimeo/134121077 + +## Topic + +Input - Random Numbers + +## 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 math->random, and show number. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **local variables**: [read more...](/microbit/reference/variables/var) +* **math**: [read more...](/microbit/js/math) +* **on button pressed**: [read more...](/microbit/reference/input/on-button-pressed) + +## Resources + +* Activity: [tutorial](/microbit/lessons/guess-the-number/tutorial) +* Activity: [quiz](/microbit/lessons/guess-the-number/quiz) +* Extended Activity: [challenges](/microbit/lessons/guess-the-number/challenges) + +## Objectives + +* learn how to create a global variable +* learn how a rotating animation +* learn how to repeat the animation + +## Links to the National Curriculum Programmes of Study for Computing + +## Assessment + +### Progression Pathways + +### Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/guess-the-number/tutorial) +* [quiz](/microbit/lessons/guess-the-number/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/guess-the-number/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/guess-the-number/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/guess-the-number/quiz-answers.md b/docs/reference/js/lessons/guess-the-number/quiz-answers.md new file mode 100644 index 00000000..9521567d --- /dev/null +++ b/docs/reference/js/lessons/guess-the-number/quiz-answers.md @@ -0,0 +1,39 @@ +# guess the number quiz answers + +Learn how to generate a random number on the micro:bit. #math #random #docs + +This is the answer key for the [guess the number quiz](/microbit/lessons/guess-the-number/quiz). + +## 1. What is on button pressed? + +Answers may vary. Generally, on button pressed run code when an input button is pressed. The micro:bit has two input buttons: A and B. + +## 2. Consider the following directions + +Write the line of code that creates a condition when the BBC micro:bit button A is pressed. + +``` +input.onButtonPressed("A", () => { +}) +``` + +## 3. Consider the following directions + +Write the line of code that creates a **local variable** and a **random number**. + +``` +let randomNumber = Math.random(10) +``` + +## 4. Consider the following code + +``` +randomNumber = Math.random(10) +``` + +If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded. + +![](/static/mb/lessons/guess-the-number-0.png) + +The random number generator will return a number from 0 to the limit. However, not including the limit unless the limit is 0. So you can place an X to represent any single digit number. + diff --git a/docs/reference/js/lessons/guess-the-number/quiz.md b/docs/reference/js/lessons/guess-the-number/quiz.md new file mode 100644 index 00000000..c1d3379a --- /dev/null +++ b/docs/reference/js/lessons/guess-the-number/quiz.md @@ -0,0 +1,35 @@ +# guess the number quiz + +Learn how to generate a random number on the micro:bit. #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [guess the number tutorial](/microbit/lessons/guess-the-number/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what "input -> on button pressed" does? + +
+ +## 2. Write the line of code that creates a condition for on button A pressed. + +
+ +## 3. Write the line of code that creates a `local variable` called `randomNumber` and will return a number from 0 to a limit of 10. + +
+ +## 4. Draw the area that could be lit based on the code below. Explain why you chose to draw that number. + +``` +let randomNumber = Math.random(10) +basic.showNumber(randomNumber, 150) +``` + +![](/static/mb/empty-microbit.png) + +
+ diff --git a/docs/reference/js/lessons/hack-your-headphones.md b/docs/reference/js/lessons/hack-your-headphones.md new file mode 100644 index 00000000..90297fdf --- /dev/null +++ b/docs/reference/js/lessons/hack-your-headphones.md @@ -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 + diff --git a/docs/reference/js/lessons/hack-your-headphones/activity.md b/docs/reference/js/lessons/hack-your-headphones/activity.md new file mode 100644 index 00000000..b30faff7 --- /dev/null +++ b/docs/reference/js/lessons/hack-your-headphones/activity.md @@ -0,0 +1,56 @@ +# hack your headphones activity + +hack your headphones #microbit #docs + +# BBC micro:bit music + +![](/static/mb/lessons/hack-your-headphones-0.png) + +In this project, you will build your own music player BBC micro:bit from headphones. Project duration: 15 minutes. + +## Materials + +* BBC 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 BBC 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 BBC 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 BBC 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 BBC 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 BBC micro:bit to your computer using your USB cable and run the [happy birthday](/microbit/dnnzgd) script on it. Press the reset button to restart your music player! + diff --git a/docs/reference/js/lessons/headbands.md b/docs/reference/js/lessons/headbands.md new file mode 100644 index 00000000..5f7adfe2 --- /dev/null +++ b/docs/reference/js/lessons/headbands.md @@ -0,0 +1,130 @@ +# headbands lesson + +create a charades game that can be played with your friends #data #string #collection #at #Boolean #on-logo-down #on-logo-up #running-time #string #number #docs + +## Topic + +Collection + +## Quick Links + +* [tutorial](/microbit/lessons/headbands/tutorial) +* [quiz](/microbit/lessons/headbands/quiz) +* [quiz answers](/microbit/lessons/headbands/quiz-answers) +* [challenges](/microbit/lessons/headbands/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a charades game with **collections**, ` create -> Collection of` , to store and retrieve data . We will be learning how to create a charades game using global variables, collection of string, add, Boolean, on logo down, on logo up, forever loop, if statements, running time as well as simple commands, such as show string and show number. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **collection** +* **global variables** : [read more...](/microbit/js/data) +* **Boolean** : [read more...](/microbit/reference/types/boolean) +* **on logo up** [read more...](/microbit/functions/on-logo-up) +* **on screen down** [read more...](/microbit/functions/on-screen-down) +* **on screen up** [read more...](/microbit/functions/on-screen-up) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **game library** : [read more...](/microbit/js/game-library) + +## Resources + +* Activity: [tutorial](/microbit/lessons/headbands/tutorial) +* Activity: [quiz](/microbit/lessons/headbands/quiz) +* Extended Activity: [challenges](/microbit/lessons/headbands/challenges) + +## Objectives + +* learn how a collection is a group of variables of the same type stored together +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how to repeat code in the background forever +* learn how to learn how to conditionally run code depending on whether a condition is true or not +* learn how to run code when the BBC micro:bit is oriented perpendicular to the floor with the logo down +* learn how to get the number of milliseconds elapsed since the script began +* learn how to show a string on the BBC micro:bit screen +* learn how to show a number of the BBC micro:bit screen + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/headbands/tutorial) +* [quiz](/microbit/lessons/headbands/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/headbands/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/headbands/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/headbands/challenges.md b/docs/reference/js/lessons/headbands/challenges.md new file mode 100644 index 00000000..02d806e9 --- /dev/null +++ b/docs/reference/js/lessons/headbands/challenges.md @@ -0,0 +1,74 @@ +# headbands challenges + +These challenges will teach you how to create a fun charades game to play with your friends. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/headbands/tutorial) + +At the tend of the tutorial, click `keep editing`. Your code should look like this: + +``` +coll = ([]) +coll.push("puppy") +coll.push("clock") +coll.push("night") +coll.push("cat") +coll.push("cow") +input.onLogoUp(() => { + let index = Math.random(coll.length) + let word = coll[index] + basic.showString(word, 150) +}) +input.onScreenDown(() => { + game.addScore(1) +}) +game.startCountdown(30000) +``` + +### Challenge 1 + +Let's add more words for the player to act out! But first, we need to increase the time in one round to give the player more time get through all the words. Let's change the `game->start countdown` statement. + +``` +// **. . .** +game.startCountdown(60000) // *** +``` + +* Run your code to see if it works as expected + +### Challenge 2 + +Now let's add 5 more words to our list of charade words. Right above the the line `word:=coll->at(index)` add 5 lines that say `coll->add("")`. In this example, we will add the words **bicycle, telephone, sun, car, and ant** but you can add whatever words you like. + +``` +// . . . +coll.push("puppy") +coll.push("clock") +coll.push("night") +coll.push("cat") +coll.push("cow") +coll.push("bicycle") // *** +coll.push("telephone") // *** +coll.push("sun") // *** +coll.push("car") // *** +coll.push("ant") // *** +// . . . +``` + +* Run your code to see if it works as expected. + +### Challenge 3 + +Remove a life using `game->remove life` when the screen is down using the `input->on screen down` event. + +### Challenge 4 + +The collection has a function `random` that returns a random element. Update your code to use this function instead of using `math->random`. + +### Challenge 5! + +Play the game and try guessing all these words in less than 2 minutes! + diff --git a/docs/reference/js/lessons/headbands/quiz-answers.md b/docs/reference/js/lessons/headbands/quiz-answers.md new file mode 100644 index 00000000..6c069824 --- /dev/null +++ b/docs/reference/js/lessons/headbands/quiz-answers.md @@ -0,0 +1,78 @@ +# headbands quiz answers + +create a charades game with a collection of strings #offset #screen #variables #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [headbands tutorial](/microbit/lessons/headbands/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is the meaning of the term 'collection' in programming? What is a 'collection' of strings? + +
+ +A 'collection' is a group of variables of the same type stored together. A 'collection' of strings is a group of strings stored together. + +## 2. Consider the following lines of code. + +``` +coll = ([]) +coll.push("puppy") +coll.push("clock") +``` + +Write the line of code that will display the string "puppy" using `data->coll`. + +
+ +``` +basic.showString(coll[0], 150) +``` + +## 3. Consider the following lines of code. + +``` +coll = ([]) +coll.push("puppy") +coll.push("clock") +coll.push("cat") +``` + +Write the line of code that will display the string "cat" using `data->coll`. + +
+ +``` +basic.showString(coll[2], 150) +``` + +## 4. Consider the following line of code. + +``` +coll = ([]) +``` + +Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow. + +
+ +``` +coll.push("puppy") +coll.push("clock") +coll.push("night") +coll.push("cat") +coll.push("cow") +``` + +## 5. Write the code to get a string from the collection at a random position. + +
+ +``` +let index = Math.random(coll.length) +let word = coll[index] +``` + diff --git a/docs/reference/js/lessons/headbands/quiz.md b/docs/reference/js/lessons/headbands/quiz.md new file mode 100644 index 00000000..8a6b34d8 --- /dev/null +++ b/docs/reference/js/lessons/headbands/quiz.md @@ -0,0 +1,63 @@ +# headbands quiz + +create a charades game with a collection of strings #offset #screen #variables #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [headbands tutorial](/microbit/lessons/headbands/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is the meaning of the term 'collection' in programming? What is a 'collection' of strings? + +
+ +
+ +## 2. Write the line of code that will display the string "puppy" using "data->coll". + +``` +coll = ([]) +coll.push("puppy") +coll.push("clock") +``` + +
+ +## 3. Write the line of code that will display the string "cat" using `"data->coll". + +``` +coll = ([]) +coll.push("puppy") +coll.push("clock") +coll.push("cat") +``` + +
+ +## 4. Write the five (5) lines of code that will add the following five words to `data->coll`: puppy, clock, night, cat, cow. + +``` +coll = ([]) +``` + +
+ +
+ +
+ +
+ +## 5. Write the code to get a string from the collection at a random position. + +
+ +
+ +
+ +
+ diff --git a/docs/reference/js/lessons/jailbreak.md b/docs/reference/js/lessons/jailbreak.md new file mode 100644 index 00000000..09d9ec53 --- /dev/null +++ b/docs/reference/js/lessons/jailbreak.md @@ -0,0 +1,108 @@ +# jailbreak lesson + +break out of a counting loop by pressing button "A" #button #while #if #Boolean #pause #string #plot #break #docs + +### @video td/videos/jailbreak-0 + +## Topic + +Break + +## Quick Links + +* [tutorial](/microbit/lessons/jailbreak/tutorial) +* [quiz](/microbit/lessons/jailbreak/quiz) +* [quiz answers](/microbit/lessons/jailbreak/quiz-answers) +* [challenges](/microbit/lessons/jailbreak/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a **break**, `break` to exit a while or for loop before the loop is complete. We will be learning how to create a break using global variables, Boolean, If (conditionals), a While Loop as well as simple commands, such as show string, plot image, show number, and pause. + +## Documentation + +* **Global Variable** : [read more...](/microbit/js/data) +* **Boolean** : [read more...](/microbit/reference/types/boolean) +* **On Button Pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **While Loop** : [read more...](/microbit/js/while) +* **Break** : [read more...](/microbit/js/break) +* **If (Conditional)** : [read more...](/microbit/reference/logic/if) +* **Show String** : [read more...](/microbit/reference/basic/show-string) +* **Plot Image ** : [read more...](/microbit/reference/led/plot-image) +* **Show Number** : [read more...](/microbit/reference/basic/show-number) +* **Pause** : [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to create global variables to store data so that you can use it later in your code, functions, and in nested code blocks +* learn how to use the variables to declare a new local Boolean variable that will have one of two possible values: true or false +* learn how to run code when an input button is pressed +* learn how to repeat code while a condition is true +* learn how to exit a while loop before the loop is complete +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to show a string on the LED screen one character at a time +* learn how to turn on LED lights on the LED screen +* learn how to show a number on the LED screen, one digit at a time +* learn how to pause your code for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL) +* Recognises that different algorithms exist for the same problem (AL) (GE) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) +* Defines data types: real numbers and Boolean (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/jailbreak/tutorial) +* [quiz](/microbit/lessons/jailbreak/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/jailbreak/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/jailbreak/challenges) + diff --git a/docs/reference/js/lessons/jailbreak/challenges.md b/docs/reference/js/lessons/jailbreak/challenges.md new file mode 100644 index 00000000..d5f0c2d8 --- /dev/null +++ b/docs/reference/js/lessons/jailbreak/challenges.md @@ -0,0 +1,104 @@ +# jailbreak challenges + +Coding challenges for the jailbreak tutorial.#docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/jailbreak/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +count = 0 +shouldBreak = false +input.onButtonPressed("A", () => { + shouldBreak = true +}) +while (true) { + if (shouldBreak) { + basic.showString("I'M OUT!", 150) + basic.plotImage(` +. # . # . +. # . # . +. . . . . +# . . . # +. # # # . +`) + break + } + count = count + 1 + basic.showNumber(count, 150) + basic.pause(1000) +} +``` + +**Challenge 1** + +Try to remove the `break` in the `if` loop. What problem does this create? + +**Challenge 2** + +Now let's resume the timer again once button `B` is pressed! To do so, begin by creating a condition to know when button `B` is pressed. + +``` +// **. . .** +while (true) { + if (shouldBreak) { + basic.showString("I'M OUT!", 150) + basic.plotImage(` +. # . # . +. # . # . +. . . . . +# . . . # +. # # # . +`) + break + } + count = count + 1 + basic.showNumber(count, 150) + basic.pause(1000) +} +input.onButtonPressed("B", () => { +}) // *** +``` + +Next, set `should break` back to false to indicate we want to run the `while` loop again. + +``` +// **. . .** +input.onButtonPressed("B", () => { + shouldBreak = false // *** +}) +``` + +And now copy the code from the previous while loop into the condition of `input->on button pressed("B")`. This will resume the counter. + +``` +// **. . .** +input.onButtonPressed("B", () => { + shouldBreak = false + while (true) { + if (shouldBreak) { + basic.showString("I'M OUT!", 150) // *** + basic.plotImage(` +. # . # . +. # . # . +. . . . . +# . . . # +. # # # . +`) // *** + break // *** + } + count = count + 1 // *** + basic.showNumber(count, 150) // *** + basic.pause(1000) // *** + } +}) +``` + +**Challenge 3** + +Notice that the two `while` loops are identical. Clean up this redundancy in your code by creating another method and then placing the `while` loop in the method. + diff --git a/docs/reference/js/lessons/jailbreak/quiz-answers.md b/docs/reference/js/lessons/jailbreak/quiz-answers.md new file mode 100644 index 00000000..3d6164be --- /dev/null +++ b/docs/reference/js/lessons/jailbreak/quiz-answers.md @@ -0,0 +1,46 @@ +# jailbreak quiz answers + +break out of a counting loop by pressing button "A" #break #string #variables #docs + +This is the answer key for the [jailbreak quiz](/microbit/lessons/jailbreak/quiz). + +## 1. What does a 'break' statement do to a 'loop' ? + +Exit a while or for loop before the loop is complete. + +## 2. Consider the following directions + +Write the line of code that will initialize a number `variable` to 0. Then create a second `variable` that tells us when we should `break` out of the loop. Set the `break` to false. + +``` +count = 0 +shouldBreak = false +``` + +## 3. Consider the following directions + +Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true). + +``` +input.onButtonPressed("A", () => { + shouldBreak = true +}) +``` + +## 4. Consider the following directions + +Add an `if` statement to determine whether or not we should break out of the loop. Then include the message "I'm Out!" and a smiley face **image** displayed. This will happen right before you `break` from the `while` loop. **Do not include the break ** + +``` +if (shouldBreak) { + basic.showString("I'M OUT!", 150) + images.createImage(` +. # . # . +. # . # . +. . . . . +# . . . # +. # # # . +`).showImage(0) +} +``` + diff --git a/docs/reference/js/lessons/jailbreak/quiz.md b/docs/reference/js/lessons/jailbreak/quiz.md new file mode 100644 index 00000000..31659b7c --- /dev/null +++ b/docs/reference/js/lessons/jailbreak/quiz.md @@ -0,0 +1,34 @@ +# jailbreak quiz + +break out of a counting loop by pressing button "A" #break #string #variables #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [jailbreak tutorial](/microbit/lessons/jailbreak/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What does a 'break' statement do to a 'loop' ? + +## 2. Consider the following directions + +Write the line of code that will initialize a number variable to 0. Then create a second variable that tells us when we should `break` out of the loop. Set the `break` to false. + +
+ +## 3. Consider the following directions + +Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true). + +
+ +## 4. Consider the following directions + +Add an `if` statement to determine whether or not we should break out of the loop. Then include the message "I'm Out!" and a smiley face **image** displayed. This will happen right before you `break` from the `while` loop. **Do not include the break ** + +
+ +
+ diff --git a/docs/reference/js/lessons/landslide.md b/docs/reference/js/lessons/landslide.md new file mode 100644 index 00000000..e1120ef5 --- /dev/null +++ b/docs/reference/js/lessons/landslide.md @@ -0,0 +1,8 @@ +# landslide + +Turn a LED on and off. #docs + +Detect and show an image when the micro:bit falls. + +* [tutorial](/microbit/lessons/landslide/tutorial) +* [challenges](/microbit/lessons/landslide/challenges) diff --git a/docs/reference/js/lessons/landslide/challenges.md b/docs/reference/js/lessons/landslide/challenges.md new file mode 100644 index 00000000..d613cc88 --- /dev/null +++ b/docs/reference/js/lessons/landslide/challenges.md @@ -0,0 +1,77 @@ +# landslide challenges + +Coding challenges for the landslide tutorial. #onfall #docs + +### ~avatar avatar fail + +Don't drop me on the ground without protection! I'm very fragile. Ouch! + +### ~ + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/landslide/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +input.onFall(() => { + images.createImage(` +. . # . . +. . # . . +. . # . . +. . . . . +. . # . . +`).showImage(0) // *** +}) +``` + +### Challenge 1 + +Add a pause within `input->on fall` after displaying `!`. This will allow us to display another image in the next challenge. + +``` +input.onFall(() => { + images.createImage(` +. . # . . +. . # . . +. . # . . +. . . . . +. . # . . +`).showImage(0) + basic.pause(2000) // *** +}) +``` + +### Challenge 2 + +Create and show an `X` image after the pause from Challenge 1. + +``` +input.onFall(() => { + images.createImage(` +. . # . . +. . # . . +. . # . . +. . . . . +. . # . . +`).showImage(0) + basic.pause(2000) + images.createImage(` +# . . . # +. # . # . +. . # . . +. # . # . +# . . . # +`).showImage(0) // *** +}) +``` + +* `Run` the program to see if it works as expected. + +### Challenge 3 + +Now let's display a third image when the micro:bit falls! First, add `basic->pause(2000)` followed by another image of your choice. Be creative! + diff --git a/docs/reference/js/lessons/letter-up.md b/docs/reference/js/lessons/letter-up.md new file mode 100644 index 00000000..d553c41a --- /dev/null +++ b/docs/reference/js/lessons/letter-up.md @@ -0,0 +1,116 @@ +# letter up lesson + +create a guessing game that can be played with your friends #at #string #at #on-logo-down #string-functions #on-logo-up #library #docs + +## Topic + +String Functions + +## Quick Links + +* [tutorial](/microbit/lessons/letter-up/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a guessing game with **global variables** `var str: "this is a string" ` and **strings functions**, ` var first char := str -> at(0) ` , to develop a sequence of characters and get a character within a string . We will be learning how to create a guessing game using local variables, strings functions, input on logo up, string related functions, on screen up, the game library as well as simple commands, such as show string and show number. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **string** : [read more...](/microbit/reference/types/string) +* **string functions** : [read more...](/microbit/reference/types/string-functions) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **local variables** : [read more...](/microbit/reference/variables/var) +* **assignment operator** : [read more...](/microbit/reference/variables/assign) +* **on logo up** [read more...](/microbit/functions/on-logo-up) +* **on screen down** [read more...](/microbit/functions/on-screen-down) +* **on screen up** [read more...](/microbit/functions/on-screen-up) +* **math random** : [read more...](/microbit/js/math) +* **game library** [read more...](/microbit/js/game-library) + +## Resources + +* Activity: [tutorial](/microbit/lessons/letter-up/tutorial) + +## Objectives + +* learn how to create a sequences of characters +* learn how to get a character within a string, using the specified index +* learn how to show a string on the LED screen +* learn how to create a local variable to store data so that you can use it later in your code +* learn how to set and change the value of a local variable +* learn how to register an event handler that executes whenever the LED screen is perpendicular to the ground and the BBC micro:bit logo is above the LED screen +* learn how to register an event handler that executes whenever the LED screen is facing the floor +* learn how to register an event handler that executes whenever the LED screen is facing the ceiling/sky +* learn how to return a random number +* learn how to use the game library to set the score, lives, and countdown + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/letter-up/tutorial) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/light-column-cascade/quiz.md b/docs/reference/js/lessons/light-column-cascade/quiz.md new file mode 100644 index 00000000..2935840f --- /dev/null +++ b/docs/reference/js/lessons/light-column-cascade/quiz.md @@ -0,0 +1,128 @@ +# cascade quiz + +Learn how to create a blinking LED script with a for loop. #LED #screen #plot #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [light column cascade tutorial](/microbit/js/light-column-cascade/tutorial). + +Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs! + +## 1. What is a for loop? + +## 2. Consider the following code + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +## 3. Consider the following code + +``` +for (let i1 = 0; i1 < 3; i1++) { + for (let j1 = 0; j1 < 3; j1++) { + led.plot(i1, j1) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +## 4. Consider the following code + +``` +for (let i2 = 0; i2 < 2; i2++) { + for (let j2 = 0; j2 < 2; j2++) { + led.plot(i2, j2) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png) + +****************************** + +## KEY + +## Directions + +Answer the questions below while working on or after you finish the tutorial. + +## 1. What is a for loop? + +Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates. + +## 2. Consider the following code + +``` +for (let i3 = 0; i3 < 5; i3++) { + for (let j3 = 0; j3 < 5; j3++) { + led.plot(i3, j3) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-0.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs + +x - the x coordinate or horizontal position (0,1,2,3,4) + +y - the y coordinate or vertical position (0,1,2,3,4) + +## 3. Consider the following code + +``` +for (let i4 = 0; i4 < 3; i4++) { + for (let j4 = 0; j4 < 3; j4++) { + led.plot(i4, j4) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/column-0.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +x - the x coordinate or horizontal position (0,1,2) + +y - the y coordinate or vertical position (0,1,2) + +## 4. Consider the following code + +``` +for (let i5 = 0; i5 < 1; i5++) { + for (let j5 = 0; j5 < 1; j5++) { + led.plot(i5, j5) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/column-1.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +x - the x coordinate or horizontal position (0,1) + +y - the y coordinate or vertical position (0,1) + diff --git a/docs/reference/js/lessons/line-of-fire.md b/docs/reference/js/lessons/line-of-fire.md new file mode 100644 index 00000000..4b72e04f --- /dev/null +++ b/docs/reference/js/lessons/line-of-fire.md @@ -0,0 +1,96 @@ +# line of fire lesson + +create a game that relies on precise instincts and timing reflexes #if # #function #data #forever #var #button #if #assignment #pause #string #number #docs + +### @video td/videos/timing-game-0 + +## Topic + +Functions + +## Quick Links + +* [tutorial](/microbit/lessons/line-of-fire/tutorial) +* [quiz](/microbit/lessons/line-of-fire/quiz) +* [quiz answers](/microbit/lessons/line-of-fire/quiz-answers) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a pong game using functions, global variable forever loop, global variables, Boolean, for loop, input on button pressed, if statements, as well as simple commands, such as plot, unplot and pause. + +## Documentation + +* **function** : [read more...](/microbit/js/function) +* **return** : [read more...](/microbit/js/return) +* **call** : [read more...](/microbit/js/call) +* **global variable** : [read more...](/microbit/js/data) +* **arithmetic operator** : [read more...](/microbit/reference/types/number) +* **Boolean** : [read more...](/microbit/reference/types/boolean) +* **forever** : [read more...](/microbit/reference/basic/forever) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **if** : [read more...](/microbit/reference/logic/if) +* **clear screen** : [read more...](/microbit/reference/basic/clear-screen) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **plot** : [read more...](/microbit/reference/led/plot) +* **unplot** : [read more...](/microbit/reference/led/unplot) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to create a function as a unit of code that performs a specific task and returns a result +* learn how a return statement exits a function and returns a value to the code +* learn how to call an existing function in your script +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how arithmetic operators operate on numbers and return a number +* learn how a Boolean type has one of two possible values: true or false +* learn how to repeat code in the background forever +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to run code when an input button is pressed +* learn how to show a string on the micro:bit's LED screen +* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates +* learn how to turn off a LED light on the LED screen. Learn how to specify which LED using x, y coordinates +* learn how to pause your code for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Defines data types: real numbers and Boolean (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/line-of-fire/tutorial) + +## Extended Activity + +* time: 20 min. +* [quiz](/microbit/lessons/line-of-fire/quiz) + +## Homework + +* Extended Activity: [quiz](/microbit/lessons/line-of-fire/quiz) + diff --git a/docs/reference/js/lessons/line-of-fire/quiz-answers.md b/docs/reference/js/lessons/line-of-fire/quiz-answers.md new file mode 100644 index 00000000..1c7dc56b --- /dev/null +++ b/docs/reference/js/lessons/line-of-fire/quiz-answers.md @@ -0,0 +1,140 @@ +# line of fire quiz answers + +create a game that relies on precise instincts and timing reflexes #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [line of fire tutorial](/microbit/lessons/line-of-fire/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the names of the two Global Variable used to store the mode of the game. Which of these variables is set to true when we are displaying the score? + +
+ +``` +dotRunning = true +displayingStats = false +``` + +`displaying stats` is set to `true` when we are displaying the score. + +## 2. Write the name of the Global Variable that represents the velocity and assign it to its initial value. Next, write the name of the Global Variable that represents the position of the dot and assign it to its initial value. + +
+ +``` +dotX = 2 +dotXVelocity = 1 +``` + +## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values. + +
+ +``` +wins = 0 +losses = 0 +``` + +## 4. Write the For Loop that will plot the 'line of fire'. + +
+ +``` +for (let i = 0; i < 5; i++) { + led.plot(2, i) +} +``` + +## 5. If the dot is running, write the 'nested If statements' that will see when to change the direction by flipping the sign of the velocity. This occurs if the dot is on the edge of the board. + +
+ +**Questions 6-8 concern with moving the dot.** + +## 6. Write the code to unplot the dot's current position. NOTE- if dotX was originally 2, then we must plot instead of unplot the dot's original position. + +
+ +Solution 1: + +``` +if (dotX == 2) { + led.plot(dotX, 2) +} else { + led.unplot(dotX, 2) +} +``` + +Alternative Solution: + +``` +if (dotX != 2) { + led.unplot(dotX, 2) +} else { + led.plot(dotX, 2) +} +``` + +## 7. Update its position variables by adding the velocity to the dot's current position. + +
+ +``` +dotX = dotX + dotXVelocity +``` + +## 8. Finally, plot the dot's new position. NOTE- if dotX is now 2, then we must unplot instead of plot the dot's new position. + +
+ +Solution 1: + +``` +led.plot(dotX, 2) +if (dotX == 2) { + led.unplot(dotX, 2) +} +``` + +Alternative Solution: + +``` +if (dotX == 2) { + led.unplot(dotX, 2) +} else { + led.plot(dotX, 2) +} +``` + +## 9. Write the code that plots and unplots the dot 10 times when button A is pressed. Pause for 60 milliseconds in between plotting and unplotting the dot. (Don't include any if statements, and don't worry about updating 'dot running'.) + +
+ +``` +for (let j = 0; j < 10; j++) { + led.plot(dotX, 2) + basic.pause(60) + led.unplot(dotX, 2) + basic.pause(60) +} +``` + +## 10. Write the code that will display the score when button B is pressed. (Don't include any IF statements, and don't worry about updating 'dot running' and 'displaying stats'.) + +
+ +``` +input.onButtonPressed("B", () => { + basic.showString("WINS", 150) + basic.showNumber(wins, 150) + basic.pause(500) + basic.showString("LOSSES", 150) + basic.showNumber(losses, 150) + basic.pause(500) +}) +``` + diff --git a/docs/reference/js/lessons/line-of-fire/quiz.md b/docs/reference/js/lessons/line-of-fire/quiz.md new file mode 100644 index 00000000..a719fbdf --- /dev/null +++ b/docs/reference/js/lessons/line-of-fire/quiz.md @@ -0,0 +1,84 @@ +# line of fire quiz + +create a game that relies on precise instincts and timing reflexes #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [line of fire tutorial](/microbit/lessons/line-of-fire/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the names of the two Global Variable used to store the mode of the game. Which of these variables is set to true when we are displaying the score? + +
+ +
+ +## 2. Write the name of the Global Variable that represents the velocity and assign it to its initial value. Next, write the name of the Global Variable that represents the position of the dot and assign it to its initial value. + +
+ +
+ +## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values. + +
+ +
+ +## 4. Write the For Loop that will plot the 'line of fire'. + +
+ +
+ +
+ +## 5. If the dot is running, write the 'nested If statements' that will see when to change the direction by flipping the sign of the velocity. This occurs if the dot is on the edge of the board. + +
+ +**Questions 6-8 concern with moving the dot.** + +## 6. Write the code to unplot the dot's current position. NOTE- if dot x was originally 2, then we must plot instead of unplot the dot's original position. + +
+ +
+ +
+ +## 7. Update its position variables by adding the velocity to the dot's current position. + +
+ +## 8. Finally, plot the dot's new position. NOTE- if dot x is now 2, then we must unplot instead of plot the dot's new position. + +
+ +
+ +
+ +## 9. Write the code that plots and unplots the dot 10 times when button A is pressed. Pause for 60 milliseconds in between plotting and unplotting the dot. (Don't include any if statements, and don't worry about updating 'dot running'.) + +
+ +
+ +
+ +## 10. Write the code that will display the score when button B is pressed. (Don't include any IF statements, and don't worry about updating 'dot running' and 'displaying stats'.) + +
+ +
+ +
+ +
+ +
+ diff --git a/docs/reference/js/lessons/logo-pointer/challenges.md b/docs/reference/js/lessons/logo-pointer/challenges.md new file mode 100644 index 00000000..6fe9fa02 --- /dev/null +++ b/docs/reference/js/lessons/logo-pointer/challenges.md @@ -0,0 +1,75 @@ +# magic logo challenges + +These challenges will help you show arrows that point which way the logo is pointing! #docs + +**Challenge 0** + +### @video vimeo/134638098 + +This [guided tutorial](/microbit/zysycw) will help you display an arrow pointing the direction the logo is oriented! + +Let's display and upward pointing arrow when the logo is up! + +``` +input.onLogoUp(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`).showImage(0) +}) +``` + +**Challenge 1** + +How about when the logo is down? We should display the arrow pointing downward! + +Let's start by adding a condition for if the logo is down. + +``` +input.onLogoUp(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`).showImage(0) +}) +input.onLogoDown(() => { +}) // *** +``` + +**Challenge 2** + +### @video vimeo/134639918 + +Now we need to display the arrow! + +``` +input.onLogoUp(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`).showImage(0) +}) +input.onLogoDown(() => { + images.createImage(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`).showImage(0) // *** +}) +``` + +**Challenge 3** + +Let's show a spinning arrow when the micro:bit is shaken. We can do this by adding an on shake condition and showing an animation of the arrow spinning! + diff --git a/docs/reference/js/lessons/looper.md b/docs/reference/js/lessons/looper.md new file mode 100644 index 00000000..f0cc5fb7 --- /dev/null +++ b/docs/reference/js/lessons/looper.md @@ -0,0 +1,80 @@ +# looper lesson + +Learn to control blinking LEDs. #LED #screen #for #docs + +### @video td/videos/looper-0 + +## Topic + +For Loop + +## Quick links + +* [tutorial](/microbit/lessons/looper/tutorial) +* [quiz](/microbit/lessons/looper/quiz) +* [quiz answers](/microbit/lessons/looper/quiz-answers) +* [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. +* [tutorial](/microbit/lessons/looper/tutorial) +* [quiz](/microbit/lessons/looper/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/looper/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/looper/challenges) + diff --git a/docs/reference/js/lessons/looper/challenges.md b/docs/reference/js/lessons/looper/challenges.md new file mode 100644 index 00000000..5e239994 --- /dev/null +++ b/docs/reference/js/lessons/looper/challenges.md @@ -0,0 +1,83 @@ +# looper challenges + +Coding challenges for the looper tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/looper/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +for (let i = 0; i < 6; i++) { + basic.showNumber(i, 150) + basic.pause(2000) +} +``` + +### Challenge 1 + +### @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 `8` instead of `6`. + +``` +for (let i1 = 0; i1 < 8; i1++) { + basic.showNumber(i1, 150) // *** + basic.pause(2000) +} +``` + +* Run the program now to see your changes. + +### Challenge 2 + +### @video td/videos/looper-2 + +What about 9? Let's do that by changing the ending value to `10`. + +``` +for (let i2 = 0; i2 < 10; i2++) { + basic.showNumber(i2, 150) + basic.pause(2000) +} +``` + +* Run your code to see the new counter. + +### Challenge 3 + +### @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 `basic->show number`. + +``` +for (let i3 = 0; i3 < 8; i3++) { + basic.showNumber(i3 + 3, 150) // *** + basic.pause(2000) +} +``` + +Run it on the simulator! + +### Challenge 4 + +### @video td/videos/looper-4 + +Now, let's **count down from 9**. Change the line `basic->show number(i + 3, 150)` to `basic->show number(9 - i, 150)`. + +``` +for (let i4 = 0; i4 < 10; i4++) { + basic.showNumber(9 - i4, 150) // *** + basic.pause(2000) +} +``` + +* Run the code to make sure it is doing what is expected. + +### Challenge 5 + +After counting down from `9` let's show the string `BOOOM`! + diff --git a/docs/reference/js/lessons/looper/lesson.md b/docs/reference/js/lessons/looper/lesson.md new file mode 100644 index 00000000..4a95fe63 --- /dev/null +++ b/docs/reference/js/lessons/looper/lesson.md @@ -0,0 +1,105 @@ +# looper lesson + +Learn to control blinking LEDs. #LED #screen #for #docs + +### @video vimeo/134453504 + +## Topic + +For loop - Blinking LED + +## Quick links + +* [tutorial](/microbit/lessons/looper/tutorial) +* [quiz](/microbit/lessons/looper/quiz) +* [quiz answers](/microbit/lessons/looper/quiz-answers) +* [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. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces a While Loop. While Loop is a while loop that will repeat code forever while - true. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **plot**: [read more...](/microbit/reference/led/plot) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **for**: [read more...](/microbit/reference/loops/for) + +## Resources + +* Activity: [tutorial](/microbit/lessons/looper/tutorial) +* Activity: [quiz](/microbit/lessons/looper/quiz) +* Extended Activity: [challenges](/microbit/lessons/looper/challenges) + +## Objectives + +* learn how to blink a light +* create a for loop that will loop through each x-value, y-value from 0 to 4. +* learn how to pause the light on and off +* learn how to repeat turning on and off the light + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses logical reasoning to predict outputs, showing an awareness of inputs. (AL) +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Uses a variable and relational operators within a loop to govern termination. (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 10 min. +* [tutorial](/microbit/lessons/looper/tutorial) +* [quiz](/microbit/lessons/looper/quiz) +* assessment opportunities: loops, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/looper/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/looper/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/looper/quiz-answers.md b/docs/reference/js/lessons/looper/quiz-answers.md new file mode 100644 index 00000000..60d928bf --- /dev/null +++ b/docs/reference/js/lessons/looper/quiz-answers.md @@ -0,0 +1,40 @@ +# looper quiz answers + +Learn how to create a series of numbers with a for loop. #LED #screen #plot #docs + +This is the answer key for the [looper quiz](/microbit/lessons/looper/quiz). + +## 1. What is a for loop? + +Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates. + +## 2. Consider the following code + +``` +for (let i = 0; i < 4; i++) { + basic.showNumber(i, 150) +} +``` + +If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded. + +Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `4` 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 = 4`. + +![](/static/mb/lessons/looper-0.png) + +## 3. Consider the following code + +``` +for (let i1 = 0; i1 < 6; i1++) { + basic.showNumber(i1, 150) +} +``` + +If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded. + +Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `6` 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 = 6`. + +![](/static/mb/lessons/looper-0.png) + +![](/static/mb/lessons/looper-1.png) + diff --git a/docs/reference/js/lessons/looper/quiz.md b/docs/reference/js/lessons/looper/quiz.md new file mode 100644 index 00000000..61663a60 --- /dev/null +++ b/docs/reference/js/lessons/looper/quiz.md @@ -0,0 +1,42 @@ +# looper quiz + +Learn how to create a series of numbers with a for loop. #LED #screen #plot #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [looper tutorial](/microbit/lessons/looper/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what a "for loop" does? + +
+ +## 2. Draw the areas where the LEDs will be lit based on the code below. Explain why you chose to draw those numbers. + +``` +for (let i = 0; i < 4; i++) { + basic.showNumber(i, 150) +} +``` + +![](/static/mb/lessons/looper-2.png) + +
+ +## 3. Draw the areas where the LEDs will be lit based on the code below. Explain why you chose to draw those numbers. + +``` +for (let i1 = 0; i1 < 6; i1++) { + basic.showNumber(i1, 150) +} +``` + +![](/static/mb/lessons/looper-3.png) + +![](/static/mb/lessons/looper-3.png) + +
+ diff --git a/docs/reference/js/lessons/love-meter.md b/docs/reference/js/lessons/love-meter.md new file mode 100644 index 00000000..3cb0c03d --- /dev/null +++ b/docs/reference/js/lessons/love-meter.md @@ -0,0 +1,104 @@ +# love meter 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) +* [challenges](/microbit/lessons/love-meter/challenges) +* [quiz](/microbit/lessons/love-meter/quiz) +* [quiz answers](/microbit/lessons/love-meter/quiz-answers) +* [tutorial](/microbit/lessons/love-meter/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use the pins **pin pressed**, `input->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. + +## 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) + +## 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) +* [tutorial](/microbit/lessons/love-meter/tutorial) +* [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) + diff --git a/docs/reference/js/lessons/love-meter/activity.md b/docs/reference/js/lessons/love-meter/activity.md new file mode 100644 index 00000000..1488eca0 --- /dev/null +++ b/docs/reference/js/lessons/love-meter/activity.md @@ -0,0 +1,44 @@ +# love meter activity + +create a love meter with the BBC micro:bit #docs + +### ~avatar avatar + +### @video td/videos/love-meter-0 + +Welcome! This tutorial will help you create a love meter with the BBC 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 **Touch Develop**. + +Begin by registering an event with `input->on pin pressed(PO)` to know when someone is holding pin ``P0`` and pin ``Gnd``. + +``` +input.onPinPressed("P0", () => { +}) +``` + +We are going to create a meter that displays a random number from 0 to 10. We use ``11`` as `math->random(n)` returns a number between ``0`` and ``n-1``. + +``` +input.onPinPressed("P0", () => { + let x = Math.random(11) +}) +``` + +Finally, let's show that number on the micro:bit. + +``` +input.onPinPressed("P0", () => { + let x_ = Math.random(11) + basic.showNumber(x_, 150) +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/love-meter/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/love-meter/challenges.md b/docs/reference/js/lessons/love-meter/challenges.md new file mode 100644 index 00000000..8f5ba4ee --- /dev/null +++ b/docs/reference/js/lessons/love-meter/challenges.md @@ -0,0 +1,72 @@ +# love meter challenges + +create a love meter with the BBC micro:bit #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/love-meter/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +input.onPinPressed("P0", () => { + let x = Math.random(11) + basic.showNumber(x, 150) +}) +``` + +### 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. + +``` +input.onPinPressed("P0", () => { + let x1 = Math.random(11) + basic.showNumber(x1, 150) + basic.pause(3000) // *** +}) +``` + +### Challenge 2 + +If the rating **x** is between ``0`` and ``3`` (strictly less than ``4``), display the text "HORRIBLE!". + +``` +input.onPinPressed("P0", () => { + let x2 = Math.random(11) + basic.showNumber(x2, 150) + basic.pause(3000) + if (x2 < 4) { + basic.showString("HORRIBLE!", 150) // *** + } +}) +``` + +### 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!" + +``` +input.onPinPressed("P0", () => { + let x3 = Math.random(11) + basic.showNumber(x3, 150) + basic.pause(3000) + if (x3 < 4) { + basic.showString("HORRIBLE!", 150) // *** + } else if (x3 < 8) { + basic.showString("MEDIOCRE!", 150) // *** + } + else { + basic.showString("MATCHED!", 150) // *** + } +}) +``` + +### Challenge 4 + +Use `basic->plot image` or `basic->show animation` to display images and animations instead of text for each case. + diff --git a/docs/reference/js/lessons/love-meter/quiz-answers.md b/docs/reference/js/lessons/love-meter/quiz-answers.md new file mode 100644 index 00000000..b673e707 --- /dev/null +++ b/docs/reference/js/lessons/love-meter/quiz-answers.md @@ -0,0 +1,45 @@ +# love meter quiz answers + +The answers to the love meter quiz. #LED #screen #variables #docs + +This is the answer key for the [love meter quiz](/microbit/lessons/love-meter/quiz). + +## 1. What does on pin pressed ("P0") do? + +
+ +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. Create a condition for on pin pressed ("P1"). + +``` +input.onPinPressed("P1", () => { +}) +``` + +## 3. What does this line of code generate? + +``` +let x = Math.random(10) +``` + +
+ +It generates a random number between 0 and 9 then stores that number in a variable. + +## 4. Why do you have to add 1 to variable x? + +``` +x = x + 1 +``` + +
+ +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 BBC micro:bit? + +
+ +You have told GND to complete the circuit. + diff --git a/docs/reference/js/lessons/love-meter/quiz.md b/docs/reference/js/lessons/love-meter/quiz.md new file mode 100644 index 00000000..8a2e4fe6 --- /dev/null +++ b/docs/reference/js/lessons/love-meter/quiz.md @@ -0,0 +1,41 @@ +# love meter quiz + +Learn how to make a love meter that you can try with someone. #LED #screen #variables #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [love meter tutorial](/microbit/lessons/love-meter/tutorial). + +Answer the questions below while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what "input -> on pin pressed (P0)" does? + +
+ +## 2. Create a condition for on pin pressed ("P1"). + +
+ +## 3. Describe what this line of code does? + +``` +let x = Math.random(10) +``` + +
+ +## 4. Describe what adding 1 to variable x does? + +``` +let x_ = Math.random(10) +x = x + 1 +``` + +
+ +## 5. Describe why you must hold ground (GND) before pressing (P0) to run a program using "input -> on pin pressed (P0)" on the BBC micro:bit + +
+ diff --git a/docs/reference/js/lessons/lucky-7.md b/docs/reference/js/lessons/lucky-7.md new file mode 100644 index 00000000..b0913a63 --- /dev/null +++ b/docs/reference/js/lessons/lucky-7.md @@ -0,0 +1,84 @@ +# lucky 7 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) +* [tutorial](/microbit/lessons/lucky-7/tutorial) + +## Class + +Year 7 + +## Prior learning / place of lesson in scheme of work + +Learn how to display a number, `basic-> show number` to generate numbers. We will be learning how to create numbers using show number and pause. + +## Documentation + +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## 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) +* [tutorial](/microbit/lessons/lucky-7/tutorial) +* [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) + diff --git a/docs/reference/js/lessons/lucky-7/activity.md b/docs/reference/js/lessons/lucky-7/activity.md new file mode 100644 index 00000000..f21f02e4 --- /dev/null +++ b/docs/reference/js/lessons/lucky-7/activity.md @@ -0,0 +1,26 @@ +# lucky 7 activity + +show a number on the LED screen. #docs #tutorials #stepByStep + +### ~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 **Touch Develop**. + +We will use `basic->show number` to display a number on the screen. The first argument (`7`) is the number to display and the second argument (`150`) is duration in milliseconds between column scroll. For example, you can reduce `150` to `100` to speed up the scrolling. + +``` +basic.showNumber(7, 150) // *** +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/lucky-7/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/lucky-7/challenges.md b/docs/reference/js/lessons/lucky-7/challenges.md new file mode 100644 index 00000000..8ee73880 --- /dev/null +++ b/docs/reference/js/lessons/lucky-7/challenges.md @@ -0,0 +1,39 @@ +# lucky 7 challenges + +Coding challenges for the lucky 7 tutorial. #docs + +## Before we get started + +Complete the [lucky 7](/microbit/lessons/lucky-7/activity) activity and your code will look like this: + +``` +basic.showNumber(7, 150) +``` + +### Challenge 1 + +But we also should pause before showing another number. Let's add a pause of 500 milliseconds. + +``` +basic.showNumber(7, 150) +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! + +``` +basic.showNumber(7, 150) +basic.pause(500) +basic.showNumber(14, 150) // *** +``` + +* 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! + diff --git a/docs/reference/js/lessons/lucky-7/quiz-answers.md b/docs/reference/js/lessons/lucky-7/quiz-answers.md new file mode 100644 index 00000000..1a6350ff --- /dev/null +++ b/docs/reference/js/lessons/lucky-7/quiz-answers.md @@ -0,0 +1,38 @@ +# lucky 7 quiz answers + +Show a number on the BBC micro:bit. #LED #screen #show #math #docs #input + +This is the answer key for the [lucky 7 quiz](/microbit/lessons/lucky-7/quiz). + +## 1. Describe what `basic->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 + +``` +basic.showNumber(7, 150) +``` + +
+ +![](/static/mb/lessons/lucky-7-0.png) + +## 3. Draw every LED that is ON after running this code + +``` +basic.showNumber(21, 150) +``` + +![](/static/mb/lessons/lucky-7-1.png) + +## 4. Write the code that will be used to display the number 3 on the BBC micro:bit. + +![](/static/mb/lessons/lucky-7-2.png) + +
+ +``` +basic.showNumber(3, 150) +``` + diff --git a/docs/reference/js/lessons/lucky-7/quiz.md b/docs/reference/js/lessons/lucky-7/quiz.md new file mode 100644 index 00000000..1e2f6059 --- /dev/null +++ b/docs/reference/js/lessons/lucky-7/quiz.md @@ -0,0 +1,44 @@ +# lucky 7 quiz + +Show a number on the BBC micro:bit. #LED #screen #show #math #docs #input + +## Name + +## Directions + +Use this activity document to guide your work in the [lucky 7 tutorial](/microbit/lessons/lucky-7/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what "basic->show number" does? + +
+ +## 2. Draw every LED that is ON after running this code + +``` +basic.showNumber(7, 150) +``` + +![](/static/mb/empty-microbit.png) + +
+ +## 3. Draw every LED that is ON after running this code + +``` +basic.showNumber(21, 150) +``` + +![](/static/mb/lessons/answering-machine-4.png) + +
+ +## 4. Write the code that will be used to display the number 3 on the BBC micro:bit. + +![](/static/mb/lessons/lucky-7-3.png) + +
+ +
+ diff --git a/docs/reference/js/lessons/magic-8-ball/challenges.md b/docs/reference/js/lessons/magic-8-ball/challenges.md new file mode 100644 index 00000000..f11bbe9a --- /dev/null +++ b/docs/reference/js/lessons/magic-8-ball/challenges.md @@ -0,0 +1,109 @@ +# magic 8 challenges + +Coding challenges for the magic 8 tutorial #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/magic-8-ball/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() + let randomNumber = Math.random(3) + if (randomNumber == 2) { + basic.showString("Yes", 150) + } else if (randomNumber == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**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 `math->random` to 5. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() + let randomNumber1 = Math.random(5) // *** + if (randomNumber1 == 2) { + basic.showString("Yes", 150) + } else if (randomNumber1 == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**Challenge 2** + +Now have the magic 8 ball respond "Try again" if **randomNumber** is 3. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() + let randomNumber2 = Math.random(5) + if (randomNumber2 == 3) { + basic.showString("Try again", 150) // *** + } else if (randomNumber2 == 2) { + basic.showString("Yes", 150) + } + else if (randomNumber2 == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**Challenge 3** + +Now what about if **randomNumber** is 4? Let's have the magic 8 ball respond "Definitely!". + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() + let randomNumber3 = Math.random(5) + if (randomNumber3 == 4) { + basic.showString("Definitely!", 150) // *** + } else if (randomNumber3 == 3) { + basic.showString("Try again", 150) + } + else if (randomNumber3 == 2) { + basic.showString("Yes", 150) + } + else if (randomNumber3 == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**Challenge 4** + +Add 3 more responses so your magic 8 ball has 8 possible responses. Be creative! + diff --git a/docs/reference/js/lessons/magic-8.md b/docs/reference/js/lessons/magic-8.md new file mode 100644 index 00000000..49650981 --- /dev/null +++ b/docs/reference/js/lessons/magic-8.md @@ -0,0 +1,102 @@ +# magic 8 lesson + +a fortune teller game with the BBC micro:bit #string #shake #clear-screen #if #string #number #var #docs + +### @video td/videos/magic-8-1 + +## Topic + +If (Conditionals) + +## Quick Links + +* [activity](/microbit/lessons/magic-8/activity) +* [quiz](/microbit/lessons/magic-8/quiz) +* [quiz answers](/microbit/lessons/magic-8/quiz-answers) +* [challenges](/microbit/lessons/magic-8/challenges) +* [tutorial](/microbit/lessons/magic-8/tutorial) + +## 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) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **random number** : [read more...](/microbit/js/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) +* [tutorial](/microbit/lessons/magic-8/tutorial) +* [quiz](/microbit/lessons/magic-8/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/magic-8/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/magic-8/challenges) + diff --git a/docs/reference/js/lessons/magic-8/activity.md b/docs/reference/js/lessons/magic-8/activity.md new file mode 100644 index 00000000..e80874b2 --- /dev/null +++ b/docs/reference/js/lessons/magic-8/activity.md @@ -0,0 +1,114 @@ +# magic 8 activity + +a fortune teller game on the BBC micro:bit #docs + +### ~avatar avatar + +Welcome! This tutorial will help you create a magic 8 ball on the BBC 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 **Touch Develop**. + +Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer true or false questions. + +``` +basic.showString("Ask a question", 150) +``` + +Display the number 8. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +``` + +* Run your program + +Register code to run when the BBC micro:bit is shaken. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { +}) +``` + +Create a variable of type number called **x**. + +Set **x** equal to a random number with a limit of 3. + +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. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x = Math.random(3) +}) +``` + +Create an if statement for the condition `if x= 2`. + +If **x** is 2, display the string 'Yes' + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x1 = Math.random(3) + if (x1 == 2) { + basic.showString("Yes", 150) + } +}) +``` + +Create an if statement for the condition `if x = 1`. + +If ``x`` is 1, display the string 'No' + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x2 = Math.random(3) + if (x2 == 2) { + basic.showString("Yes", 150) + } else if (x2 == 1) { + basic.showString("No", 150) + } +}) +``` + +If **x** is not 2 or 1, it must be 0. This is the else condition. + +If **x** is 0, display the string 'I don't know' + +Display the number 8 so users know they can ask the magic 8 ball another question! + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() + let randomNumber = Math.random(3) + if (randomNumber == 2) { + basic.showString("Yes", 150) + } else if (randomNumber == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +* Run your program + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/magic-8/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/magic-8/challenges.md b/docs/reference/js/lessons/magic-8/challenges.md new file mode 100644 index 00000000..87a59ea4 --- /dev/null +++ b/docs/reference/js/lessons/magic-8/challenges.md @@ -0,0 +1,105 @@ +# magic 8 challenges + +Coding challenges for the magic 8 tutorial #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/magic-8-ball/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x = Math.random(3) + if (x == 2) { + basic.showString("Yes", 150) + } else if (x == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**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 `math->random` to 5. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x1 = Math.random(5) // *** + if (x1 == 2) { + basic.showString("Yes", 150) + } else if (x1 == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**Challenge 2** + +Now have the magic 8 ball respond ``"Try again"`` if ``x`` is 3. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x2 = Math.random(5) + if (x2 == 3) { + basic.showString("Try again", 150) // *** + } else if (x2 == 2) { + basic.showString("Yes", 150) + } + else if (x2 == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**Challenge 3** + +Now what about if ``x`` is 4? Let's have the magic 8 ball respond ``"Definitely!"``. + +``` +basic.showString("Ask a question", 150) +basic.showNumber(8, 150) +input.onGesture(Gesture.Shake, () => { + let x3 = Math.random(5) + if (x3 == 4) { + basic.showString("Definitely!", 150) // *** + } else if (x3 == 3) { + basic.showString("Try again", 150) + } + else if (x3 == 2) { + basic.showString("Yes", 150) + } + else if (x3 == 1) { + basic.showString("No", 150) + } + else { + basic.showString("I don't know", 150) + } + basic.showNumber(8, 150) +}) +``` + +**Challenge 4** + +Add 3 more responses so your magic 8 ball has 8 possible responses. Be creative! + diff --git a/docs/reference/js/lessons/magic-8/quiz-answers.md b/docs/reference/js/lessons/magic-8/quiz-answers.md new file mode 100644 index 00000000..9503cc01 --- /dev/null +++ b/docs/reference/js/lessons/magic-8/quiz-answers.md @@ -0,0 +1,57 @@ +# magic 8 quiz answers + +create a magic 8 ball on the BBC micro:bit #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [magic 8 tutorial](/microbit/lessons/magic-8/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Define what an 'if statement' is. + +
+ +An if statement will conditionally run code depending on whether or not a condition is true. + +## 2. Create a Variable called ``x`` and assign it to a random number between 0 and 2. + +``` +let x = Math.random(3) +``` + +## 3. Write the 'if statement' to check if ``x`` is equal to 2. Inside the 'if statement', display the string "Yes". + +``` +if (x == 2) { + basic.showString("Yes", 150) +} +``` + +## 3. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No." + +``` +if (x == 2) { + basic.showString("Yes", 150) +} else if (x == 1) { + basic.showString("No", 150) +} +``` + +## 5. Write the code to display the string "I don't know" if the Variable ``x`` is neither 2 nor 1. + +``` +if (x == 2) { + basic.showString("Yes", 150) +} else if (x == 1) { + basic.showString("No", 150) +} +else { + basic.showString("I don't know", 150) +} +``` + +Note: Students are only required to write the bottom half of this answer (starting with "else"). + diff --git a/docs/reference/js/lessons/magic-8/quiz.md b/docs/reference/js/lessons/magic-8/quiz.md new file mode 100644 index 00000000..317adce7 --- /dev/null +++ b/docs/reference/js/lessons/magic-8/quiz.md @@ -0,0 +1,32 @@ +# magic 8 quiz + +create a magic 8 ball on the BBC micro:bit #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [magic 8 tutorial](/microbit/lessons/magic-8/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Define what an 'if statement' is. + +
+ +## 2. Create a Variable called ``x`` and assign it to a random number between 0 and 2. + +
+ +## 3. Write the 'if statement' to check if ``x`` is equal to 2. Inside the 'if statement', display the string "Yes". + +
+ +## 3. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No." + +
+ +## 5. Write the code to display the string "I don't know" if the Variable ``x`` is neither 2 nor 1. + +
+ diff --git a/docs/reference/js/lessons/magic-logo.md b/docs/reference/js/lessons/magic-logo.md new file mode 100644 index 00000000..85bd36c0 --- /dev/null +++ b/docs/reference/js/lessons/magic-logo.md @@ -0,0 +1,83 @@ +# 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) +* [quiz](/microbit/lessons/magic-logo/quiz) +* [quiz answers](/microbit/lessons/magic-logo/quiz-answers) +* [challenges](/microbit/lessons/magic-logo/challenges) +* [tutorial](/microbit/lessons/magic-logo/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to plot image **on logo up**, `input->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 input logo up, basic plot image, and input 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 + +* 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) +* 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) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises the audience when designing and creating digital content (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-logo/activity) +* [quiz](/microbit/lessons/magic-logo/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/magic-logo/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/magic-logo/challenges) + diff --git a/docs/reference/js/lessons/magic-logo/activity.md b/docs/reference/js/lessons/magic-logo/activity.md new file mode 100644 index 00000000..8341266e --- /dev/null +++ b/docs/reference/js/lessons/magic-logo/activity.md @@ -0,0 +1,41 @@ +# magic logo activity + +show an image that points up when the logo is up. #docs #microbit + +### ~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 BBC micro:bit can detect when the **logo** is oriented **up**. We call that the **logo up** event. We will use `input->on logo up` to register an event handler that will run when the **logo up** event happens. + +``` +input.onLogoUp(() => { +}) // *** +``` + +When the BBC micro:bit goes logo up, the code nested under the `basic->on logo up` function will run. Let's add a line of code to plot an image in there. + +``` +input.onLogoUp(() => { + basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) // *** +}) +``` + +Run your code and try to turn around the BBC 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)! + +### ~ + diff --git a/docs/reference/js/lessons/magic-logo/challenges.md b/docs/reference/js/lessons/magic-logo/challenges.md new file mode 100644 index 00000000..6beb58aa --- /dev/null +++ b/docs/reference/js/lessons/magic-logo/challenges.md @@ -0,0 +1,55 @@ +# magic logo challenges + +Coding challenges for the magic logo tutorial. #docs + +## Before we get started + +Complete the [magic logo](/microbit/lessons/magic-logo/activity) activity and your code will look like this: + +``` +input.onLogoUp(() => { + basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +}) +``` + +### Challenge 1 + +How about when the logo is down? We should display an arrow pointing downward! + +### @video td/videos/magic-logo-1-2 + +``` +input.onLogoUp(() => { + basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +}) +input.onLogoDown(() => { + basic.plotImage(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`) // *** +}) // *** +``` + +### Challenge 2 + +Use the `input->on screen up` event to show a spinning arrow when the screen is turned up. + +### Challenge 3 + +Display another animation using the `input->on screen up` event. + diff --git a/docs/reference/js/lessons/magic-logo/quiz-answers.md b/docs/reference/js/lessons/magic-logo/quiz-answers.md new file mode 100644 index 00000000..1202ff32 --- /dev/null +++ b/docs/reference/js/lessons/magic-logo/quiz-answers.md @@ -0,0 +1,51 @@ +# magic logo quiz answers + +show an image that points up when the logo is up #logo #show #create #docs + +## Name + +## Directions + +This is the answer key for the [magic logo quiz](/microbit/lessons/magic-logo/quiz) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Define 'on logo up' + +A function that will run code when the BBC micro:bit screen is facing up and vertically orientated. + +
+ +## 2. Consider the following directions + +Write the condition that detects when the BBC micro:bit logo is facing up and vertically orientated. + +
+ +``` +input.onLogoUp(() => { +}) +``` + +
+ +## 3. Consider the following animation + +![](/static/mb/lessons/magic-logo-0.png) + +Write the code to display a downward pointing arrow when the logo is down. + +
+ +``` +input.onLogoDown(() => { + basic.plotImage(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`) +}) +``` + diff --git a/docs/reference/js/lessons/magic-logo/quiz.md b/docs/reference/js/lessons/magic-logo/quiz.md new file mode 100644 index 00000000..f777c325 --- /dev/null +++ b/docs/reference/js/lessons/magic-logo/quiz.md @@ -0,0 +1,26 @@ +# magic logo quiz + +show an image that points up when the logo is up #logo #show #create #docs + +## Name + +## Directions + +Use the hints from the [magic logo activity](/microbit/lessons/magic-logo/activity) to answer this quiz! + +## 1. Define what `input->on logo up` does + +
+ +## 2. The `logo up` event is raised when... + +* the screen is facing up and the board is horizontal +* the screen is facing down and the board is horizontal +* the board is vertical and the logo is facing up + +## 3. Consider the following animation + +![](/static/mb/lessons/magic-logo-0.png) + +Write the code to display a downward pointing arrow when the BBC micro:bit logo is down. + diff --git a/docs/reference/js/lessons/meteorite.md b/docs/reference/js/lessons/meteorite.md new file mode 100644 index 00000000..ad6b068e --- /dev/null +++ b/docs/reference/js/lessons/meteorite.md @@ -0,0 +1,99 @@ +# meteorite lesson + +a game in which you must dodge the meteorites with your ship. #functions #data #forever #var #button #if #assignment #plot-all #pause #string #number #docs + +## Topic + +Functions + +## Quick Links + +* [tutorial](/microbit/lessons/meteorite/tutorial) +* [quiz](/microbit/lessons/meteorite/quiz) +* [quiz answers](/microbit/lessons/meteorite/quiz-answers) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a meteorite game using functions, forever loop, global variables, for loop, input on button pressed, if statements, math random, input on shake as well as simple commands, such as show string, show number, and pause. + +## Documentation + +* **function** : [read more...](/microbit/js/function) +* **call** : [read more...](/microbit/js/call) +* **global variable** : [read more...](/microbit/js/data) +* **arithmetic operators** : [read more...](/microbit/reference/types/number) +* **math random** : [read more...](/microbit/js/math) +* **forever** : [read more...](/microbit/reference/basic/forever) +* **for** : [read more...](/microbit/reference/loops/for) +* **fade out** : [read more...](/microbit/reference/led/fade-out) +* **fade in** : [read more...](/microbit/reference/led/fade-in) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **if** : [read more...](/microbit/reference/logic/if) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **plot** : [read more...](/microbit/reference/led/plot) +* **plot all** : [read more...](/microbit/reference/led/plot-all) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to create a function as a unit of code that performs a specific task and returns a result +* learn how to call an existing function in your script +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how arithmetic operators operate on numbers and return a number +* learn how to return a random number +* learn how to repeat code in the background forever +* learn how to gradually decrease the LED screen brightness until the LED lights are turned off +* learn how to gradually increase the LED screen brightness until the LED lights are turned on +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to run code when an input button is pressed +* learn how to show a number on the micro:bit's LED screen +* learn how to show a string on the micro:bit's LED screen +* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates +* learn how to turn on all the 25 LEDs on the LED screen +* learn how to pause your code for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Defines data types: real numbers and Boolean (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/meteorite/tutorial) + +## Extended Activity + +* time: 20 min. +* [quiz](/microbit/lessons/meteorite/quiz) + +## Homework + +* Extended Activity: [quiz](/microbit/lessons/meteorite/quiz) + diff --git a/docs/reference/js/lessons/meteorite/quiz-answers.md b/docs/reference/js/lessons/meteorite/quiz-answers.md new file mode 100644 index 00000000..2fc38c69 --- /dev/null +++ b/docs/reference/js/lessons/meteorite/quiz-answers.md @@ -0,0 +1,88 @@ +# meteorite quiz answers + +create the game meteorite #LED #number #math #acceleration #docs + +## Name + +## Directions + +This is the answer key for the [meteorite quiz](/microbit/lessons/meteorite/quiz) + +## 1. Write the code that sets up the position variables of meteorite 1. (Hint: look inside the function "initialize game".) + +
+ +``` +meteorite_1X = Math.random(5) +meteorite_1Y = -4 +``` + +## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".) + +
+ +``` +led.plot(shipLeftX, 4) +led.plot(shipLeftX + 1, 4) +``` + +## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1". + +
+ +``` +if (meteorite_1X == 4 && (shipLeftX == meteorite_1X || shipLeftX + 1 == meteorite_1X)) { + gameOver() +} +``` + +## 4. Write the code that increase the difficulty by making the game run faster. + +
+ +``` +pauseDifficulty = (pauseDifficulty * 49) / 50 +``` + +## 5. Write the code that moves the ship left. + +
+ +``` +led.unplot(shipLeftX + 1, 4) +shipLeftX = shipLeftX - 1 +led.plot(shipLeftX, 4) +``` + +## 6. Write the code that moves the ship right. + +
+ +``` +led.unplot(shipLeftX, 4) +shipLeftX = shipLeftX + 1 +led.plot(shipLeftX + 1, 4) +``` + +## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1. + +
+ +``` +if (shipLeftX == meteorite_1X && meteorite_1Y == 4) { + gameOver() +} +``` + +## 8. Write the code that flashes all the LEDs thee times to create the effect of a crash. (Hint: look at the function "game over".) + +
+ +``` +led.plotAll() +for (let i = 0; i < 3; i++) { + led.fadeIn(400) + led.fadeOut(400) +} +``` + diff --git a/docs/reference/js/lessons/meteorite/quiz.md b/docs/reference/js/lessons/meteorite/quiz.md new file mode 100644 index 00000000..ff760adb --- /dev/null +++ b/docs/reference/js/lessons/meteorite/quiz.md @@ -0,0 +1,44 @@ +# meteorite quiz + +create the game meteorite #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [meteorite tutorial](/microbit/lessons/meteorite/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that sets up the position variables of meteorite 1. (Hint: look inside the function "initialize game".) + +
+ +## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".) + +
+ +## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1". + +
+ +## 4. Write the code that increase the difficulty by making the game run faster. + +
+ +## 5. Write the code that moves the ship left. + +
+ +## 6. Write the code that moves the ship right. + +
+ +## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1. + +
+ +## 8. Write the code that flashes all the LEDs thee times to create the effect of a crash. (Hint: look at the function "game over".) + +
+ diff --git a/docs/reference/js/lessons/minesweeper.md b/docs/reference/js/lessons/minesweeper.md new file mode 100644 index 00000000..17d8d11c --- /dev/null +++ b/docs/reference/js/lessons/minesweeper.md @@ -0,0 +1,112 @@ +# minesweeper lesson + +A game that tests your memory for placing a LED mine then finding the hidden LED mine #var #data #if #random #min #max #mod #plot #unplot #pause #accceleration #docs + +### @video td/videos/minesweeper-0 + +## Topic + +Global Variables + +## Quick Links + +* [tutorial](/microbit/lessons/minesweeper/tutorial) +* [quiz](/microbit/lessons/minesweeper/quiz) +* [quiz answers](/microbit/lessons/minesweeper/quiz-answers) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a minesweeper game with **plot**, `led->plot` , **unplot**, `led->unplot`, **global variables** to keep track of the coordinates that the player is selecting. We will be learning how to create a minesweeper game using global variables, if (conditionals), input on button pressed, math random as well as simple commands such as led plot, led unplot, show string, and pause. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **global variables** : [read more...](/microbit/js/data) +* **math random number** : [read more...](/microbit/js/math) +* **plot** : [read more...](/microbit/reference/led/plot) +* **unplot** : [read more...](/microbit/reference/led/unplot) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **if** : [read more...](/microbit/reference/logic/if) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Resources + +* Activity: [tutorial](/microbit/lessons/minesweeper/tutorial) +* Activity: [quiz](/microbit/lessons/minesweeper/quiz) + +## Objectives + +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how to return a random number +* learn how to turn on a LED light on the LED screen +* learn how to turn off a LED light on the LED screen +* learn how to run code when an input button is pressed +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to show a string of the LED screen one character at a time (scrolling left to right) +* learn how to pause your code for the specified number of milliseconds + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/minesweeper/tutorial) +* [quiz](/microbit/lessons/minesweeper/quiz) + diff --git a/docs/reference/js/lessons/minesweeper/quiz-answers.md b/docs/reference/js/lessons/minesweeper/quiz-answers.md new file mode 100644 index 00000000..400f2f29 --- /dev/null +++ b/docs/reference/js/lessons/minesweeper/quiz-answers.md @@ -0,0 +1,55 @@ +# minesweeper quiz answers + +make a game to test your memory for placing a LED mine then finding the hidden LED mine #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [minesweeper tutorial](/microbit/lessons/minesweeper/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that randomly generates a number between 0 and 4 and stores that value in a global variable called 'mine x'. + +
+ +``` +mineX = Math.random(5) +``` + +## 2. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )` + +![](/static/mb/lessons/blink-1.png) + +
+ +``` +selectX = 0 +selectY = 0 +led.plot(selectX, selectY) +``` + +## 3. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )` + +![](/static/mb/lessons/blink-0.png) + +
+ +``` +selectX = 2 +selectY = 2 +led.plot(selectX, selectY) +``` + +## 4. How do you check if a dot is one away from given x and y coordinates? + +
+ +
+ +``` +if (mineX + 2 > selectX && selectX > mineX - 2 && mineY + 2 > selectY && selectY > mineY - 2) { +} +``` + diff --git a/docs/reference/js/lessons/minesweeper/quiz.md b/docs/reference/js/lessons/minesweeper/quiz.md new file mode 100644 index 00000000..5c71242a --- /dev/null +++ b/docs/reference/js/lessons/minesweeper/quiz.md @@ -0,0 +1,34 @@ +# minesweeper quiz + +make a game to test your memory for placing a LED mine then finding the hidden LED mine #math #random #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [minesweeper tutorial](/microbit/lessons/minesweeper/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that randomly generates a number between 0 and 4 and stores that value in a global variable called 'mine x'. + +
+ +## 2. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )` + +![](/static/mb/lessons/blink-1.png) + +
+ +## 3. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )` + +![](/static/mb/lessons/blink-0.png) + +
+ +## 4. How do you check if a dot is one away from given x and y coordinates? + +
+ +
+ diff --git a/docs/reference/js/lessons/night-light.md b/docs/reference/js/lessons/night-light.md new file mode 100644 index 00000000..035d7c1f --- /dev/null +++ b/docs/reference/js/lessons/night-light.md @@ -0,0 +1,75 @@ +# 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) +* [quiz](/microbit/lessons/night-light/quiz) +* [quiz answers](/microbit/lessons/night-light/quiz-answers) +* [challenges](/microbit/lessons/night-light/challenges) +* [tutorial](/microbit/lessons/night-light/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to **set brightness** of an image `led->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 plot all, input on button pressed as well as simple commands, such as LED set brightness. + +## Documentation + +* **set brightness** : [read more...](/microbit/reference/led/set-brightness) +* **plot all** : [read more...](/microbit/reference/led/plot-all) +* **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) +* [quiz](/microbit/lessons/night-light/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/night-light/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/night-light/challenges) + diff --git a/docs/reference/js/lessons/night-light/activity.md b/docs/reference/js/lessons/night-light/activity.md new file mode 100644 index 00000000..7bc00baf --- /dev/null +++ b/docs/reference/js/lessons/night-light/activity.md @@ -0,0 +1,45 @@ +# night light activity + +change the brightness of the BBC micro:bit. #docs #tutorials #stepByStep + +### ~avatar avatar + +### @video td/videos/night-light-0 + +Welcome! This tutorial will teach you how to change the brightness of the BBC micro:bit. Let's get started! + +### ~ + +The brightness of the LED screen can be changed by using the `led->set brightness` function. This function takes a number between ``0`` (off) and ``255`` (full brightness). + +Let's build a little app that dims the screen when pressing button ``A``. + +Add the code `led->plot all` to turn on all the LEDs. Don't hesitate to run your code to see what happens. + +``` +led.plotAll() // *** +``` + +The screen starts with a 50% brightness value by default (128). Add a new line of code to set the full brightness (255) using `led->set brightness`. + +``` +led.setBrightness(255) // *** +led.plotAll() +``` + +Add a new event handler for `input->on button pressed(A)` and add the code to set the brightness to `64`. + +``` +led.setBrightness(255) +led.plotAll() +input.onButtonPressed("A", () => { + led.setBrightness(64) // *** +}) // *** +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/night-light/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/night-light/challenges.md b/docs/reference/js/lessons/night-light/challenges.md new file mode 100644 index 00000000..4d6f73c9 --- /dev/null +++ b/docs/reference/js/lessons/night-light/challenges.md @@ -0,0 +1,42 @@ +# night light challenges + +Coding challenges for the night light tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/night-light/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +led.setBrightness(255) +led.plotAll() +input.onButtonPressed("A", () => { + led.setBrightness(64) +}) +``` + +### Challenge 1 + +### @video td/videos/night-light-2 + +What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add an event handler with `input->on button pressed(B)` add `led->set brightness(0)` to turn off the LEDs. + +``` +led.setBrightness(255) +led.plotAll() +input.onButtonPressed("A", () => { + led.setBrightness(64) +}) +input.onButtonPressed("B", () => { + led.setBrightness(0) // *** +}) // *** +``` + +**Challenge 3** + +Add an event handler with `input->on screen up` to change the LED brightness back to a `255`. + +* `Run main` your script to see the LEDs change brightness. diff --git a/docs/reference/js/lessons/night-light/quiz-answers.md b/docs/reference/js/lessons/night-light/quiz-answers.md new file mode 100644 index 00000000..2396e758 --- /dev/null +++ b/docs/reference/js/lessons/night-light/quiz-answers.md @@ -0,0 +1,46 @@ +# night light quiz answers + +Answers to the night light quiz. #LED #image #brightness #fade #docs + +This is the answer key for the [night light quiz](/microbit/lessons/night-light/quiz). + +## 1. Define the function "set brightness" + +This function sets the brightness of the LED screen. + +## 2. Consider the following image + +![](/static/mb/lessons/night-light-0.png) + +If the rectangle above represents the BBC micro:bit, write the code to set all the LEDs to full brightness and to turn on all the LEDs. + +
+ +``` +led.setBrightness(255) +led.plotAll() +``` + +## 3. Consider the following image + +![](/static/mb/lessons/night-light-1.png) + +If the rectangle above represents the BBC micro:bit, write the code to set the screen brightness to 50% (128) and turns on all the LEDs. + +
+ +``` +led.setBrightness(128) +led.plotAll() +``` + +## 4. Consider the following image + +![](/static/mb/lessons/night-light-2.png) + +If the rectangle above represents the BBC micro:bit, write the code to turn off all the LEDs. + +``` +led.setBrightness(0) +``` + diff --git a/docs/reference/js/lessons/night-light/quiz.md b/docs/reference/js/lessons/night-light/quiz.md new file mode 100644 index 00000000..0c6ce527 --- /dev/null +++ b/docs/reference/js/lessons/night-light/quiz.md @@ -0,0 +1,30 @@ +# night light quiz + +change the brightness of the BBC micro:bit #LED #image #brightness #fade #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [night light tutorial](/microbit/lessons/night-light/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what "led->set brightness" does ? + +## 2. If the picture below is the BBC micro:bit, write the code that sets all the LEDs to full brightness and turns on all the LEDs + +![](/static/mb/lessons/night-light-0.png) + +
+ +## 3. If the picture below is the BBC micro:bit, write the code that sets the screen brightness to 50% (128) and turns on all the LEDs. + +![](/static/mb/lessons/night-light-1.png) + +
+ +## 4. If the picture below is the BBC micro:bit, write the code turns off all the LEDs. + +![](/static/mb/lessons/night-light-2.png) + diff --git a/docs/reference/js/lessons/number-psych/quiz-answers.md b/docs/reference/js/lessons/number-psych/quiz-answers.md new file mode 100644 index 00000000..cf43a869 --- /dev/null +++ b/docs/reference/js/lessons/number-psych/quiz-answers.md @@ -0,0 +1,207 @@ +# number psych quiz answers + +a 4-player game in which each player must outwit his opponents. #math #random #docs #shake + +## Name + +## Directions + +Use this activity document to guide your work in the [number psych console tutorial](/microbit/lessons/number-psych-console/tutorial) and the [number psych controller tutorial](/microbit/lessons/number-psych-controller/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +**Questions 1-9 are concerned with 'number pysch console tutorial'** + +## 1. Create a 'collection of options' and save them in a local variable named 'options'. + +
+ +``` +let options = ([]) +``` + +## 2. Add the options '1', '3', and '5' into the local variable 'options'. + +
+ +``` +options.push(1) +options.push(3) +options.push(5) +``` + +## 3. Create a collection of scores and add four values of '0' into the collection. + +
+ +``` +let scores = ([]) +``` + +## 4. Write the code that reads a byte that indicates a controller is asking for a player number. (Don't bother checking if the byte received is 255.) Next, write the code that transfers the player number to the controller. + +
+ +``` +scores = ([]) +for (let i2 = 0; i2 < 4; i2++) { + scores.push(0) +} +``` + +## 5.Write the code that transfers the three options. + +
+ +``` +for (let i5 = 0; i5 < 3; i5++) { + micro_bitTransfer.transferByte(options[i5]) + basic.pause(200) +} +``` + +## 6.Write the code that requests each player to send their choice in the player order number. Don't worry about reading their choice. (Hint: look at the four loop with 'k' as the index.) + +
+ +``` +for (let k = 0; k < 4; k++) { + micro_bitTransfer.transferByte(101 + k) +} +``` + +## 7.Write the code to create two collections. One collection ("choices") stores all the choices, while the other collection ("has common") stores whether or not the choice is unique. (If the choice is not unique, then "has common" will be set to true for that particular choice.) + +
+ +``` +let choices = ([]) +let hasCommon = ([]) +``` + +## 8. Write the code that compares each of the choices with each other. If the two choices are the same, then set the appropriate value inside 'has common' to true. (Hint: look at the for loops with 'l' and 'n' as their indexes.) + +
+ +``` +for (let l = 0; l < 4; l++) { + for (let n = 0; n < 4; n++) { + // ### ~avatar avatar + // If the choice at `l` and `n` are the same, assuming `l` isn't equal to `n`, then there is a match. + // {stcode} + // MACRO: stcode + // ### ~ + if (choices[l] == choices[n] && ! (l == n)) { + // ### ~avatar avatar + // Set `has common` at `l` and `n` to true. + // {stcode} + // MACRO: stcode + // ### ~ + hasCommon[l] = true + hasCommon[n] = true + } + } +} +``` + +## 9. For each value inside 'has common', transfer a '1' if there is a match and transfer a '0' if there isn't a match. Add a pause of 100 milliseconds at the beginning of each transfer.) + +
+ +``` +for (let i4 = 0; i4 < 4; i4++) { + basic.pause(100) + if (hasCommon[i4]) { + micro_bitTransfer.transferBit(1) + } else { + micro_bitTransfer.transferBit(0) + } +} +``` + +**Questions 10-14 are concerned with 'number pysch controller tutorial'** + +## 10. Write the code that asks for a player number if button 'A' is pressed on the BBC controller micro:bit. + +
+ +``` +input.onButtonPressed("A", () => { + if (gameMode == 0 && playerNumber == 0) { + micro_bitTransfer.transferByte(255) + } +}) +``` + +## 11. Write the code that adds the three transferred options to the "options" collection. (Hint: look at the for loop with 'k' as the index.) + +
+ +``` +for (let k1 = 0; k1 < 3; k1++) { + options.push(micro_bitTransfer.readByte()) +} +``` + +## 12. Write the code that detects when button 'B' is pressed. Inside this condition, if 'game mode' is 2, set 'game mode' back to 1 and plot a waiting image. + +
+ +``` +input.onButtonPressed("B", () => { + if (gameMode == 2) { + gameMode = 1 + basic.plotImage(` +. . . . . +. . . . . +. # # # . +. . . . . +. . . . . +`) + } +}) +``` + +## 13. Create a while loop that first reads which controller the console micro:bit is requesting data from. Plot a waiting image, and then write an IF statement to check if the request corresponds to the controller. (Don't worry about writing anything inside the if statement). + +
+ +``` +while (true) { + let playerRequest = micro_bitTransfer.readByte() + basic.plotImage(` +. . . . . +. . . . . +. # # # . +. . . . . +. . . . . +`) + if (playerRequest == 100 + playerNumber) { + } +} +``` + +## 14. Write the code that displays an "X" on the BBC micro:bit if 'result' is 1. Otherwise, display a "check mark". + +
+ +``` +if (result == 1) { + basic.plotImage(` +# . . . # +. # . # . +. . # . . +. # . # . +# . . . # +`) +} else { + basic.plotImage(` +. . . . . +. . . . # +. . . # . +# . # . . +. # . . . +`) +} +``` + diff --git a/docs/reference/js/lessons/number-psych/quiz.md b/docs/reference/js/lessons/number-psych/quiz.md new file mode 100644 index 00000000..e9848f38 --- /dev/null +++ b/docs/reference/js/lessons/number-psych/quiz.md @@ -0,0 +1,116 @@ +# number psych quiz + +a 4-player game in which each player must outwit his opponents. #math #random #docs #shake + +## Name + +## Directions + +Use this activity document to guide your work in the [number psych console tutorial](/microbit/lessons/number-psych-console/tutorial) and the [number psych controller tutorial](/microbit/lessons/number-psych-controller/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +**Questions 1-9 are concerned with 'number pysch console tutorial'** + +## 1. Create a 'collection of options' and save them in a local variable named 'options'. + +
+ +## 2. Add the options '1', '3', and '5' into the local variable 'options'. + +
+ +
+ +## 3. Create a collection of scores and add four values of '0' into the collection. + +
+ +
+ +## 4. Write the code that reads a byte that indicates a controller is asking for a player number. (Don't bother checking if the byte received is 255.) Next, write the code that transfers the player number to the controller. + +
+ +
+ +
+ +## 5.Write the code that transfers the three options. + +
+ +
+ +## 6.Write the code that requests each player to send their choice in the player order number. Don't worry about reading their choice. (Hint: look at the four loop with 'k' as the index.) + +
+ +
+ +
+ +## 7.Write the code to create two collections. One collection ("choices") stores all the choices, while the other collection ("has common") stores whether or not the choice is unique. (If the choice is not unique, then "has common" will be set to true for that particular choice.) + +
+ +
+ +## 8. Write the code that compares each of the choices with each other. If the two choices are the same, then set the appropriate value inside 'has common' to true. (Hint: look at the for loops with 'l' and 'n' as their indexes.) + +
+ +
+ +
+ +
+ +
+ +
+ +## 9. For each value inside 'has common', transfer a '1' if there is a match and transfer a '0' if there isn't a match. Add a pause of 100 milliseconds at the beginning of each transfer.) + +
+ +
+ +
+ +**Questions 10-14 are concerned with 'number pysch controller tutorial'** + +## 10. Write the code that asks for a player number if button 'A' is pressed on the BBC controller micro:bit. + +
+ +
+ +## 11. Write the code that adds the three transferred options to the "options" collection. (Hint: look at the for loop with 'k' as the index.) + +
+ +
+ +
+ +## 12. Write the code that detects when button 'B' is pressed. Inside this condition, if 'game mode' is 2, set 'game mode' back to 1 and plot a waiting image. + +
+ +
+ +## 13. Create a while loop that first reads which controller the console micro:bit is requesting data from. Plot a waiting image, and then write an IF statement to check if the request corresponds to the controller. (Don't worry about writing anything inside the if statement). + +
+ +
+ +
+ +## 14. Write the code that displays an "X" on the BBC micro:bit if 'result' is 1. Otherwise, display a "check mark". + +
+ +
+ diff --git a/docs/reference/js/lessons/offset-image.md b/docs/reference/js/lessons/offset-image.md new file mode 100644 index 00000000..92cfbf60 --- /dev/null +++ b/docs/reference/js/lessons/offset-image.md @@ -0,0 +1,137 @@ +# offset image lesson + +shift an image horizontally across the display with offset #offset #image #docs + +### @video td/videos/offset-image-0 + +## Topic + +**If** Conditionals + +## Quick Links + +* [tutorial](/microbit/lessons/offset-image/tutorial) +* [quiz](/microbit/lessons/offset-image/quiz) +* [quiz answers](/microbit/lessons/offset-image/quiz-answers) +* [challenges](/microbit/lessons/offset-image/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to offset image with a conditional **If**, `if condition then` to run code depending on whether a condition is true or not. We will be learning how to offset image using a local variable, forever loop, the conditional If, input on button pressed, as well as simple commands, such as show string, create image and image show image. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Computational thinking: Thinking about systems or problems in a way that allows computer systems to be used to model or solve these. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Hardware: The physical systems and components of digital devices; see also software. +* Loop: A block of code repeated automatically under the program’s control. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Repetition: Executing a section of computer code a number of times as part of the program. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* ** global variables ** : [read more...](/microbit/js/data) +* ** assignment operator ** : [read more...](/microbit/reference/variables/assign) +* ** forever ** : [read more...](/microbit/reference/basic/forever) +* ** If ** : [read more...](/microbit/reference/logic/if) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **create image** : [read more...](/microbit/reference/images/create-image) +* **show image** : [read more...](/microbit/reference/images/show-image) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) + +## Resources + +* Activity: [tutorial](/microbit/lessons/offset-image/tutorial) +* Activity: [quiz](/microbit/lessons/offset-image/quiz) +* Extended Activity: [challenges](/microbit/lessons/offset-image/challenges) + +## Objectives + +* learn how to a create a global variable as a place where you can store and retrieve data, accessible across functions and in nested code blocks +* learn how to set and change the value of a global variable +* learn how to repeat code in the background forever +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to show a string on the LED screen +* learn how to create an Image to show on the micro:bit's LED screen +* learn how to show an Image on the micro:bit's LED screen +* learn how to run code when an input button is pressed + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (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) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* 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) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/offset-image/tutorial) +* [quiz](/microbit/lessons/offset-image/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/offset-image/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/offset-image/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/offset-image/challenges.md b/docs/reference/js/lessons/offset-image/challenges.md new file mode 100644 index 00000000..5d94f317 --- /dev/null +++ b/docs/reference/js/lessons/offset-image/challenges.md @@ -0,0 +1,98 @@ +# offset image challenges + +Coding challenges for the offset image tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/offset-image/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +offset = 0 +basic.forever(() => { + if (offset == -4) { + basic.showString("Push button A", 150) + } + images.createImage(` +. . # . . +. . # . . +. . # . . +. # # # . +. . # . . +`).showImage(offset) +}) +input.onButtonPressed("A", () => { + offset = offset + 1 +}) +``` + +### Challenge 1 + +Create a condition for if button `B` is pressed. We want the image to move to the left when button `B` is pressed. + +``` +offset = 0 +basic.forever(() => { + if (offset == -4) { + basic.showString("Push button A", 150) + } + images.createImage(` +. . # . . +. . # . . +. . # . . +. # # # . +. . # . . +`).showImage(offset) +}) +input.onButtonPressed("A", () => { + offset = offset + 1 +}) +input.onButtonPressed("B", () => { + offset = offset - 1 // *** +}) // *** +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +### @video td/videos/offset-image-2 + +Now we want to make sure that the button does not go off the screen to the right. Add a new line that checks to see if offset = 5 after button `A` is pressed. + +If `offset = 5` then prompt the user to move the image to the left by displaying the text: "Push button B". + +``` +offset = 0 +basic.forever(() => { + if (offset == -4) { + basic.showString("Push button A", 150) + } + if (offset == 5) { + basic.showString("Press Button B", 150) // *** + } + images.createImage(` +. . # . . +. . # . . +. . # . . +. # # # . +. . # . . +`).showImage(offset) +}) +input.onButtonPressed("A", () => { + offset = offset + 1 +}) +input.onButtonPressed("B", () => { + offset = offset - 1 +}) +``` + +* Run the code to see if it works as expected. + +**Challenge 3** + +Now make sure the image does not go off the left side and if it does, prompt the user to push button `A`. + diff --git a/docs/reference/js/lessons/offset-image/quiz-answers.md b/docs/reference/js/lessons/offset-image/quiz-answers.md new file mode 100644 index 00000000..e320c114 --- /dev/null +++ b/docs/reference/js/lessons/offset-image/quiz-answers.md @@ -0,0 +1,48 @@ +# offset image quiz answers + +shift an image horizontally across the display with offset #offset #screen #variables #docs + +This is the answer key for the [offset image quiz](/microbit/lessons/offset-image/quiz). + +## 1. What is a 'if, then, else statement' ? + +
+ +An if-then statement will run a block of code if the condition specified is true. The statement will run the "else" block of code if that condition is false. + +## 2. Consider the message + +Write the line of code that that will create the message "Push button A" (Hint: This message appears `if` the offset is equal -4 then the BBC micro:bit will state "Push Button A"). + +
+ +``` +if (offset == -4) { + basic.showString("Push Button A", 150) +} +``` + +## 3. Consider the following image + +![](/static/mb/lessons/offset-image-0.png) + +When with this image be displayed? + +
+ +When the offset is NOT equal to -4 then the BBC micro:bit will show the image above. + +## 4. Consider the following image + +![](/static/mb/lessons/offset-image-1.png) + +Write the two lines of code that cause the `variable` offset to increase by one when button `A` is pressed. + +
+ +``` +input.onButtonPressed("A", () => { + offset = offset + 1 +}) +``` + diff --git a/docs/reference/js/lessons/offset-image/quiz.md b/docs/reference/js/lessons/offset-image/quiz.md new file mode 100644 index 00000000..f616682a --- /dev/null +++ b/docs/reference/js/lessons/offset-image/quiz.md @@ -0,0 +1,36 @@ +# offset image quiz + +shift an image horizontally across the display with offset #offset #screen #variables #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [offset image tutorial](/microbit/lessons/offset-image/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is an 'if, then, else statement' ? + +
+ +## 2. Write the line condition that if true, will display the message "Push button A". This message appears if the offset is equal -4 then the BBC micro:bit will state "Push Button A". + +
+ +
+ +## 3. Write the one line of code to show this image + +![](/static/mb/lessons/offset-image-0.png) + +
+ +
+ +## 4. Write the two lines of code that trigger the variable offset to increase by one. + +![](/static/mb/lessons/offset-image-1.png) + +
+ diff --git a/docs/reference/js/lessons/on-fall/challenges.md b/docs/reference/js/lessons/on-fall/challenges.md new file mode 100644 index 00000000..0ada8bfc --- /dev/null +++ b/docs/reference/js/lessons/on-fall/challenges.md @@ -0,0 +1,69 @@ +# landslide challenges + +The on fall function. #onfall #docs + +### Challenge 0 + +Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/on-fall/tutorial) will show you how to detect when the micro:bit is falling. Your goal is to write a program that detects when the micro:bit falls! + +``` +input.onFall(() => { + images.createImage(` +. . # . . +. . # . . +. . # . . +. . . . . +. . # . . +`).showImage(0) // *** +}) +``` + +### Challenge 1 + +Add a pause within `input->on fall`. This will allow us to display another image in the next challenge. + +``` +input.onFall(() => { + images.createImage(` +. . # . . +. . # . . +. . # . . +. . . . . +. . # . . +`).showImage(0) + basic.pause(2000) // *** +}) +``` + +### Challenge 2 + +Create and display an `X` after the pause from Challenge 1 + +``` +input.onFall(() => { + images.createImage(` +. . # . . +. . # . . +. . # . . +. . . . . +. . # . . +`).showImage(0) + basic.pause(2000) + images.createImage(` +# . . . # +. # . # . +. . # . . +. # . # . +# . . . # +`).showImage(0) // *** +}) +``` + +### Challenge 3 + +Create a loop so that the micro:bit alternates between the exclamation point and "X" images when the micro:bit falls. You will need a `forever` loop and a pause at the end of the loop to do this. + +## See Also + +[on shake](/microbit/reference/input/on-gesture) + diff --git a/docs/reference/js/lessons/on-logo-up-and-down/challenges.md b/docs/reference/js/lessons/on-logo-up-and-down/challenges.md new file mode 100644 index 00000000..05c82b7a --- /dev/null +++ b/docs/reference/js/lessons/on-logo-up-and-down/challenges.md @@ -0,0 +1,67 @@ +# on logo up and down challenges + +My script. #docs + +**Challenge 0** + +This [guided tutorial](/microbit/zysycw) will help you display an arrow pointing the direction the logo is orientated! + +Let's display and upward pointing arrow when the logo is up! + +``` +input.onLogoUp(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`).showImage(0) +}) +``` + +**Challenge 1** + +How about when the logo is down? We should display the arrow pointing downward! + +Let's start by adding a condition for if the logo is down. + +``` +input.onLogoUp(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`).showImage(0) +}) +input.onLogoDown(() => { +}) +``` + +**Challenge 2** + +Now we need to display the arrow! + +``` +input.onLogoUp(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`).showImage(0) +}) +input.onLogoDown(() => { + images.createImage(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`).showImage(0) // *** +}) +``` + diff --git a/docs/reference/js/lessons/on-shake/challenges.md b/docs/reference/js/lessons/on-shake/challenges.md new file mode 100644 index 00000000..94646b1d --- /dev/null +++ b/docs/reference/js/lessons/on-shake/challenges.md @@ -0,0 +1,83 @@ +# flipping bird challenges + +These challenges will allow you to create and display a flipping image of a bird when the micro:bit is shaken. #docs + +### Challenge 0 + +### @video vimeo/134449611 + +Greetings! This [guided tutorial](/microbit/lessons/flipping-bird/tutorial) will begin to show you how to flip a bird. + +``` +counter = 0 +input.onGesture(Gesture.Shake, () => { + counter = counter + 1 + if (math.mod(counter, 2) == 1) { + images.createImage(` +# # . # # +. . # . . +. . . . . +. . . . . +. . . . . +`).showImage(0) + } +}) +``` + +### Challenge 1 + +We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case. + +``` +counter = 0 +input.onGesture(Gesture.Shake, () => { + counter = counter + 1 + if (math.mod(counter, 2) == 1) { + images.createImage(` +# # . # # +. . # . . +. . . . . +. . . . . +. . . . . +`).showImage(0) + } + if (math.mod(counter, 2) == 0) { + } +}) +``` + +### Challenge 2 + +Inside of that `if` statement you created in challenge 1, add `image->create image()->show image(0)` and display an upside down flying bird. + +``` +counter = 0 +input.onGesture(Gesture.Shake, () => { + counter = counter + 1 + if (math.mod(counter, 2) == 1) { + images.createImage(` +# # . # # +. . # . . +. . . . . +. . . . . +. . . . . +`).showImage(0) + } + if (math.mod(counter, 2) == 0) { + images.createImage(` +. . . . . +. . . . . +. . . . . +. . # . . +# # . # # +`).showImage(0) // *** + } +}) +``` + +* Run the code to see if it works as expected. + +### Challenge 3 + +Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display! + diff --git a/docs/reference/js/lessons/ornament-chain.md b/docs/reference/js/lessons/ornament-chain.md new file mode 100644 index 00000000..0b008445 --- /dev/null +++ b/docs/reference/js/lessons/ornament-chain.md @@ -0,0 +1,25 @@ +# ornament chain lesson + +display beautiful images on the BBC micro:bit #var #pause #docs + +## Topic + +Telegraph + +## Quick Links + +* [activity](/microbit/lessons/ornament-chain/activity) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to convert your BBC micro:bit into a telegraph using a second BBC micro:bit as well as pin P1, P2, 3V, GND, and crocodile clips (or spring clips). The connect BBC micro:bit uses pins P1, P2, 3V, GND. + +## Objectives + +* learn how to setup the BBC micro:bit with crocodile clips +* learn how to telegraph to another BBC micro:bit + diff --git a/docs/reference/js/lessons/ornament-chain/activity.md b/docs/reference/js/lessons/ornament-chain/activity.md new file mode 100644 index 00000000..e6fe74b9 --- /dev/null +++ b/docs/reference/js/lessons/ornament-chain/activity.md @@ -0,0 +1,80 @@ +# ornament chain activity + +build a telgraph #microbit #docs + +# Ornament Chain Activity + +![](/static/mb/lessons/ornament-chain-0.jpg) + +![](/static/mb/lessons/ornament-chain-1.jpg) + +In this project, you will build your ornament chain between BBC micro:bits. Project duration: 15 minutes. + +## Materials + +* BBC 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 BBC micro:bit. + +### Step 2 + +![](/static/mb/lessons/ornament-chain-2.png) + +Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the BBC micro:bit. + +### Step 3 + +![](/static/mb/lessons/ornament-chain-3.png) + +Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the BBC micro:bit. + +### Step 4 + +![](/static/mb/lessons/ornament-chain-4.png) + +Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the BBC micro:bit. + +### Step 5 + +![](/static/mb/lessons/ornament-chain-5.png) + +Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd BBC micro:bit. + +### Step 6 + +![](/static/mb/lessons/ornament-chain-6.png) + +Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd BBC micro:bit. + +### Step 7 + +![](/static/mb/lessons/ornament-chain-7.png) + +Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd BBC micro:bit. + +### Step 8 + +![](/static/mb/lessons/ornament-chain-8.png) + +Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd BBC micro:bit + +### Step 9 + +![](/static/mb/lessons/ornament-chain-0.jpg) + +![](/static/mb/lessons/ornament-chain-1.jpg) + +Your ornament chain is ready! + +### Step 10 + +* Connect the first BBC micro:bit to your computer using your USB cable and run the [ornament chain](/microbit/rnvpgo) script on it. +* Connect the second BBC micro:bit to your computer using your USB cable and run the [ornament chain](/microbit/rnvpgo) script on it. +* The first person and second person take turns pressing button A to start the ornament chain game! diff --git a/docs/reference/js/lessons/pong.md b/docs/reference/js/lessons/pong.md new file mode 100644 index 00000000..2f65b50c --- /dev/null +++ b/docs/reference/js/lessons/pong.md @@ -0,0 +1,135 @@ +# pong lesson + +code your own game of Pong on the micro:bit #data #assignment #on-button-pressed #if # #function #data #forever #var #button #if #assignment #pause #string #number #docs + +### @video td/videos/pong-0 + +## Topic + +Functions + +## Quick Links + +* [tutorial](/microbit/lessons/pong/tutorial) +* [quiz](/microbit/lessons/pong/quiz) +* [quiz answers](/microbit/lessons/pong/quiz-answers) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a pong game using functions, global variable forever loop, global variables, Boolean, for loop, input on button pressed, if statements, as well as simple commands, such as plot, unplot and pause. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Hardware: The physical systems and components of digital devices; see also software. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **function** : [read more...](/microbit/js/function) +* **return** : [read more...](/microbit/js/return) +* **call** : [read more...](/microbit/js/call) +* **global variable** : [read more...](/microbit/js/data) +* **arithmetic operator** : [read more...](/microbit/reference/types/number) +* **Boolean** : [/td/Boolean]() +* **forever** : [read more...](/microbit/reference/basic/forever) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **if** : [read more...](/microbit/reference/logic/if) +* **clear screen** : [read more...](/microbit/reference/basic/clear-screen) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **plot** : [read more...](/microbit/reference/led/plot) +* **unplot** : [read more...](/microbit/reference/led/unplot) +* **pause** : [read more...](/microbit/reference/basic/pause) + +## Resources + +* Activity: [tutorial](/microbit/lessons/pong/tutorial) +* Activity: [quiz](/microbit/lessons/pong/quiz) + +## Objectives + +* learn how to create a function as a unit of code that performs a specific task and returns a result +* learn how a return statement exits a function and returns a value to the code +* learn how to call an existing function in your script +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how arithmetic operators operate on numbers and return a number +* learn how a Boolean type has one of two possible values: true or false +* learn how to repeat code in the background forever +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to run code when an input button is pressed +* learn how to show a string on the micro:bit's LED screen +* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates +* learn how to turn off a LED light on the LED screen. Learn how to specify which LED using x, y coordinates +* learn how to pause your code for the specified number of milliseconds + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Defines data types: real numbers and Boolean (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/pong/tutorial) + +## Extended Activity + +* time: 20 min. +* [quiz](/microbit/lessons/pong/quiz) + +## Homework + +* Extended Activity: [quiz](/microbit/lessons/pong/quiz) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/pong/activity.md b/docs/reference/js/lessons/pong/activity.md new file mode 100644 index 00000000..7a2b4f05 --- /dev/null +++ b/docs/reference/js/lessons/pong/activity.md @@ -0,0 +1,65 @@ +# pong activity + +Building a game of pong with sprites. #docs #lessons #pong + +### ~avatar avatar + +### @video td/videos/pong-0 + +Welcome! This tutorial will teach you how to build a simple pong game using sprites. + +### ~ + +The game works as follow: the user moves a paddle on the left of the screen and a ball bounces on the other side. Let's start by creating the 2 sprites. + +``` +let paddle = game.createSprite(0, 2) +let ball = game.createSprite(4, 2) +``` + +Let's make the ball start with an angle. + +``` +ball.setDirection(-45) +``` + +The user will control the paddle by pressing ``A`` to go up and ``B`` to go down. Let's add ``on button pressed`` event handlers to do that. + +``` +input.onButtonPressed("A", () => { + paddle.changeYBy(-1) +}) +input.onButtonPressed("B", () => { + paddle.changeYBy(1) +}) +``` + +Let's add a ``forever`` loop to start the main game logic. + +``` +basic.forever(() => { + // Leave the sprite on screen for a little while. + basic.pause(400) + // Let's move the ball in whatever direction it is currently going. + ball.move(1) + // The ball might be on the left side of the screen (``x = 0``), let's test for that. + if (ball.x() == 0) { + // Let's add a little pause to let the user know that the ball is on the side. + basic.pause(400) + // If the paddle is not at the same ``y`` coordinate, it missed the ball and we can trigger a game over. If not, we add a point to the score. + if (paddle.y() != ball.y()) { + game.gameOver() + } else { + game.addScore(1) + basic.pause(500) + } + } + // The ball moved and might be on a side, let's make sure it bounces. + ball.ifOnEdge_Bounce() + // If the ball is on the left side, slide it forward to change slightly the bouncing mechanics. + if (ball.x() == 0) { + ball.changeXBy(1) + } +}) +``` + diff --git a/docs/reference/js/lessons/pong/quiz-answers.md b/docs/reference/js/lessons/pong/quiz-answers.md new file mode 100644 index 00000000..51f6afde --- /dev/null +++ b/docs/reference/js/lessons/pong/quiz-answers.md @@ -0,0 +1,87 @@ +# pong quiz answers + +create the game Pong #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [pong tutorial](/microbit/lessons/pong/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values. + +
+ +``` +ballX = 2 +ballY = 1 +``` + +## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values. + +
+ +``` +ballXVelocity = 1 +ballYVelocity = 1 +``` + +## 3. Write the code that plots the initial position of the paddle and the ball. + +
+ +``` +led.plot(0, paddleY) +led.plot(ballX, ballY) +``` + +## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.) + +
+ +``` +input.onButtonPressed("A", () => { + if (paddleNotUp()) { + led.unplot(0, paddleY) + paddleY = paddleY - 1 + led.plot(0, paddleY) + } +}) +``` + +## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.) + +
+ +``` +input.onButtonPressed("A", () => { + if (paddleNotDown()) { + led.unplot(0, paddleY) + paddleY = paddleY + 1 + led.plot(0, paddleY) + } +}) +``` + +## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".) + +
+ +``` +if (ballY == 4 || ballY == 0) { + ballYVelocity = (-1) * ballYVelocity +} +``` + +## 7. Write the code to move the ball. (Hint: look at the function "move ball".) + +
+ +``` +led.unplot(ballX, ballY) +ballX = ballX + ballXVelocity +ballY = ballY + ballYVelocity +``` + diff --git a/docs/reference/js/lessons/pong/quiz.md b/docs/reference/js/lessons/pong/quiz.md new file mode 100644 index 00000000..6a507f97 --- /dev/null +++ b/docs/reference/js/lessons/pong/quiz.md @@ -0,0 +1,40 @@ +# pong quiz + +create the game Pong #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [pong tutorial](/microbit/lessons/pong/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values. + +
+ +## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values. + +
+ +## 3. Write the code that plots the initial position of the paddle and the ball. + +
+ +## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.) + +
+ +## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.) + +
+ +## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".) + +
+ +## 7. Write the code to move the ball. (Hint: look at the function "move ball".) + +
+ diff --git a/docs/reference/js/lessons/prank-wifi-app/challenges.md b/docs/reference/js/lessons/prank-wifi-app/challenges.md new file mode 100644 index 00000000..6906cee2 --- /dev/null +++ b/docs/reference/js/lessons/prank-wifi-app/challenges.md @@ -0,0 +1,147 @@ +# prank wifi app challenges + +My script. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/prank-wifi-app/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.showString("Check Wifi", 150) +basic.forever(() => { + let xAccel = math.abs(input.acceleration("x")) + let yAccel = math.abs(input.acceleration("y")) + let zAccel = math.abs(input.acceleration("z")) + let sum = xAccel + yAccel + zAccel + if (sum < 1400) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) + } else if (sum >= 1400 && sum < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) + } + else if (sum >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) + } +}) +``` + +**Challenge 1** + +What if wanted to show the maximum connectivity of wifi instead of just 1, 3, or 4 bars? + +Let's start by changing the first **IF** statement to `if sum <1200`. + +Edit this line: **if** sum <1400 **then** + +Just click on the `1400` and backspace until you can add your own number of `1200`. + +``` +basic.showString("Check Wifi", 150) +basic.forever(() => { + let xAccel1 = math.abs(input.acceleration("x")) + let yAccel1 = math.abs(input.acceleration("y")) + let zAccel1 = math.abs(input.acceleration("z")) + let sum1 = xAccel1 + yAccel1 + zAccel1 + if (sum1 < 1200) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) + } else if (sum1 >= 1400 && sum1 < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) + } + else if (sum1 >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) + } +}) +``` + +**Challenge 2** + +Let's add an **IF** at the bottom of your code that checks to see if `sum >= to 1200` **and** if `sum <1400` + +``` +basic.showString("Check Wifi", 150) +basic.forever(() => { + let xAccel2 = math.abs(input.acceleration("x")) + let yAccel2 = math.abs(input.acceleration("y")) + let zAccel2 = math.abs(input.acceleration("z")) + let sum2 = xAccel2 + yAccel2 + zAccel2 + if (sum2 < 1200) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) + } else if (sum2 >= 1400 && sum2 < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) + } + else if (sum2 >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) + } + if (sum2 >= 1200 && sum2 < 1400) { + basic.plotImage(` +. . . . # +. . . # # +. . # # # +. # # # # +# # # # # +`) // *** + } +}) +``` + +**Challenge 3** + +Now it's your turn! Be creative and change the Wifi meter images to your own wifi image you're sure will prank your friends by editing the lines that call `plot image()`. + diff --git a/docs/reference/js/lessons/prank-wifi.md b/docs/reference/js/lessons/prank-wifi.md new file mode 100644 index 00000000..f63ff4dc --- /dev/null +++ b/docs/reference/js/lessons/prank-wifi.md @@ -0,0 +1,9 @@ +# prank wifi lesson + +create a fake wifi app to trick your friends #abs #acceleration #if #math #plot #image #functions #var #docs + +create a fake wifi app to trick your friends + +* [tutorial](/microbit/lessons/prank-wifi/tutorial) +* [quiz](/microbit/lessons/prank-wifi/quiz) +* [challenges](/microbit/lessons/prank-wifi/challenges) diff --git a/docs/reference/js/lessons/prank-wifi/challenges.md b/docs/reference/js/lessons/prank-wifi/challenges.md new file mode 100644 index 00000000..017e9537 --- /dev/null +++ b/docs/reference/js/lessons/prank-wifi/challenges.md @@ -0,0 +1,147 @@ +# prank wifi challenges + +create a fake wifi app to trick your friends. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/prank-wifi/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.showString("Check Wifi", 150) +basic.forever(() => { + let xAccel = math.abs(input.acceleration("x")) + let yAccel = math.abs(input.acceleration("y")) + let zAccel = math.abs(input.acceleration("z")) + let sum = xAccel + yAccel + zAccel + if (sum < 1400) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) + } else if (sum >= 1400 && sum < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) + } + else if (sum >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) + } +}) +``` + +**Challenge 1** + +What if wanted to show the maximum connectivity of wifi instead of just 1, 3, or 4 bars? + +Let's start by changing the first **IF** statement to `if sum <1200`. + +Edit this line: **if** sum <1400 **then** + +Just click on the `1400` and backspace until you can add your own number of `1200`. + +``` +basic.showString("Check Wifi", 150) +basic.forever(() => { + let xAccel1 = math.abs(input.acceleration("x")) + let yAccel1 = math.abs(input.acceleration("y")) + let zAccel1 = math.abs(input.acceleration("z")) + let sum1 = xAccel1 + yAccel1 + zAccel1 + if (sum1 < 1200) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) + } else if (sum1 >= 1400 && sum1 < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) + } + else if (sum1 >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) + } +}) +``` + +**Challenge 2** + +Let's add an **IF** at the bottom of your code that checks to see if `sum >= to 1200` **and** if `sum <1400` + +``` +basic.showString("Check Wifi", 150) +basic.forever(() => { + let xAccel2 = math.abs(input.acceleration("x")) + let yAccel2 = math.abs(input.acceleration("y")) + let zAccel2 = math.abs(input.acceleration("z")) + let sum2 = xAccel2 + yAccel2 + zAccel2 + if (sum2 < 1200) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) + } else if (sum2 >= 1400 && sum2 < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) + } + else if (sum2 >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) + } + if (sum2 >= 1200 && sum2 < 1400) { + basic.plotImage(` +. . . . # +. . . # # +. . # # # +. # # # # +# # # # # +`) // *** + } +}) +``` + +**Challenge 3** + +Now it's your turn! Be creative and change the Wifi meter images to your own wifi image you're sure will prank your friends by editing the lines that call `plot image()`. + diff --git a/docs/reference/js/lessons/prank-wifi/quiz-answers.md b/docs/reference/js/lessons/prank-wifi/quiz-answers.md new file mode 100644 index 00000000..b3a3751b --- /dev/null +++ b/docs/reference/js/lessons/prank-wifi/quiz-answers.md @@ -0,0 +1,92 @@ +# prank wifi quiz answers + +create a fake wifi app to trick your friends #string #forever #abs #var #plot #image #if #math #abs #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [prank WiFi tutorial](/microbit/lessons/prank-wifi/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the lines of code that takes the absolute value of the accelerations with respect to the x, y and z axis and stores the values as Local Variables + +
+ +``` +let xAccel = math.abs(input.acceleration("x")) +let yAccel = math.abs(input.acceleration("y")) +let zAccel = math.abs(input.acceleration("z")) +``` + +
+ +## 2. Write the lines of code that add all the accelerations together to get the total acceleration and stores the value as a Local Variable called "sum" + +
+ +
+ +``` +let sum = xAccel + yAccel + zAccel +``` + +
+ +## 3. Write the 'If statement' used if the sum of the acceleration value is less than 1400 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi if the acceleration in this 'If statement' + +
+ +``` +if (sum < 1400) { + basic.plotImage(` +. . . . . +. . . . . +. . # . . +. # # . . +# # # . . +`) +} +``` + +
+ +## 4. Write tje 'If statement' used if the sum of the acceleration value is greater than 1400 milli-gravitys but less than 1680 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi inside this 'If statement' + +
+ +
+ +``` +if (sum >= 1400 && sum < 1680) { + basic.plotImage(` +. . . . . +. . . # . +. . # # . +. # # # . +# # # # . +`) +} +``` + +## 5. Write the 'if statement' needed to display this specific plot image on the device + +![](/static/mb/lessons/prank-wifi-0.png) + +
+ +
+ +``` +if (sum >= 1680) { + basic.plotImage(` +. . . . . +. . . . . +. . . . . +. . . . . +# . . . . +`) +} +``` + diff --git a/docs/reference/js/lessons/prank-wifi/quiz.md b/docs/reference/js/lessons/prank-wifi/quiz.md new file mode 100644 index 00000000..f4938e64 --- /dev/null +++ b/docs/reference/js/lessons/prank-wifi/quiz.md @@ -0,0 +1,46 @@ +# prank wifi quiz + +create a fake wifi app to trick your friends #string #forever #abs #var #plot #image #if #math #abs #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [prank WiFi tutorial](/microbit/lessons/prank-wifi/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the lines of code that takes the absolute value of the accelerations with respect to the x, y and z axis and stores the values as Local Variables + +
+ +
+ +## 2. Write the lines of code that add all the accelerations together to get the total acceleration and stores the value as a Local Variable called "sum" + +
+ +
+ +
+ +## 3. Write the 'If statement' used if the sum of the acceleration value is less than 1400 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi if the acceleration in this 'If statement' + +
+ +
+ +## 4. Write tje 'If statement' used if the sum of the acceleration value is greater than 1400 milli-gravitys but less than 1680 milli-gravitys. Then write the code that will plot an image of the fake amount of WiFi inside this 'If statement' + +
+ +
+ +## 5. Write the 'if statement' needed to display this specific plot image on the device + +![](/static/mb/lessons/prank-wifi-0.png) + +
+ +
+ diff --git a/docs/reference/js/lessons/rectangle-explosion/challenges.md b/docs/reference/js/lessons/rectangle-explosion/challenges.md new file mode 100644 index 00000000..3cb61522 --- /dev/null +++ b/docs/reference/js/lessons/rectangle-explosion/challenges.md @@ -0,0 +1,83 @@ +# snowflake fall challenges + +These challenges will allow you to make an exploding rectangle. #docs + +**Challenge 0** + +### @video vimeo/134649147 + +This [guided tutorial](https://test.microbit.co.uk/td/lessons/rectangle-explosion/tutorial) will help you create a snowflake animation! + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) +}) +``` + +**Challenge 1** + +### @video vimeo/134649148 + +Let's begin creating our falling effect by adding another snowflake with `show animation` that displays a different snowflake pattern after the first one. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) + basic.showAnimation(` +. . . . . . . # . . +. . # . . . # . # . +. # # # . # . . . # +. . # . . . # . # . +. . . . . . . # . . +`, 400) // *** +}) +``` + +**Challenge 2** + +### @video vimeo/134649149 + +To finalize our snowflake fall, let's add a different snowflake pattern. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) + basic.showAnimation(` +. . . . . . . # . . +. . # . . . # . # . +. # # # . # . . . # +. . # . . . # . # . +. . . . . . . # . . +`, 400) + basic.showAnimation(` +. . . . . . . # . . . # . # . +. . # . . . # . # . # # . # # +. # # # . # . . . # . . . . . +. . # . . . # . # . # # . # # +. . . . . . . # . . . # . # . +`, 400) // *** +}) +``` + +**Challenge 3** + +If you notice, we have three `basic->show animation()` functions. Try to create the snowflake fall effect by just using one `basic->show animation()`. + diff --git a/docs/reference/js/lessons/return/challenges.md b/docs/reference/js/lessons/return/challenges.md new file mode 100644 index 00000000..a9eba150 --- /dev/null +++ b/docs/reference/js/lessons/return/challenges.md @@ -0,0 +1,46 @@ +# return challenges + +This script will teach you how to create a function and use an output parameter. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](/microbit/lessons/return/tutorial) will help you code the following script! + +``` +let original1 = 5 +input.onButtonPressed("A", () => { + let doubled = doubleIt_(5) + basic.showNumber(doubled, 150) // *** +}) +``` + +### Challenge 1 + +Create a new function called `square` that returns squares the number passed into the function. (Squaring means that you multiply the number by itself.) + +``` +export function squareIt(n: number) : number { + let num: number + return n * n + return num +} +``` + +### Challenge 2 + +Add a condition to know when button `B` is pressed. We will use this condition in the last challenge. + +``` +let original = 5 +input.onButtonPressed("A", () => { + let one = doubleIt_(original) + basic.showNumber(one, 150) +}) +input.onButtonPressed("B", () => { +}) +``` + +### Challenge 3 + +When the `B` button is pressed, display the square of the original value. Use the function `square it`. You should get the value 25. + diff --git a/docs/reference/js/lessons/rock-paper-scissors-book-version/challenges.md b/docs/reference/js/lessons/rock-paper-scissors-book-version/challenges.md new file mode 100644 index 00000000..cd0ba1d9 --- /dev/null +++ b/docs/reference/js/lessons/rock-paper-scissors-book-version/challenges.md @@ -0,0 +1,235 @@ +# rock paper scissors book version + +My script. #docs + +Welcome! This guide will show you how to complete the challenges for the game of rock, paper, scissors! + +## Challenge 1 + +### Step 16 + +Awesome! You have just created your game of rock paper scissors. However, why don't we add a little more to it? We can keep track of your score against the micro:bit using global variables. Create a global variable to keep track of the wins against the micro:bit. To do so, click on `add new`, then `Data`, and then `Number`. + +``` +var wins: number = 0 +``` + +### Step 17 + +At the beginning of the game, you don't have any wins against the micro:bit. As a result, let's set the `data->wins` variable to 0 at the top of your main function. + +``` +wins = 0 // *** +input.onGesture(Gesture.Shake, () => { + let img = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset = 5 * Math.random(3) + img.showImage(offset) +}) +``` + +### Step 18 + +Now let's keep track of wins by using button `A`. Every time button `A` is pressed, we want to increment `data->wins` by 1. We can begin by adding a condition `input->on button pressed("A")`. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img1 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset1 = 5 * Math.random(3) + img1.showImage(offset1) +}) +input.onButtonPressed("A", () => { +}) // *** +``` + +### Step 19 + +Nice! Now that we added the condition for when button `A` is pressed, we can increment `data->wins` by 1. Add the following statement in the condition. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img2 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset2 = 5 * Math.random(3) + img2.showImage(offset2) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 // *** +}) +``` + +### Step 20 + +You have tracked the number of wins you have against the micro:bit. However, how will you ever know how many wins you have? After we increment `data->wins`, let's display the total number of wins you have. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img3 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset3 = 5 * Math.random(3) + img3.showImage(offset3) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) // *** + basic.showNumber(wins, 150) // *** +}) +``` + +* Tap `run` to run the program on the simulator. Notice the number of wins you have against the micro:bit. + +## Challenge 2 + +### Step 21 + +You have managed to keep score of the number of wins you have against the micro:bit. However, what about losses? Let's begin by creating another global variable to keep track of losses. + +``` +var losses: number = 0 +``` + +### Step 22 + +Add a condition for when button `B` is pressed. When this occurs, we will increment your losses against the micro:bit by 1. Let's hope that this button will not be pressed too often! + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img4 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset4 = 5 * Math.random(3) + img4.showImage(offset4) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) +}) +input.onButtonPressed("B", () => { +}) // *** +``` + +### Step 23 + +Now let's continue where we left off. Just as we did for `data->wins` when button `A` is pressed, we need to increment `losses` by 1 when button `B` is pressed. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img5 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset5 = 5 * Math.random(3) + img5.showImage(offset5) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) +}) +input.onButtonPressed("B", () => { + losses = losses + 1 // *** +}) +``` + +### Step 24 + +Let's also display the score when button `B` is pressed, just as we have done for button `A`. This will help us keep track of the number of wins and losses you have against the micro:bit. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img6 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset6 = 5 * Math.random(3) + img6.showImage(offset6) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) +}) +input.onButtonPressed("B", () => { + losses = losses + 1 + basic.showString("WINS", 150) // *** + basic.showNumber(wins, 150) // *** + basic.showString("LOSSES:", 150) // *** + basic.showNumber(losses, 150) // *** +}) +``` + +### Step 25 + +You have managed to keep track of both the wins and losses you have against the micro:bit! But did you notice that you haven't updated something? Take a look at condition of `input->on button pressed("A")`. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img7 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset7 = 5 * Math.random(3) + img7.showImage(offset7) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) + basic.showString("LOSSES:", 150) // *** + basic.showNumber(losses, 150) // *** +}) +input.onButtonPressed("B", () => { + losses = losses + 1 + basic.showString("WINS", 150) + basic.showNumber(wins, 150) + basic.showString("LOSSES:", 150) + basic.showNumber(losses, 150) +}) +``` + +* Tap the `run` button to run your game on the simulator. See if you can get more wins than the micro:bit can! + +Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the micro:bit. Challenge your friends to see who can get a better score against the micro:bit. + diff --git a/docs/reference/js/lessons/rock-paper-scissors-teacher-guide/challenges.md b/docs/reference/js/lessons/rock-paper-scissors-teacher-guide/challenges.md new file mode 100644 index 00000000..63fbae9f --- /dev/null +++ b/docs/reference/js/lessons/rock-paper-scissors-teacher-guide/challenges.md @@ -0,0 +1,235 @@ +# rock paper scissors teacher guide + +My script. #docs + +Welcome! This guide will show you how to complete the challenges for the game of rock, paper, scissors! + +## Challenge 1 + +### Step 16 + +Awesome! You have just created your game of rock paper scissors. However, why don't we add a little more to it? We can keep track of your score against the micro:bit using global variables. Create a global variable to keep track of the wins against the micro:bit. To do so, click on `add new`, then `Data`, and then `Number`. + +``` +var wins: number = 0 +``` + +### Step 17 + +At the beginning of the game, you don't have any wins against the micro:bit. As a result, let's set the `data->wins` variable to 0 at the top of your main function. + +``` +wins = 0 // *** +input.onGesture(Gesture.Shake, () => { + let img = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset = 5 * Math.random(3) + img.showImage(offset) +}) +``` + +### Step 18 + +Now let's keep track of wins by using button `A`. Every time button `A` is pressed, we want to increment `data->wins` by 1. We can begin by adding a condition `input->on button pressed("A")`. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img1 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset1 = 5 * Math.random(3) + img1.showImage(offset1) +}) +input.onButtonPressed("A", () => { +}) // *** +``` + +### Step 19 + +Nice! Now that we added the condition for when button `A` is pressed, we can increment `data->wins` by 1. Add the following statement in the condition. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img2 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset2 = 5 * Math.random(3) + img2.showImage(offset2) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 // *** +}) +``` + +### Step 20 + +You have tracked the number of wins you have against the micro:bit. However, how will you ever know how many wins you have? After we increment `data->wins`, let's display the total number of wins you have. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img3 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset3 = 5 * Math.random(3) + img3.showImage(offset3) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) // *** + basic.showNumber(wins, 150) // *** +}) +``` + +* Tap `run` to run the program on the simulator. Notice the number of wins you have against the micro:bit. + +## Challenge 2 + +### Step 21 + +You have managed to keep score of the number of wins you have against the micro:bit. However, what about losses? Let's begin by creating another global variable to keep track of losses. + +``` +var losses: number = 0 +``` + +### Step 22 + +Add a condition for when button `B` is pressed. When this occurs, we will increment your losses against the micro:bit by 1. Let's hope that this button will not be pressed too often! + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img4 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset4 = 5 * Math.random(3) + img4.showImage(offset4) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) +}) +input.onButtonPressed("B", () => { +}) // *** +``` + +### Step 23 + +Now let's continue where we left off. Just as we did for `data->wins` when button `A` is pressed, we need to increment `losses` by 1 when button `B` is pressed. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img5 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset5 = 5 * Math.random(3) + img5.showImage(offset5) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) +}) +input.onButtonPressed("B", () => { + losses = losses + 1 // *** +}) +``` + +### Step 24 + +Let's also display the score when button `B` is pressed, just as we have done for button `A`. This will help us keep track of the number of wins and losses you have against the micro:bit. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img6 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset6 = 5 * Math.random(3) + img6.showImage(offset6) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) +}) +input.onButtonPressed("B", () => { + losses = losses + 1 + basic.showString("WINS", 150) // *** + basic.showNumber(wins, 150) // *** + basic.showString("LOSSES:", 150) // *** + basic.showNumber(losses, 150) // *** +}) +``` + +### Step 25 + +You have managed to keep track of both the wins and losses you have against the micro:bit! But did you notice that you haven't updated something? Take a look at condition of `input->on button pressed("A")`. + +``` +wins = 0 +input.onGesture(Gesture.Shake, () => { + let img7 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + let offset7 = 5 * Math.random(3) + img7.showImage(offset7) +}) +input.onButtonPressed("A", () => { + wins = wins + 1 + basic.showString("WINS:", 150) + basic.showNumber(wins, 150) + basic.showString("LOSSES:", 150) // *** + basic.showNumber(losses, 150) // *** +}) +input.onButtonPressed("B", () => { + losses = losses + 1 + basic.showString("WINS", 150) + basic.showNumber(wins, 150) + basic.showString("LOSSES:", 150) + basic.showNumber(losses, 150) +}) +``` + +* Tap the `run` button to run your game on the simulator. See if you can get more wins than the micro:bit can! + +Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the micro:bit. Challenge your friends to see who can get a better score against the micro:bit. + diff --git a/docs/reference/js/lessons/rock-paper-scissors.md b/docs/reference/js/lessons/rock-paper-scissors.md new file mode 100644 index 00000000..f259cba6 --- /dev/null +++ b/docs/reference/js/lessons/rock-paper-scissors.md @@ -0,0 +1,95 @@ +# rock paper scissors lesson + +a game against the BBC micro:bit #var #image #button #string #number #docs + +### @video td/videos/rock-paper-scissors-0 + +## Topic + +Local Variables + +## Quick Links + +* [activity](/microbit/lessons/rock-paper-scissors/activity) +* [challenges](/microbit/lessons/rock-paper-scissors/challenges) +* [tutorial](/microbit/lessons/rock-paper-scissors/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create a **local variable**, `var t :=time` where you can store data, so that you can use it in your code. We will be learning how to create a classic rock paper scissors game using global variables, input on shake, local variables, math random as well as simple commands such as create image, show image, show string, and show number. + +## Documentation + +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **create image** : [read more...](/microbit/reference/images/create-image) +* **math random** : [read more...](/microbit/js/math) +* **show image** : [read more...](/microbit/reference/images/show-image) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **show string** : [read more...](/microbit/reference/basic/show-string) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Objectives + +* learn how to create a condition so the micro:bit will run code when it is shaken +* learn how to create a local variable for a place where you can store data +* learn how to create an image to show on the micro:bit's LED screen +* learn how to return a random number +* learn how to show an image on the micro:bit's LED screen +* learn how to run code when an input button is pressed +* learn how to show a string on the LED screen +* learn how to show a number on the LED screen + +## 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) +* Declares and assigns variables(AB) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Uses filters or can perform single criteria searches for information.(AL) +* 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/rock-paper-scissors/activity) +* [tutorial](/microbit/lessons/rock-paper-scissors/tutorial) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/rock-paper-scissors/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/rock-paper-scissors/challenges) + diff --git a/docs/reference/js/lessons/rock-paper-scissors/activity.md b/docs/reference/js/lessons/rock-paper-scissors/activity.md new file mode 100644 index 00000000..073fe47a --- /dev/null +++ b/docs/reference/js/lessons/rock-paper-scissors/activity.md @@ -0,0 +1,56 @@ +# rock paper scissors activity + +a game against the BBC micro:bit. #docs + +### ~avatar avatar + +### @video td/videos/rock-paper-scissors-0 + +Welcome! This tutorial will help you create a game of rock paper scissors with the BBC 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 **Touch Develop**. + +We want the BBC micro:bit to choose rock, paper, or scissors when it is shaken. Let's begin by creating an `input->on shake` condition so the micro:bit will run code when it is shaken. + +``` +input.onGesture(Gesture.Shake, () => { +}) +``` + +Next, create an image that contains 3 frames: rock, paper, and scissors. We will control which image is shown with `offset`. + +``` +input.onGesture(Gesture.Shake, () => { + let img = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) +}) +``` + +The BBC micro:bit will look like it's showing 1 frame of the image by displaying the whole image with plot frame and math random. We can help the BBC micro:bit randomly decide which offset to using plot image by math random. The BBC micro:bit will randomly pick the image to display with plot image and the `math->random(3)` function. + +``` +input.onGesture(Gesture.Shake, () => { + let img1 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + img1.plotFrame(Math.random(3)) +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/rock-paper-scissors/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/rock-paper-scissors/challenges.md b/docs/reference/js/lessons/rock-paper-scissors/challenges.md new file mode 100644 index 00000000..94ea9087 --- /dev/null +++ b/docs/reference/js/lessons/rock-paper-scissors/challenges.md @@ -0,0 +1,70 @@ +# rock paper scissors challenges + +Coding challenges for the rock paper scissors tutorial. #docs + +## Before we get started + +Complete the following [guided activity](/microbit/lessons/rock-paper-scissors/activity) , your code should look like this: + +``` +input.onGesture(Gesture.Shake, () => { + let img = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . . # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + img.plotFrame(Math.random(3)) +}) +``` + +### Challenge 1 + +When the `A` button is pressed, increment the **score** by ``1``. You can use the `game->add score` function for that. + +``` +input.onGesture(Gesture.Shake, () => { + let img1 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . . # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + img1.plotFrame(Math.random(3)) +}) +input.onButtonPressed("A", () => { + game.addScore(1) // *** +}) // *** +``` + +### Challenge 2 + +After incrementing the score, display the total number of wins you have. + +``` +input.onGesture(Gesture.Shake, () => { + let img2 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . . # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) + img2.plotFrame(Math.random(3)) +}) +input.onButtonPressed("A", () => { + game.addScore(1) + basic.showString("WINS: ", 150) // *** + basic.showNumber(game.score(), 150) // *** +}) +``` + +* Run and compile the code to see if it works as expected. + +### Challenge 3 + +You have successfully tracked and displayed the number of wins on the BBC micro:bit! However, what about losses? Use `game->remove life` when button `B` is pressed. + +* Run and compile the code to see if it works as expected. diff --git a/docs/reference/js/lessons/rock-paper-scissors/quiz.md b/docs/reference/js/lessons/rock-paper-scissors/quiz.md new file mode 100644 index 00000000..84947f7c --- /dev/null +++ b/docs/reference/js/lessons/rock-paper-scissors/quiz.md @@ -0,0 +1,74 @@ +# rock paper scissors quiz + +shift an image horizontally across the display with offset #offset #screen #variables #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [rock paper scissors tutorial](/microbit/lessons/rock-paper-scissors/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Describe what `offset` does? + +
+ +## 2. Draw which LEDs are ON after running this code and the random number returned is 0 + +``` +let img = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) +let offset = Math.random(3) * 5 +img.showImage(offset) +``` + +![](/static/mb/lessons/night-light-2.png) + +
+ +
+ +## 3. Draw which LEDs are ON after running this code with an offset of 5. This would occur if the random number returned is 1. + +``` +let img_ = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) +let offset_ = Math.random(3) * 5 +img.showImage(offset) +``` + +![](/static/mb/lessons/night-light-2.png) + +
+ +
+ +## 4. Draw which LEDs are ON after running this code with an offset of 10. This would occur if the random number returned is 2. + +``` +let img_1 = images.createImage(` +. . . . . # # # # # . . . . # +. # # # . # . . . # # # . # . +. # # # . # . . . # . # # . . +. # # # . # . . . # # # . # . +. . . . . # # # # # . . . . # +`) +let offset_1 = Math.random(3) * 5 +img.showImage(offset) +``` + +![](/static/mb/lessons/night-light-2.png) + +
+ diff --git a/docs/reference/js/lessons/rotating-animation.md b/docs/reference/js/lessons/rotating-animation.md new file mode 100644 index 00000000..2192302b --- /dev/null +++ b/docs/reference/js/lessons/rotating-animation.md @@ -0,0 +1,12 @@ +# rotating animation + +Create a rotating image with a while loop. #docs #for #LED + +### @video vimeo/134323475 + +Rotate images with a while loop. + +* [tutorial](/microbit/lessons/rotation-pattern/tutorial) +* [quiz](/microbit/lessons/rotation-animation/quiz) +* [challenges](/microbit/lessons/rotation-animation/challenges) +* [lesson plan](/microbit/lessons/rotation-animation/lesson-plan) diff --git a/docs/reference/js/lessons/rotating-animation/challenges.md b/docs/reference/js/lessons/rotating-animation/challenges.md new file mode 100644 index 00000000..9f91d931 --- /dev/null +++ b/docs/reference/js/lessons/rotating-animation/challenges.md @@ -0,0 +1,68 @@ +# rotation animation challenges + +These challenges take the rotation animation to the next level by adding a while loop and changing a boolean to false. #docs + +**Challenge 0** + +### @video vimeo/134323475 + +The [Rotating Pattern tutorial](https://test.microbit.co.uk/td/lessons/rotation-animation/tutorial) will help you create images that look like a rotating pattern by using a while loop. + +``` +rotating = true +while (rotating) { + basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +} +``` + +**Challenge 1** + +Now let's add to this by creating a condition for on button pressed `A` before the while loop. + +``` +rotating = true +input.onButtonPressed("A", () => { +}) // *** +while (rotating) { + basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +} +``` + +**Challenge 2** + +### @video vimeo/134323896 + +Now that we have the on button pressed condition, let's make the animation stop rotating by setting the rotating global variable to false when button `A` is pressed. + +``` +rotating = true +input.onButtonPressed("A", () => { + rotating = false // *** +}) // *** +while (rotating) { + basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +} +``` + +**Challenge 3** + +Let's also make the image rotate the opposite way when button A is pressed! We can do this with another while loop that is only executed when `rotating->equals(false)`. + diff --git a/docs/reference/js/lessons/rotating-animation/lesson-plan.md b/docs/reference/js/lessons/rotating-animation/lesson-plan.md new file mode 100644 index 00000000..8f78e8d7 --- /dev/null +++ b/docs/reference/js/lessons/rotating-animation/lesson-plan.md @@ -0,0 +1,99 @@ +# rotating animation lesson plan + +Learn how to create images with a global variable and while loop. #LED #screen #plot #docs + +### @video vimeo/134323475 + +## Topic + +While Loop - Rotating Animations + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create images that look like a rotating animation by using a while loop. We will be learning how to create a rotating animation using a global variable, while loop as well as simple commands, such as on button pressed and show animation. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **global variables**: [read more...](/microbit/functions/data) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **forever**: [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [tutorial](/microbit/lessons/rotating-pattern/tutorial) +* Activity: [quiz](/microbit/lessons/rotating-animation/quiz) +* Extended Activity: [challenges](/microbit/lessons/rotating-animation/challenges) + +## Objectives + +* learn how to create a global variable +* learn how a rotating animation +* learn how to repeat the animation + +## Links to the National Curriculum Programmes of Study for Computing + +## Assessment + +### Progression Pathways + +### Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/rotating-animation/tutorial) +* [quiz](/microbit/lessons/rotating-animation/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/rotating-animation/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/rotating-animation/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/rotating-animation/quiz.md b/docs/reference/js/lessons/rotating-animation/quiz.md new file mode 100644 index 00000000..1d9ea128 --- /dev/null +++ b/docs/reference/js/lessons/rotating-animation/quiz.md @@ -0,0 +1,77 @@ +# rotating animation quiz + +Learn how to create a rotating image with a while loop. #image #loop #while #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [rotating animation tutorial](/microbit/js/tutorials/rotating-animation). + +Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs! + +## 1. What is a while loop? + +## 2. Consider the following directions + +Write the code to create a **global variable** called `rotating` and initialize it to **true**. + +## 3. Consider the following directions + +Write the code to create a **while** loop that will be executed only if the **global variable** called `rotating` is **true**. + +## 4. Consider the following code + +``` +basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +``` + +If the rectangles below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted in the series. Explain why the LED is lighted there. + +![](/static/mb/empty-microbit.png)![](/static/mb/empty-microbit.png)![](/static/mb/empty-microbit.png)![](/static/mb/empty-microbit.png) + +****************************** + +## ANSWER KEY + +## Directions + +Answer the questions below while working on or after you finish the tutorial. + +## 2. Consider the following directions + +Write the line of code to create a **global variable** called `rotating` and initialize it to **true**. + +``` +rotating = true +``` + +## 3. Consider the following directions + +Write the line of code that create a **while** loop that will be executed only if the **global variable** called `rotating` is **true**. + +``` +while (rotating) { +} +``` + +## 4. Consider the following code + +``` +basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +``` + +If the rectangles below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted in the series. Explain why the LED is lighted there. + diff --git a/docs/reference/js/lessons/rotation-animation.md b/docs/reference/js/lessons/rotation-animation.md new file mode 100644 index 00000000..a9d39ed6 --- /dev/null +++ b/docs/reference/js/lessons/rotation-animation.md @@ -0,0 +1,82 @@ +# rotation animation lesson + +Learn how to create images with a global variable and while loop. #LED #screen #plot #docs + +## Topic + +While Loop + +## Quick links + +* [tutorial](/microbit/lessons/rotation-animation/tutorial) +* [quiz](/microbit/lessons/rotation-animation/quiz) +* [quiz answers](/microbit/lessons/rotation-animation/quiz-answers) +* [challenges](/microbit/lessons/rotation-animation/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create images that look like a rotating animation by using a while loop. We will be learning how to create a rotating animation using a global variable, while loop as well as simple commands, such as on button pressed and show animation. + +## Documentation + +* **global variable**: [read more...](/microbit/js/data) +* **assignment operator**: [read more...](/microbit/reference/variables/assign) +* **while**: [read more...](/microbit/js/while) +* **Boolean condition (for the while loop)** : [read more...](/microbit/reference/types/boolean) +* **on button pressed**: [read more...](/microbit/reference/input/on-button-pressed) +* **show animation**: [read more...](/microbit/reference/basic/show-animation) +* **pause**: [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to create a global variable for a place where you can store data, accessible across functions, and in nested code blocks +* learn how to set or change the value of a global variable +* learn how to repeat code while a condition is true +* learn how to declare a global boolean variable to determine which code will execute next +* learn how to run code when an input button is pressed +* learn how to show a series of image frames on the LED screen +* learn how to pause your code 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) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/rotation-animation/tutorial) +* [quiz](/microbit/lessons/rotation-animation/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/rotation-animation/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/rotation-animation/challenges) + diff --git a/docs/reference/js/lessons/rotation-animation/challenges.md b/docs/reference/js/lessons/rotation-animation/challenges.md new file mode 100644 index 00000000..29ba9f3f --- /dev/null +++ b/docs/reference/js/lessons/rotation-animation/challenges.md @@ -0,0 +1,75 @@ +# rotation animation challenges + +Coding challenges for the rotation animation tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/rotation-animation/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +rotating = true +while (rotating) { + basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) + basic.pause(25) +} +``` + +### Challenge 1 + +Now let's add to this by creating a condition for on button pressed `A` before the while loop. + +``` +rotating = true +input.onButtonPressed("A", () => { +}) // *** +while (rotating) { + basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) + basic.pause(25) +} +``` + +### Challenge 2 + +### @video td/videos/rotation-animation-1-and-2 + +Now that we have the on button pressed condition, let's make the animation stop rotating by setting the rotating global variable to false when button `A` is pressed. + +``` +rotating = true +input.onButtonPressed("A", () => { + rotating = false // *** +}) // *** +while (rotating) { + basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) + basic.pause(25) +} +``` + +* Run the code to see the awesome rotation. + +### Challenge 3 + +Let's also make the image rotate the opposite way when button A is pressed! We can do this with another while loop that is only executed while `not rotating`. + diff --git a/docs/reference/js/lessons/rotation-animation/lesson-plan.md b/docs/reference/js/lessons/rotation-animation/lesson-plan.md new file mode 100644 index 00000000..8b75c276 --- /dev/null +++ b/docs/reference/js/lessons/rotation-animation/lesson-plan.md @@ -0,0 +1,99 @@ +# rotation animation lesson plan + +Learn how to create images with a global variable and while loop. #LED #screen #plot #docs + +### @video vimeo/134323475 + +## Topic + +While Loop - Rotating Animations + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create images that look like a rotating animation by using a while loop. We will be learning how to create a rotating animation using a global variable, while loop as well as simple commands, such as on button pressed and show animation. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces Forever. Forever will repeats code in the background forever. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **global variables**: [read more...](/microbit/js/data) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **forever**: [read more...](/microbit/reference/basic/forever) + +## Resources + +* Activity: [tutorial](/microbit/lessons/rotation-animation/tutorial) +* Activity: [quiz](/microbit/lessons/rotation-animation/quiz) +* Extended Activity: [challenges](/microbit/lessons/rotation-animation/challenges) + +## Objectives + +* learn how to create a global variable +* learn how a rotating animation +* learn how to repeat the animation + +## Links to the National Curriculum Programmes of Study for Computing + +## Assessment + +### Progression Pathways + +### Computational Thinking Framework + +#### Algorithms + +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Declares and assigns variables.(AB) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/rotation-animation/tutorial) +* [quiz](/microbit/lessons/rotation-animation/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/rotation-animation/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/rotation-animation/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/rotation-animation/quiz-answers.md b/docs/reference/js/lessons/rotation-animation/quiz-answers.md new file mode 100644 index 00000000..51fc2f41 --- /dev/null +++ b/docs/reference/js/lessons/rotation-animation/quiz-answers.md @@ -0,0 +1,55 @@ +# rotation animation quiz answers + +Learn how to create a rotating image with a while loop. #image #loop #while #docs + +This is the answer key for the [rotation animation quiz](/microbit/lessons/rotation-animation/quiz). + +## 1. What is a "global variable"? + +Answers may vary. A global variable is a place where you can store data so that you can use it later in your code. + +## 2. Consider the following directions + +Write the code to create a **global variable** called `foo` that stores a boolean and initialize it to **false**. + +``` +rotating = true +``` + +## 3. Consider the following code + +``` +while (rotating) { +} +``` + +Explain what this line of code does. + +
+ +It is a **while** loop that will be executed only if the **global variable** called `rotating` is **true**. + +## 4. Consider the following code + +``` +basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +``` + +If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed. Explain why that particular area is shaded. + +![](/static/mb/lessons/rotation-animation-0.png) + +![](/static/mb/lessons/rotation-animation-1.png) + +![](/static/mb/lessons/rotation-animation-2.png) + +![](/static/mb/lessons/rotation-animation-3.png) + +Show animation will show a series of image frames on the LED screen, pausing the specified time (400 milliseconds) after each frame + diff --git a/docs/reference/js/lessons/rotation-animation/quiz.md b/docs/reference/js/lessons/rotation-animation/quiz.md new file mode 100644 index 00000000..35f47452 --- /dev/null +++ b/docs/reference/js/lessons/rotation-animation/quiz.md @@ -0,0 +1,45 @@ +# rotation animation quiz + +Learn how to create a rotating image with a while loop. #image #loop #while #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [rotation animation tutorial](/microbit/lessons/rotation-animation/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a "global variable"? + +
+ +## 2. Write the code to create a global variable called foo that stores a boolean and initialize it to false. + +
+ +## 3. Explain why you use a while loop with a global variable + +``` +while (rotating) { +} +``` + +
+ +## 4. Draw the areas on the micro:bits to illustrate the code below. Explain why you chose to draw in those areas. + +``` +basic.showAnimation(` +# . . . . . . # . . . . . . # . . . . . +. # . . . . . # . . . . . # . . . . . . +. . # . . . . # . . . . # . . # # # # # +. . . # . . . # . . . # . . . . . . . . +. . . . # . . # . . # . . . . . . . . . +`, 400) +``` + +![](/static/mb/lessons/looper-2.png) + +
+ diff --git a/docs/reference/js/lessons/runaway-pacman.md b/docs/reference/js/lessons/runaway-pacman.md new file mode 100644 index 00000000..fcc70abc --- /dev/null +++ b/docs/reference/js/lessons/runaway-pacman.md @@ -0,0 +1,7 @@ +# runaway pacman lessons + +make a game to test hand-eye coordination #docs #functions #var + +Make a game to test hand-eye coordination + +* [tutorial](/microbit/lessons/runaway-pacman/tutorial) diff --git a/docs/reference/js/lessons/runaway-pacman/quiz-answers.md b/docs/reference/js/lessons/runaway-pacman/quiz-answers.md new file mode 100644 index 00000000..de181370 --- /dev/null +++ b/docs/reference/js/lessons/runaway-pacman/quiz-answers.md @@ -0,0 +1,117 @@ +# runaway pacman quiz answers + +create a game that is inspired by the classic arcade game Pac Man #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [runaway pacman tutorial](/microbit/lessons/runaway-pacman/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the the method name created that will set up the game board. + +
+ +``` +initializeState() +``` + +## 2. Write the the method name created that will draw the player and the monster(s) + +
+ +``` +redraw() +``` + +## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.) + +
+ +``` +basic.forever(() => { + levelTime = levelTime + 12 + basic.pause(12) +}) +``` + +## 4. Write the code that will reset the time and continue playing if we have been eaten. + +
+ +``` +if ( ! playing) { + levelTime = 0 + playing = true +} +``` + +## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds. + +
+ +``` +if (levelTime >= 5000) { +} +``` + +## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.) + +
+ +``` +gameSuspended = true +``` + +## 7. Write the code to add a monster. (Hint: look in the function "add monster".) + +
+ +``` +let m = new Entity() +monsters.push(m) +totalMonsters = totalMonsters + 1 +``` + +## 8. Write the code that will restart the time to 0 after you begin the next level. + +
+ +``` +levelTime = 0 +``` + +## 9. Write the code that makes the player go either North or East when button 'A' is pressed. + +
+ +``` +input.onButtonPressed("A", () => { + let temp = math.abs(person.dirX) * (-1) + // {stcode} + // MACRO: stcode + person.dirX = math.abs(person.dirY) * (-1) + // {stcode} + // MACRO: stcode + person.dirY = temp +}) +``` + +## 10. Write the code that makes the player go either South or West when button 'B' is pressed. + +
+ +``` +input.onButtonPressed("B", () => { + let temp1 = math.abs(person.dirX) + // {stcode} + // MACRO: stcode + person.dirX = math.abs(person.dirY) + // {stcode} + // MACRO: stcode + person.dirY = temp1 +}) +``` + diff --git a/docs/reference/js/lessons/runaway-pacman/quiz.md b/docs/reference/js/lessons/runaway-pacman/quiz.md new file mode 100644 index 00000000..538b1f64 --- /dev/null +++ b/docs/reference/js/lessons/runaway-pacman/quiz.md @@ -0,0 +1,60 @@ +# runaway pacman quiz + +create a game that is inspired by the classic arcade game Pac Man #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [runaway pacman tutorial](/microbit/lessons/runaway-pacman/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the the method name created that will set up the game board. + +
+ +## 2. Write the the method name created that will draw the player and the monster(s) + +
+ +## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.) + +
+ +## 4. Write the code that will reset the time and continue playing if we have been eaten. + +
+ +## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds. + +
+ +## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.) + +
+ +## 7. Write the code to add a monster. (Hint: look in the function "add monster".) + +
+ +## 8. Write the code that will restart the time to 0 after you begin the next level. + +
+ +## 9. Write the code that makes the player go either North or East when button 'A' is pressed. + +
+ +
+ +
+ +## 10. Write the code that makes the player go either South or West when button 'B' is pressed. + +
+ +
+ +
+ diff --git a/docs/reference/js/lessons/running-time/challenges.md b/docs/reference/js/lessons/running-time/challenges.md new file mode 100644 index 00000000..40ec6a1a --- /dev/null +++ b/docs/reference/js/lessons/running-time/challenges.md @@ -0,0 +1,30 @@ +# running time challenges + +My script. #docs + +**Challenge 0** + +Great job! You have successfully completed the [Running Time tutorial](/microbit/lessons/running-time/tutorial) . You have a forever loop that declares a variable in it that holds the running time in milliseconds of the micro:bit and then shows the seconds on the LED screen. + +``` +basic.forever(() => { + let now = input.runningTime() + basic.showNumber(now / 1000, 150) +}) +``` + +**Challenge 1** + +When button A is pressed, reset the time by subtracting the current time from the variable now. + +``` +basic.forever(() => { + let now1 = input.runningTime() + basic.showNumber(now1 / 1000, 150) +}) +if (input.buttonIsPressed("A")) { + let now2 = 0 // *** +} +``` + +* Run the code to see if it works as expected. diff --git a/docs/reference/js/lessons/screen-up-and-down/challenges.md b/docs/reference/js/lessons/screen-up-and-down/challenges.md new file mode 100644 index 00000000..2eb0eea0 --- /dev/null +++ b/docs/reference/js/lessons/screen-up-and-down/challenges.md @@ -0,0 +1,64 @@ +# screen up and down challenges + +The on screen up function. #onscreenup #docs + +**Challenge 0** + +Congratulations! You have completed the [Screen Up/Down tutorial](/microbit/hqjwkb) . You should have an image of a heart created and shown when the screen is moved up. + +``` +input.onScreenUp(() => { + images.createImage(` +# # . # # +# # # # # +# # # # # +. # # # . +. . # . . +`).showImage(0) +}) +``` + +**Challenge 1** + +Now have the Micro:bit do something when the screen is moved downward. You can do this by calling the on screen down method. Do not do anything when you call the on screen down method. + +``` +input.onScreenUp(() => { + images.createImage(` +# # . # # +# # # # # +# # # # # +. # # # . +. . # . . +`).showImage(0) +}) +input.onScreenDown(() => { + +}) +``` + +**Challenge 2** + +When the Micro:bit is moved downward, create and show an image of an upside down heart. + +``` +input.onScreenUp(() => { + images.createImage(` +# # . # # +# # # # # +# # # # # +. # # # . +. . # . . +`).showImage(0) +}) +input.onScreenDown(() => { + images.createImage(` +. . # . . +. # # # . +# # # # # +# # # # # +# # . # # +`).showImage(0) // *** +}) +``` + diff --git a/docs/reference/js/lessons/screen-wipe.md b/docs/reference/js/lessons/screen-wipe.md new file mode 100644 index 00000000..89178d0b --- /dev/null +++ b/docs/reference/js/lessons/screen-wipe.md @@ -0,0 +1,109 @@ +# screen wipe lesson + +clear the screen by pressing button "A" #button #clear #docs + +### @video td/videos/screen-wipe-0 + +## Topic + +Clear Screen + +## Quick Links + +* [activity](/microbit/lessons/screen-wipe/activity) +* [quiz](/microbit/lessons/screen-wipe/quiz) +* [quiz answers](/microbit/lessons/screen-wipe/quiz-answers) +* [challenges](/microbit/lessons/screen-wipe/challenges) +* [tutorial](/microbit/lessons/screen-wipe/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to **clear screen**, `basic->clear screen` to turn off all the LED lights on the LED screen. We will be learning how to clear all LED lights on the LED screen using clear screen, input on button pressed as well as simple commands, such as show animation. + +## What the teacher needs to know/QuickStart Computing Glossary + +* Algorithm: An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. +* 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. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* 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 animation** : [read more...](/microbit/reference/basic/show-animation) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **clear screen** : [read more...](/microbit/reference/basic/clear-screen) + +## Resources + +* Activity: [tutorial](/microbit/lessons/screen-wipe/tutorial) +* Activity: [quiz](/microbit/lessons/screen-wipe/quiz) +* Extended Activity: [challenges](/microbit/lessons/screen-wipe/challenges) + +## Objectives + +* learn how to show a series of image frames on the LED screen, pausing the specified time after each frame +* learn how to run code when an input button is pressed +* learn how to turn off all the LED lights on the LED screen + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Shows an awareness of tasks best completed by humans or computers (EV) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (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) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Selects the appropriate data types(AL) (AB + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Recognises ethical issues surrounding the application of information technology beyond school. +* Designs criteria to critically evaluate the quality of solutions, uses the criteria to identify improvements and can make appropriate refinements to the solution (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/screen-wipe/tutorial) +* [quiz](/microbit/lessons/screen-wipe/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/screen-wipe/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/screen-wipe/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/screen-wipe/activity.md b/docs/reference/js/lessons/screen-wipe/activity.md new file mode 100644 index 00000000..4c298313 --- /dev/null +++ b/docs/reference/js/lessons/screen-wipe/activity.md @@ -0,0 +1,47 @@ +# screen wipe activity + +Clear the screen by pressing buttons on the BBC micro:bit #docs #tutorials #stepByStep + +### ~avatar avatar + +### @video td/videos/screen-wipe-0 + +This activity will teach how to clear the screen by pressing button ``A`` on the BBC micro:bit. + +### ~ + +You can use the `basic->clear screen` function to turn off all the LED on the screen. Let's illustrate this concept with a small script where the user has to press the button ``A`` to turn off the screen. Let's start by adding the code to show an animation. + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) // *** +``` + +We add another line of code that registers an **event handler** on the `input->on button pressed(A)` and calls `basic->clear screen`. + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() // *** +}) // *** +``` + +Run the script in the simulator or on the BBC micro:bit to see how this works! + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/screen-wipe/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/screen-wipe/challenges.md b/docs/reference/js/lessons/screen-wipe/challenges.md new file mode 100644 index 00000000..f617ba30 --- /dev/null +++ b/docs/reference/js/lessons/screen-wipe/challenges.md @@ -0,0 +1,73 @@ +# screen wipe challenges + +Coding challenges for the screen wipe tutorial. #docs + +## Before we get started + +Complete the [screen wipe](/microbit/lessons/screen-wipe) activity and your code will look like this: + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() +}) +``` + +**Challenge 1** + +Create an event handler for Button "B". + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() +}) +input.onButtonPressed("B", () => { +}) +``` + +**Challenge 2** + +### @video td/videos/screen-wipe-2 + +Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`. + +``` +basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +input.onButtonPressed("A", () => { + basic.clearScreen() +}) +input.onButtonPressed("B", () => { + basic.showAnimation(` +# # # # # # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) // *** +}) +``` + +**Challenge 3** + +Show an animation that scrolls back up when you press button "B". + +* tap the `run` button to view your final product! diff --git a/docs/reference/js/lessons/screen-wipe/quiz-answers.md b/docs/reference/js/lessons/screen-wipe/quiz-answers.md new file mode 100644 index 00000000..a69dda8e --- /dev/null +++ b/docs/reference/js/lessons/screen-wipe/quiz-answers.md @@ -0,0 +1,45 @@ +# screen wipe quiz answers + +clear the screen by pressing the "A" button after an animation has been played #LED #screen #variables #docs + +This is the answer key for the [screen wipe quiz](/microbit/lessons/screen-wipe/quiz). + +## 1. What does the function "clear screen" do on the BBC micro:bit? + +This function turns off all the LED lights on the LED screen. + +## 2. Write the line of code that creates and displays this animation. + +![](/static/mb/lessons/screen-wipe-0.png) + +
+ +``` +basic.showAnimation(` +# # # # . # # # # # . . . . . . . . . . +# # # # # # # # # # . . . . . . . . . . +. . . . . # # # # # # # # # # . . . . . +. . . . . # # # # # # # # # # # # # # # +. . . . . . . . . . . . . . . # # # # # +`, 400) +``` + +## 3. Write the condition that will detect when the BBC micro:bit is shaken. + +
+ +``` +input.onGesture(Gesture.Shake, () => { +}) +``` + +## 4. Write the code that will clear an animation from the screen after shaking the BBC micro:bit. + +
+ +``` +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() +}) +``` + diff --git a/docs/reference/js/lessons/screen-wipe/quiz.md b/docs/reference/js/lessons/screen-wipe/quiz.md new file mode 100644 index 00000000..0999e9df --- /dev/null +++ b/docs/reference/js/lessons/screen-wipe/quiz.md @@ -0,0 +1,32 @@ +# screen wipe quiz + +clear the screen by pressing the "A" button after an animation has been played #LED #screen #variables #docs #button + +## Name + +## Directions + +Use this activity document to guide your work in the [screen wipe tutorial](/microbit/lessons/screen-wipe/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What does the function "clear screen" do on the BBC micro:bit? + +
+ +## 2. We can show all of these images in one line of code. What method can we use to do this? + +![](/static/mb/lessons/screen-wipe-0.png) + +
+ +## 3. How can the BBC micro:bit detect when it is shaken? + +
+ +
+ +## 4. Write the code that will clear an animation from the screen after shaking the BBC micro:bit. + +
+ diff --git a/docs/reference/js/lessons/set-brightness/challenges.md b/docs/reference/js/lessons/set-brightness/challenges.md new file mode 100644 index 00000000..0ec3578f --- /dev/null +++ b/docs/reference/js/lessons/set-brightness/challenges.md @@ -0,0 +1,54 @@ +# set brightness challenges + +These challenges will allow you to change the brightness of the micro:bit. #docs + +**Challenge 0** + +### @video vimeo/133782335 + +[This tutorial](/microbit/lessons/set-brightness/tutorial) will show you how to set the brightness on the micro:bit. + +``` +led.setBrightness(255) +led.plotAll() +input.onButtonPressed("A", () => { + led.setBrightness(64) +}) +``` + +**Challenge 1** + +### @video vimeo/133782335 + +What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add a condition for `input->on button pressed("B")`. + +``` +led.setBrightness(255) +led.plotAll() +input.onButtonPressed("A", () => { + led.setBrightness(64) +}) +input.onButtonPressed("B", () => { +}) // *** +``` + +**Challenge 2** + +Inside of the condition `input->on button pressed("B")`, add `led->set brightness(0)` to turn off the LEDs. + +``` +led.setBrightness(255) +led.plotAll() +input.onButtonPressed("A", () => { + led.setBrightness(64) +}) +input.onButtonPressed("B", () => { + led.setBrightness(0) // *** +}) +``` + +**Challenge 3** + +Now, in the condition `input->on button pressed("B")`, add `basic->pause(1000)` and then set the brightness to a new value! + +* `Run` your script to see the LEDs change brightness. diff --git a/docs/reference/js/lessons/show-number/challenges.md b/docs/reference/js/lessons/show-number/challenges.md new file mode 100644 index 00000000..b5f9125e --- /dev/null +++ b/docs/reference/js/lessons/show-number/challenges.md @@ -0,0 +1,39 @@ +# show number challenges + +My script. #docs + +### Challenge 0 + +Welcome! This [guided tutorial](/microbit/xvogbz) will help you show a number on the LED screen! + +Show a number on the LED screen! One digit will display at a time, scrolling from left to right. + +Make lucky number 7 display on the screen! + +``` +basic.showNumber(7, 150) +``` + +### Challenge 1 + +But we also should pause before showing another number. + +``` +basic.showNumber(7, 150) +basic.pause(500) // *** +``` + +### Challenge 2 + +Let's display the next multiple of 7 on the screen! + +``` +basic.showNumber(7, 150) +basic.pause(500) +basic.showNumber(14, 150) // *** +``` + +### Challenge 3 + +Keep displaying multiples of 7 such as 21 and 28, but don't forget to add pauses between the numbers! + diff --git a/docs/reference/js/lessons/show-string/challenges.md b/docs/reference/js/lessons/show-string/challenges.md new file mode 100644 index 00000000..f7323230 --- /dev/null +++ b/docs/reference/js/lessons/show-string/challenges.md @@ -0,0 +1,38 @@ +# show string challenges + +My script. #docs + +**Challenge 0** + +Welcome! This [guided tutorial](/microbit/pxjkww) introduces the basic show string method on the micro:bit. + +Let's show the string 'Hello' on the LED screen. The string will scroll one character at a time from left to right. + +``` +basic.showString("Hello ", 150) +``` + +**Challenge 1** + +Now, let's show the string 'World' on the LED screen. + +``` +basic.showString("Hello ", 150) +basic.showString("World", 150) // *** +``` + +**Challenge 2** + +Let's display another string to introduce yourself! + +After 'Hello World' we want to display the string 'My name is '. + +``` +basic.showString("Hello World", 150) +basic.showString("Good Night World ", 150) // *** +``` + +**Challenge 3** + +Add Micro's response to Good Night World! + diff --git a/docs/reference/js/lessons/smiley.md b/docs/reference/js/lessons/smiley.md new file mode 100644 index 00000000..4bed3b35 --- /dev/null +++ b/docs/reference/js/lessons/smiley.md @@ -0,0 +1,87 @@ +# smiley lesson + +design a blinking image lesson #docs + +### @video td/videos/smiley-0 + +## Topic + +Show Animation + +## Quick Links + +* [activity](/microbit/lessons/smiley/activity) +* [quiz](/microbit/lessons/smiley/quiz) +* [quiz answers](/microbit/lessons/smiley/quiz-answers) +* [challenges](/microbit/lessons/smiley/challenges) +* [tutorial](/microbit/lessons/smiley/tutorial) + +## Class + +Year 7 + +## Prior learning / place of lesson in scheme of work + +Learn how to **Show LEDs** on the screen. We will be learning show animation, show LEDs and pause. + +## Documentation + +* **show animation** : [read more...](/microbit/reference/basic/show-animation) +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) + +## Objectives + +* learn how to show a series of image frames on the LED screen, pausing the specified time after each frame +* learn how to plot an image to show an image on the micro:bit's LED 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. +* [tutorial](/microbit/lessons/smiley/tutorial) +* [quiz](/microbit/lessons/smiley/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/smiley/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/smiley/challenges) + diff --git a/docs/reference/js/lessons/smiley/activity.md b/docs/reference/js/lessons/smiley/activity.md new file mode 100644 index 00000000..db9d65e7 --- /dev/null +++ b/docs/reference/js/lessons/smiley/activity.md @@ -0,0 +1,30 @@ +# smiley activity + +Learn to design a blinking image. #docs #microbit + +### ~avatar avatar + +### @video td/videos/smiley-0 + +Welcome! This tutorial will help you make a smiley face blink. Let's get started! + +### ~ + +Create an animation with a frame displaying a smiley face and the next frame with no LEDs lit up. This will make it look like the smiley face is blinking as the display switches between frames. + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . . . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) // *** +``` + +### ~avatar boothing + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/smiley/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/smiley/challenges.md b/docs/reference/js/lessons/smiley/challenges.md new file mode 100644 index 00000000..5b0a6a68 --- /dev/null +++ b/docs/reference/js/lessons/smiley/challenges.md @@ -0,0 +1,67 @@ +# smiley challenges + +Coding challenges for the smiley tutorial. #docs + +## Before we get started + +Complete the [smiley activity](/microbit/lessons/smiley/activity) and your code will look like this: + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . . . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +### Challenge 1 + +What if we want to make the face to frown when button `A` is pressed? + +Let's make add code that will run when button `A` is pressed! + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . . . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +input.onButtonPressed("A", () => { +}) // *** +``` + +### Challenge 2 + +### @video td/videos/smiley-2 + +Now, we want to show a frowny face when this button is pressed. Let's plot that image. + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . . . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +input.onButtonPressed("A", () => { + basic.showLeds(` +. # . # . +. # . # . +. . . . . +. # # # . +# . . . # +`, 400) // *** +}) +``` + +* Run your code to see if it works as expected. + +### Challenge 3 + +When button `B` is pressed, let's change the sad face back to a happy face. To do this, begin by adding a condition for `input->on button pressed(B)`. Then show a smiley face inside the condition. + diff --git a/docs/reference/js/lessons/smiley/quiz-answers.md b/docs/reference/js/lessons/smiley/quiz-answers.md new file mode 100644 index 00000000..0d308826 --- /dev/null +++ b/docs/reference/js/lessons/smiley/quiz-answers.md @@ -0,0 +1,78 @@ +# smiley quiz answers + +#LED #screen #animation #docs + +This is the answer key for the [smiley quiz](/microbit/lessons/smiley/quiz). + +## 1. Define 'show animation' : + +A function that will show a series of image frames on the LED screen, pausing the specified time after each frame. + +## 2. Why is there an extra empty frame after the smiley face? + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +
+ +
+ +The extra empty frame creates a blinking smiley, allowing the BBC micro:bit to alternate between showing the smiley and the empty screen. + +## 3. Change the delay shown from 400 milliseconds to 1000 milliseconds. + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +
+ +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 1000) +``` + +## 4. Now let's change the delay shown below from 400 milliseconds to 2.5 seconds. + +![](/static/mb/lessons/smiley-0.png) + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +
+ +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 2500) +``` + diff --git a/docs/reference/js/lessons/smiley/quiz.md b/docs/reference/js/lessons/smiley/quiz.md new file mode 100644 index 00000000..d9f0f981 --- /dev/null +++ b/docs/reference/js/lessons/smiley/quiz.md @@ -0,0 +1,54 @@ +# smiley quiz + +make a smiley face blink #LED #screen #animation #docs + +## Name + +## 1. Describe what `basic->show animation` does + +
+ +
+ +## 2. Why is there an extra empty frame after the smiley face? + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +
+ +## 3. Change the delay shown from 400 milliseconds to 1000 milliseconds. + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +
+ +## 4. Now let's change the delay shown below from 400 milliseconds to 2.5 seconds. + +``` +basic.showAnimation(` +. # . # . . . . . . +. # . # . . . . . . +. . # . . . . . . . +# . . . # . . . . . +. # # # . . . . . . +`, 400) +``` + +
+ diff --git a/docs/reference/js/lessons/snowflake-fall.md b/docs/reference/js/lessons/snowflake-fall.md new file mode 100644 index 00000000..078b9006 --- /dev/null +++ b/docs/reference/js/lessons/snowflake-fall.md @@ -0,0 +1,74 @@ +# snowflake fall lesson + +design a blinking rectangle animation #animation #loop #forever #docs + +### @video td/videos/snowflake-fall-0 + +## Topic + +Show Animation + +## Quick Links + +* [activity](/microbit/lessons/snowflake-fall/activity) +* [quiz](/microbit/lessons/snowflake-fall/quiz) +* [quiz answers](/microbit/lessons/snowflake-fall/quiz-answers) +* [challenges](/microbit/lessons/snowflake-fall/challenges) +* [tutorial](/microbit/lessons/snowflake-fall/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **animation**, `basic->show animation` to display an animated image. We will be learning how to create an animated image using forever loop as well as simple commands, such as show animation. + +## Documentation + +* **show animation** : [read more...](/microbit/reference/basic/show-animation) +* **forever** : [read more...](/microbit/reference/basic/forever) + +## Objectives + +* learn how to show a series of image frames on the LED screen, pausing the specified time after each frame +* learn how to repeat code in the background forever + +## 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) + +#### 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/snowflake-fall/activity) +* [quiz](/microbit/lessons/snowflake-fall/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/snowflake-fall/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/snowflake-fall/challenges) + diff --git a/docs/reference/js/lessons/snowflake-fall/activity.md b/docs/reference/js/lessons/snowflake-fall/activity.md new file mode 100644 index 00000000..78eaa2f8 --- /dev/null +++ b/docs/reference/js/lessons/snowflake-fall/activity.md @@ -0,0 +1,41 @@ +# snowflake fall activity + +design a blinking rectangle animation. #docs #tutorials #stepByStep + +### ~avatar avatar + +### @video td/videos/snowflake-fall-0 + +Welcome! This tutorial will teach how design a **snowfall animation**. Let's get started! + +### ~ + +Let's start by creating a `basic->forever` loop that will allow us to repeat the animation code. Any code in the `forever` loop will repeat in the background... forever. + +``` +basic.forever(() => { +}) // *** +``` + +The next step is to add `basic->show animation` inside the `forever` loop to repeat an animation. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . . . . . . +. . # . . . . . . . +. # # # . . . . . . +. . # . . . . . . . +. . . . . . . . . . +`, 400) // *** +}) +``` + +Run your code in the simulator or download it to your BBC micro:bit to see what happens! + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/snowflake-fall/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/snowflake-fall/challenges.md b/docs/reference/js/lessons/snowflake-fall/challenges.md new file mode 100644 index 00000000..fbc99e15 --- /dev/null +++ b/docs/reference/js/lessons/snowflake-fall/challenges.md @@ -0,0 +1,64 @@ +# snowflake fall challenges + +Coding challenges for the snowflake fall tutorial. #docs + +## Before we get started + +Complete the [snowflake fall](/microbit/lessons/snowflake-fall/activity) activity and your code will look like this: + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) +}) +``` + +### Challenge 1 + +### @video td/videos/snowflake-fall-1 + +Let's begin creating our falling effect by adding another snowflake with `basic->show animation` that displays a different snowflake pattern after the first one. We need 2 frames in the new animation that display both the first and the second snowflake images. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . . . # . . +. . # . . . # . # . +. # # # . # . . . # +. . # . . . # . # . +. . . . . . . # . . +`, 400) // *** +}) +``` + +* Run your program to see the cool animation. + +### Challenge 2 + +### @video td/videos/snowflake-fall-2 + +To finalize our snowflake fall, let's add a different snowflake pattern. + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . . . # . . . # . # . +. . # . . . # . # . # # . # # +. # # # . # . . . # . . . . . +. . # . . . # . # . # # . # # +. . . . . . . # . . . # . # . +`, 400) // *** +}) +``` + +* Run your program and see if it works. + +### Challenge 3 + +Add a fourth frame to the current animation... or make it your own! + diff --git a/docs/reference/js/lessons/snowflake-fall/quiz-answer.md b/docs/reference/js/lessons/snowflake-fall/quiz-answer.md new file mode 100644 index 00000000..24800c22 --- /dev/null +++ b/docs/reference/js/lessons/snowflake-fall/quiz-answer.md @@ -0,0 +1,70 @@ +# snowflake fall quiz answers + +create a snowflake fall animation #animation#forever #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [snowflake fall tutorial](/microbit/lessons/snowflake-fall/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. In reference to an animation, what is an "interval"? + +The number of milliseconds to pause after each image frame. + +## 2. Consider the following code + +``` +basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) +``` + +What is the `interval` of the animation? + +400 + +## 3. Consider the following image + +![](/static/mb/lessons/snowflake-fall-0.png) + +Write the code to create a `forever` loop that shows an animation. Change the interval from 400 to 200 to make the animation go twice as fast! + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . . . . . . +. . # . . . . . . . +. # # # . . . . . . +. . # . . . . . . . +. . . . . . . . . . +`, 200) +}) +``` + +## 4. Consider the following images + +![](/static/mb/lessons/snowflake-fall-1.png) + +![](/static/mb/lessons/snowflake-fall-2.png) + +Write the code to create a `forever` loop that shows an animation. Change the interval from 400 to 800 to make the animation go twice as slow! + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . # # # # # +. . # . . # # . # # +. # # # . # . # . # +. . # . . # # . # # +. . . . . # # # # # +`, 800) +}) +``` + diff --git a/docs/reference/js/lessons/snowflake-fall/quiz-answers.md b/docs/reference/js/lessons/snowflake-fall/quiz-answers.md new file mode 100644 index 00000000..0bec3e5d --- /dev/null +++ b/docs/reference/js/lessons/snowflake-fall/quiz-answers.md @@ -0,0 +1,56 @@ +# snowflake fall quiz answers + +create a snowflake fall animation #animation#forever #docs + +This is the answer key for the [snowflake fall quiz](/microbit/lessons/snowflake-fall/quiz). + +## 1. In reference to an animation, what is an "interval"? + +The number of milliseconds to pause after each image frame. + +## 2. What is the interval of the animation? + +``` +basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) +``` + +## 3. Write the code to allow this animation to never stop displaying on the BBC micro:bit + +![](/static/mb/lessons/snowflake-fall-0.png) + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) +}) +``` + +## 4. Write the code to create a forever loop that shows an animation of these images. Change the interval from 400 to 800 to make the animation go twice as slow! + +![](/static/mb/lessons/snowflake-fall-1.png) + +![](/static/mb/lessons/snowflake-fall-2.png) + +``` +basic.forever(() => { + basic.showAnimation(` +. . . . . # # # # # +. . # . . # # . # # +. # # # . # . # . # +. . # . . # # . # # +. . . . . # # # # # +`, 800) +}) +``` + diff --git a/docs/reference/js/lessons/snowflake-fall/quiz.md b/docs/reference/js/lessons/snowflake-fall/quiz.md new file mode 100644 index 00000000..e3bfe19d --- /dev/null +++ b/docs/reference/js/lessons/snowflake-fall/quiz.md @@ -0,0 +1,42 @@ +# snowflake fall quiz + +create a snowflake fall animation #animation#forever #docs + +## Name + +## Directions + +Use the hints in the [snowflake fall activity](/microbit/lessons/snowflake-fall/activity) to answer this quiz! + +## 1. In reference to an animation, what is an "interval"? + +
+ +## 2. What is the interval of the animation? + +``` +basic.showAnimation(` +. . . . . +. . # . . +. # # # . +. . # . . +. . . . . +`, 400) +``` + +
+ +## 3. How can we make this animation never stop displaying on the BBC micro:bit? + +![](/static/mb/lessons/snowflake-fall-0.png) + +
+ +## 4. Write the code to create a forever loop that shows an animation of these images. Change the interval from 400 to 800 to make the animation go twice as slow! + +![](/static/mb/lessons/snowflake-fall-1.png) + +![](/static/mb/lessons/snowflake-fall-2.png) + +
+ diff --git a/docs/reference/js/lessons/speed-button.md b/docs/reference/js/lessons/speed-button.md new file mode 100644 index 00000000..63092092 --- /dev/null +++ b/docs/reference/js/lessons/speed-button.md @@ -0,0 +1,133 @@ +# speed button lesson + +code a speed game by declaring Booleans on the BBC micro:bit #if #string #var #data #docs + +### @video td/videos/speed-button-3 + +## Topic + +Running Time + +## Quick Links + +* [tutorial](/microbit/lessons/speed-button/tutorial) +* [quiz](/microbit/lessons/speed-button/quiz) +* [quiz answers](/microbit/lessons/speed-button/quiz-answers) +* [challenges](/microbit/lessons/speed-button/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to declare a **Boolean** variable, `var t:= true` `var f:=false` for one of two possible values: true or false. We will be learning how to declare Boolean variables using global variables, if (conditionals), input on button pressed, input running time, as well as simple commands, such as input on button pressed, and show string. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Hardware: The physical systems and components of digital devices; see also software. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Repetition: Executing a section of computer code a number of times as part of the program. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **running time** : [read more...](/microbit/reference/input/running-time) +* **global variable** : [read more...](/microbit/js/data) +* **Boolean** : [read more...](/microbit/reference/types/boolean) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **if** : [read more...](/microbit/reference/logic/if) +* **show string** : [read more...](/microbit/reference/basic/show-string) + +## Resources + +* Activity: [tutorial](/microbit/lessons/speed-button/tutorial) +* Activity: [quiz](/microbit/lessons/speed-button/quiz) +* Extended Activity: [challenges](/microbit/lessons/speed-button/challenges) + +## Objectives + +* learn how to get the number of milliseconds elapsed since the script began. 1,000 milliseconds = 1 second +* learn how to create a global variable to store data so that you can use it later in your code and will be accessible across functions and in nested code blocks +* learn how to create a Boolean with one of two possible values: true or false +* learn how to run code when an input button is pressed +* learn how to conditionally run code depending on whether a condition is true or not +* learn how to show a string on the LED screen one character at a time + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL) +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB) +* Recognises that different algorithms exist for the same problem (AL) (GE) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* 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) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* 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) + +#### Communication Networks + +* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/speed-button/tutorial) +* [quiz](/microbit/lessons/speed-button/quiz) +* assessment opportunities: forever, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/speed-button/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/speed-button/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/speed-button/challenges.md b/docs/reference/js/lessons/speed-button/challenges.md new file mode 100644 index 00000000..1f265c4f --- /dev/null +++ b/docs/reference/js/lessons/speed-button/challenges.md @@ -0,0 +1,99 @@ +# speed button challenges + +Coding challenges for the speed button tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/speed-button/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +let counter = 0 +let fastPress = false +input.onButtonPressed("A", () => { + counter = counter + 1 +}) +``` + +### Challenge 1 + +We need to know when the user has hit button `A` 15 times. The user wins when he/she is able to accomplish this in less than 5000 milliseconds (5 seconds). We can check for both conditions by using an `and` operator. When using an `and` operator, both conditions need to be true in order for the condition to be true. + +``` +let counter1 = 0 +let fastPress1 = false +input.onButtonPressed("A", () => { + counter1 = counter1 + 1 + if (counter1 == 15 && input.runningTime() < 5000) { + } +}) +``` + +Next, if the user has won, let's set our boolean to true. This indicates that he or she has won. + +``` +let counter2 = 0 +let fastPress2 = false +input.onButtonPressed("A", () => { + counter2 = counter2 + 1 + if (counter2 == 15 && input.runningTime() < 5000) { + fastPress2 = true // *** + } +}) +``` + +### Challenge 2 + +We want to set `fastPress` to false if the user was too slow. To do so, we need another condition to see if the user took more than 5000 milliseconds (5 seconds). In the `if` statement, set `fastPress` to false. + +``` +let counter3 = 0 +let fastPress3 = false +input.onButtonPressed("A", () => { + counter3 = counter3 + 1 + if (counter3 == 15 && input.runningTime() < 5000) { + fastPress3 = true + } + if (counter3 == 15 && input.runningTime() > 4999) { + fastPress3 = false // *** + } +}) +``` + +### Challenge 3 + +### @video td/videos/speed-button-3 + +Now let's display if the user won or lost. To do so, we need to check the status of `fastPress` when the game is finished, and then show the correct message. + +``` +let counter4 = 0 +let fastPress4 = false +input.onButtonPressed("A", () => { + counter4 = counter4 + 1 + if (counter4 == 15 && input.runningTime() < 5000) { + fastPress4 = true + } + if (counter4 == 15 && input.runningTime() > 4999) { + fastPress4 = false + } + if (counter4 == 15 && fastPress4) { + basic.showString("YOU WIN!", 150) // *** + } + if (counter4 == 15 && ! fastPress4) { + basic.showString("TOO SLOW!", 150) // *** + } +}) +``` + +* Click the `run` button to see if the code runs properly. + +### Challenge 4 + +### @video td/videos/speed-button-4 + +Modify the code to change the difficulty level. Increasing the time will make it easier, while decreasing the time will make it harder. For example, changing the 5000 milliseconds to 6000 milliseconds will make the difficulty easier. + diff --git a/docs/reference/js/lessons/speed-button/quiz-answers.md b/docs/reference/js/lessons/speed-button/quiz-answers.md new file mode 100644 index 00000000..7e573099 --- /dev/null +++ b/docs/reference/js/lessons/speed-button/quiz-answers.md @@ -0,0 +1,50 @@ +# speed button quiz answers + +counter that keeps track of how many times button "A" has been pressed #LED #screen #variables #docs #input + +This is the answer key for the [speed button quiz](/microbit/lessons/speed-button/quiz). + +## 1. What is a variable? + +
+ +A variable that is available throughout your main function. + +## 2. If the rectangle below represents the BBC micro:bit, shade the area that shows the value of the variable count. + +``` +let count = 0 +``` + +![](/static/mb/lessons/speed-button-0.png) + +## 3. If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed after two button presses on Button A. Explain why that particular area is shaded. + +``` +let count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +
+ +![](/static/mb/lessons/speed-button-1.png) + +After two button presses, **count** will be equal to 2. + +## 5. If the rectangle below represents the BBC micro:bit, shade the areas that will be displayed after five button presses on Button A. Explain why that particular area is shaded. + +``` +count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +![](/static/mb/lessons/speed-button-2.png) + +After five button presses, **count** will be equal to 5. + diff --git a/docs/reference/js/lessons/speed-button/quiz.md b/docs/reference/js/lessons/speed-button/quiz.md new file mode 100644 index 00000000..cc9d2591 --- /dev/null +++ b/docs/reference/js/lessons/speed-button/quiz.md @@ -0,0 +1,50 @@ +# speed button quiz + +counter that keeps track of how many times button "A" has been pressed #LED #screen #variables #docs #input + +## Name + +## Directions + +Use this activity document to guide your work in the [speed button tutorial](/microbit/lessons/speed-button/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a variable? + +## 2. Draw which LEDs show the number being stored as a global variable called count + +``` +let count = 0 +``` + +![](/static/mb/empty-microbit.png) + +## 3. Draw which LED is ON after running this code and pressing Button A twice. Explain why you chose to draw that number + +``` +let count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +![](/static/mb/empty-microbit.png) + +
+ +## 4. Draw which LED is ON after running this code and pressing Button A five times. Explain why you chose to draw that number. + +``` +count_ = 0 +input.onButtonPressed("A", () => { + count_ = count_ + 1 + basic.showNumber(count_, 100) +}) +``` + +![](/static/mb/empty-microbit.png) + +
+ diff --git a/docs/reference/js/lessons/spinner.md b/docs/reference/js/lessons/spinner.md new file mode 100644 index 00000000..cd8335d0 --- /dev/null +++ b/docs/reference/js/lessons/spinner.md @@ -0,0 +1,96 @@ +# spinner lesson + +a spin the BBC micro:bit game with the input on shake #button #pressed #math #random #var #string #if #docs + +## Topic + +If (Conditionals) + +## Quick Links + +* [activity](/microbit/lessons/spinner/activity) +* [challenges](/microbit/lessons/spinner/challenges) +* [quiz](/microbit/lessons/spinner/quiz) +* [quiz answers](/microbit/lessons/spinner/quiz-answers) +* [tutorial](/microbit/lessons/spinner/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use an if statement **if condition do** 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, input on shake, a local variable, assignment operator, math random as well as simple commands such as plot image. + +## Documentation + +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **variable** : [read more...](/microbit/reference/variables/var) +* **assignment operator** : [read more...](/microbit/reference/variables/assignment) +* **math random** : [read more...](/microbit/js/math) +* **If** : [read more...](/microbit/reference/logic/if) +* **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 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 + +* 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/spinner/activity) +* [tutorial](/microbit/lessons/spinner/tutorial) +* [quiz](/microbit/lessons/spinner/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/spinner/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/spinner/challenges) + diff --git a/docs/reference/js/lessons/spinner/activity.md b/docs/reference/js/lessons/spinner/activity.md new file mode 100644 index 00000000..97492b43 --- /dev/null +++ b/docs/reference/js/lessons/spinner/activity.md @@ -0,0 +1,87 @@ +# spinner activity + +create an arrow that randomly points to a player. #docs + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**. + +Let's begin by adding an `input->on shake` condition to know when the BBC micro:bit is shaken. + +``` +input.onGesture(Gesture.Shake, () => { +}) +``` + +Now let's randomly generate a number from 0 to 3 so that we can randomly display an arrow in a given direction. + +``` +input.onGesture(Gesture.Shake, () => { + let randomArrow = Math.random(4) +}) +``` + +Now let's handle each of the cases by displaying the appropriate arrow. (Let's display an up arrow if `random arrow` is 0. + +``` +input.onGesture(Gesture.Shake, () => { + let randomArrow1 = Math.random(4) + if (randomArrow1 == 0) { + basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) + } +}) +``` + +Now let's handle the rest of the cases for `random arrow`. + +``` +input.onGesture(Gesture.Shake, () => { + let randomArrow2 = Math.random(4) + if (randomArrow2 == 0) { + basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) + } else if (randomArrow2 == 1) { + basic.showLeds(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`, 400) + } + else if (randomArrow2 == 2) { + basic.showLeds(` +. . # . . +. . # # . +# # # # # +. . # # . +. . # . . +`, 400) + } + else if (randomArrow2 == 3) { + basic.showLeds(` +. . # . . +. # # . . +# # # # # +. # # . . +. . # . . +`, 400) + } +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/spinner/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/spinner/challenges.md b/docs/reference/js/lessons/spinner/challenges.md new file mode 100644 index 00000000..61d1d5c4 --- /dev/null +++ b/docs/reference/js/lessons/spinner/challenges.md @@ -0,0 +1,156 @@ +# spinner challenges + +create an arrow that randomly points to a player. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/spinner/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +input.onGesture(Gesture.Shake, () => { + let randomArrow = Math.random(4) + if (randomArrow == 0) { + basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) + } + if (randomArrow == 1) { + basic.plotImage(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`) + } + if (randomArrow == 2) { + basic.plotImage(` +. . # . . +. . # # . +# # # # # +. . # # . +. . # . . +`) + } + if (randomArrow == 3) { + basic.plotImage(` +. . # . . +. # # . . +# # # # # +. # # . . +. . # . . +`) + } +}) +``` + +### Challenge 1 + +Modify the random number generator so that it can include new arrows we will create in the next challenge. + +``` +input.onGesture(Gesture.Shake, () => { + let randomArrow1 = Math.random(8) // *** + // **. . .** + if (randomArrow1 == 4) { + basic.plotImage(` +# # # # . +# # # . . +# # # . . +# . . # . +. . . . # +`) + } + if (randomArrow1 == 5) { + basic.plotImage(` +. # # # # +. . # # # +. . # # # +. # . # # +# . . . . +`) + } + if (randomArrow1 == 6) { + basic.plotImage(` +# . . . . +. # . . # +. . # # # +. . # # # +. # # # # +`) + } + if (randomArrow1 == 7) { + basic.plotImage(` +. . . . # +# . . # . +# # # . . +# # # . . +# # # # . +`) + } +}) +``` + +* Do **not** run the code yet because it will not work until you have conditions for every random number. + +### Challenge 2 + +Let's add four more arrows that point diagonally. + +``` +input.onGesture(Gesture.Shake, () => { + let randomArrow2 = Math.random(4) + // **. . .** + if (randomArrow2 == 4) { + basic.plotImage(` +# # # # . +# # # . . +# # # . . +# . . # . +. . . . # +`) // *** + } + if (randomArrow2 == 5) { + basic.plotImage(` +. # # # # +. . # # # +. . # # # +. # . # # +# . . . . +`) // *** + } + if (randomArrow2 == 6) { + basic.plotImage(` +# . . . . +. # . . # +. . # # # +. . # # # +. # # # # +`) // *** + } + if (randomArrow2 == 7) { + basic.plotImage(` +. . . . # +# . . # . +# # # . . +# # # . . +# # # # . +`) // *** + } +}) +``` + +* Run your code to see if it works as expected + +### Challenge 3 + +Add some other arrows if there are more than 8 players. + diff --git a/docs/reference/js/lessons/spinner/quiz-answers.md b/docs/reference/js/lessons/spinner/quiz-answers.md new file mode 100644 index 00000000..327ae2d9 --- /dev/null +++ b/docs/reference/js/lessons/spinner/quiz-answers.md @@ -0,0 +1,56 @@ +# spinner quiz answers + +a spin the BBC micro:bit game with the input on shake #math #random #docs #shake + +## Name + +## Directions + +Use this activity document to guide your work in the [spinner tutorial](/microbit/lessons/spinner/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that stores a random number between 0 and 3 into a local variable named 'random arrow'. + +
+ +``` +let randomArrow = Math.random(4) +``` + +## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1. + +![](/static/mb/lessons/spinner-0.png) + +
+ +``` +if (randomArrow == 1) { + basic.plotImage(` +. . # . . +. . # . . +# # # # # +. # # # . +. . # . . +`) +} +``` + +## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2. + +![](/static/mb/lessons/spinner-1.png) + +
+ +``` +if (randomArrow == 2) { + basic.plotImage(` +. . # . . +. . # # . +# # # # # +. . # # . +. . # . . +`) +} +``` + diff --git a/docs/reference/js/lessons/spinner/quiz.md b/docs/reference/js/lessons/spinner/quiz.md new file mode 100644 index 00000000..9f5d2768 --- /dev/null +++ b/docs/reference/js/lessons/spinner/quiz.md @@ -0,0 +1,28 @@ +# spinner quiz + +a spin the BBC micro:bit game with the input on shake #math #random #docs #shake + +## Name + +## Directions + +Use this activity document to guide your work in the [spinner tutorial](/microbit/lessons/spinner/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that stores a random number between 0 and 3 into a local variable named 'random arrow'. + +
+ +## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1. + +![](/static/mb/lessons/spinner-0.png) + +
+ +## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2. + +![](/static/mb/lessons/spinner-1.png) + +
+ diff --git a/docs/reference/js/lessons/strobe-light.md b/docs/reference/js/lessons/strobe-light.md new file mode 100644 index 00000000..45f861ae --- /dev/null +++ b/docs/reference/js/lessons/strobe-light.md @@ -0,0 +1,76 @@ +# strobe light lesson + +Learn how to create a blinking LED script. #LED #screen #plot #docs + +### @video td/videos/strobe-light-0 + +## Topic + +For Loop + +## Quick links + +* [tutorial](/microbit/lessons/strobe-light/tutorial) +* [quiz](/microbit/lessons/strobe-light/quiz) +* [quiz answers](/microbit/lessons/strobe-light/quiz-answers) +* [challenges](/microbit/lessons/strobe-light/challenges) + +## Class + +Year 7 + +## Documentation + +* **for loop**: [read more...](/microbit/reference/loops/for) +* **plot**: [read more...](/microbit/reference/led/plot) +* **unplot**: [read more...](/microbit/reference/led/unplot) +* **pause**: [read more...](/microbit/reference/basic/pause) + +## Objectives + +* learn how to repeat code a fixed number of times +* learn how to turn on a LED light on the LED screen. Specify with LED using x, y coordinates +* learn how to turn off a LED light on the LED screen. Specify which LED which x, y coordinates +* learn how to pause program execution for the specified number of milliseconds + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses logical reasoning to predict outputs, showing an awareness of inputs. (AL) +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Uses a variable and relational operators within a loop to govern termination. (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 10 min. +* [tutorial](/microbit/lessons/strobe-light/tutorial) +* [quiz](/microbit/lessons/strobe-light/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/strobe-light/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/strobe-light/challenges) + diff --git a/docs/reference/js/lessons/strobe-light/challenges.md b/docs/reference/js/lessons/strobe-light/challenges.md new file mode 100644 index 00000000..c9e8c5a6 --- /dev/null +++ b/docs/reference/js/lessons/strobe-light/challenges.md @@ -0,0 +1,76 @@ +# strobe light challenges + +Coding challenges for the strobe light tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/strobe-light/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + basic.pause(200) + } +} +``` + +### Challenge 1 + +### @video td/videos/strobe-light-1 + +Make the LEDs light up faster by changing the **pause** from 200 to 100 milliseconds: + +``` +for (let i1 = 0; i1 < 5; i1++) { + for (let j1 = 0; j1 < 5; j1++) { + led.plot(i1, j1) + basic.pause(100) // *** + } +} +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +### @video td/videos/strobe-light-2 + +Make the board light up by rows instead of by columns by swapping the `i` and `j` variables in `led->plot(i, j)`. + +``` +for (let i2 = 0; i2 < 5; i2++) { + for (let j2 = 0; j2 < 5; j2++) { + led.plot(j2, i2) // *** + basic.pause(100) + } +} +``` + +* Run the code to see if it works as expected. + +### Challenge 3 + +### @video td/videos/strobe-light-ultimate + +Now that all the LEDs are lit up, let's make them turn off by reversing the strobe light pattern! You can use `led->unplot` to turn off a single LED. + +``` +for (let i3 = 0; i3 < 5; i3++) { + for (let j3 = 0; j3 < 5; j3++) { + led.plot(j3, i3) + basic.pause(100) + } +} +for (let k = 0; k < 5; k++) { + for (let l = 0; l < 5; l++) { + led.unplot(4 - l, 4 - k) // *** + basic.pause(100) // *** + } +} +``` + diff --git a/docs/reference/js/lessons/strobe-light/lesson-plan.md b/docs/reference/js/lessons/strobe-light/lesson-plan.md new file mode 100644 index 00000000..f65f3671 --- /dev/null +++ b/docs/reference/js/lessons/strobe-light/lesson-plan.md @@ -0,0 +1,100 @@ +# strobe light lesson plan + +Learn how to create a blinking LED script. #LED #screen #plot #docs + +## Topic + +For loop - Blinking LED + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to control a blinking LED. We will be learning how to create a blinking app using the for loop as well as simple commands, such as plot and pause. + +## What the teacher needs to know + +**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.** + +**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem** + +**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces a While Loop. While Loop is a while loop that will repeat code forever while - true. + +**Command:** An instruction for the computer to execute, written in a particular programming language.** + +**QuickStart Computing Glossary + +## Documentation + +* **plot**: [read more...](/microbit/reference/led/plot) +* **pause**: [read more...](/microbit/reference/basic/pause) +* **for loop**: [read more...](/microbit/reference/loops/for) + +## Resources + +* Activity: [tutorial](/microbit/lessons/strobe-light/tutorial) +* Activity: [quiz](/microbit/lessons/strobe-light/quiz) +* Extended Activity: [challenges](/microbit/lessons/strobe-light/challenges) + +## Objectives + +* learn how to blink a light +* create a for loop that will loop through each x-value, y-value from 0 to 4. +* learn how to pause the light on and off +* learn how to repeat turning on and off the light + +## Links to the National Curriculum Programmes of Study for Computing + +## Assessment + +**Progression Pathways:** + +**Computational Thinking Framework:** + +#### Algorithms + +* Uses logical reasoning to predict outputs, showing an awareness of inputs. (AL) +* Understands that iteration is the repetition of a process such as a loop. (AL) +* Represents solutions using a structured notation. (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals. (AL) +* Uses a variable and relational operators within a loop to govern termination. (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) + +#### Data & Data Representation + +* Understands the difference between data and information. (AB) +* Defines data types: real numbers and Boolean. (AB) + +#### Information Technology + +* Collects, organises and presents data and information in digital content. (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 10 min. +* [tutorial](/microbit/lessons/strobe-light/tutorial) +* [quiz](/microbit/lessons/strobe-light/quiz) +* assessment opportunities: loops, plot, pause, clear screen + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/strobe-light/challenges) +* assessment opportunities: loops, plot, pause, clear screen + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/strobe-light/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/strobe-light/quiz-answers.md b/docs/reference/js/lessons/strobe-light/quiz-answers.md new file mode 100644 index 00000000..b6bb6fc5 --- /dev/null +++ b/docs/reference/js/lessons/strobe-light/quiz-answers.md @@ -0,0 +1,70 @@ +# strobe light quiz answers + +Learn how to create a blinking images with a for loop. #LED #screen #plot #docs + +This is the answer key for the [strobe light quiz](/microbit/lessons/strobe-light/quiz). + +## 1. What is a for loop? + +Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates. + +## 2. Consider the following code + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-0.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs + +``x`` - the x coordinate or horizontal position (0,1,2,3,4) + +``y`` - the y coordinate or vertical position (0,1,2,3,4) + +## 3. Consider the following code + +``` +for (let i1 = 0; i1 < 3; i1++) { + for (let j1 = 0; j1 < 3; j1++) { + led.plot(i1, j1) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-1.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +``x`` - the x coordinate or horizontal position (0,1,2) + +``y`` - the y coordinate or vertical position (0,1,2) + +## 4. Consider the following code + +``` +for (let i2 = 0; i2 < 2; i2++) { + for (let j2 = 0; j2 < 2; j2++) { + led.plot(i2, j2) + } +} +``` + +If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there. + +![](/static/mb/lessons/cascade-2.png) + +This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. + +``x`` - the x coordinate or horizontal position (0,1) + +``y`` - the y coordinate or vertical position (0,1) + diff --git a/docs/reference/js/lessons/strobe-light/quiz.md b/docs/reference/js/lessons/strobe-light/quiz.md new file mode 100644 index 00000000..e9257efa --- /dev/null +++ b/docs/reference/js/lessons/strobe-light/quiz.md @@ -0,0 +1,50 @@ +# strobe light quiz + +Learn how to create a blinking LED script with a for loop. #LED #screen #plot #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [strobe light tutorial](/microbit/lessons/strobe-light/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a for loop? + +## 2. Draw which LEDs are ON after running this code + +``` +for (let i = 0; i < 5; i++) { + for (let j = 0; j < 5; j++) { + led.plot(i, j) + } +} +``` + +![](/static/mb/empty-microbit.png) + +## 3. Draw which LEDs are ON after running this code + +``` +for (let i1 = 0; i1 < 3; i1++) { + for (let j1 = 0; j1 < 3; j1++) { + led.plot(i1, j1) + } +} +``` + +![](/static/mb/empty-microbit.png) + +## 4. Draw which LEDs are ON after running this code + +``` +for (let i2 = 0; i2 < 2; i2++) { + for (let j2 = 0; j2 < 2; j2++) { + led.plot(i2, j2) + } +} +``` + +![](/static/mb/empty-microbit.png) + diff --git a/docs/reference/js/lessons/teach.md b/docs/reference/js/lessons/teach.md new file mode 100644 index 00000000..3e23323a --- /dev/null +++ b/docs/reference/js/lessons/teach.md @@ -0,0 +1,78 @@ +# Teach + +Overview of Touch Develop lesson instructions for the BBC micro:bit. #docs #contents + +### @short Teach + +The [lessons](/microbit/lessonss) promote computational thinking and computer science literacy from an early age and provide opportunities for learning these skills within the context of public and private education, where they will be available to Year 7 students. This page is a 'how to manual' for using the lessons in the classroom. + +### @section full + +## Summary + +The [lessons](/microbit/lessonss) promote computational thinking and computer science literacy from an early age and provide opportunities for learning these skills within the context of public education, where they will be available to Year 7 students. You will find comprehensive teacher training and preparation (lesson plans, videos, guided tutorials, quiz, challenges, and quiz answers). The curriculum has been organized for students from Beginner to Advanced lessons in an effort to build student confidence with computational thinking and coding concepts. The lesson has been constructed with a teacher lesson plan, video(s), tutorial, quiz, challenges, and quiz answers to demonstrate mastery with the Progression Pathways and Computational Thinking Framework. The lesson should occur on-site during a single instructional block. + +## Lesson Resources + +1) Lesson Plan + +The lesson plan maps to the Progressions Pathways, Computing Curriculum, and QuickStart Computing Glossary. The lesson plan explains the concepts being taught for computational thinking while supporting your classroom instruction. A lesson plan also contains Quick Links to the lesson's tutorial, challenges, quiz, and quiz answers as shown in the [blink lesson plan](/microbit/lessons/blink). + +2) Tutorial + +Expand your knowledge of programming with lots of great step-by-step tutorials. All the lessons come with interactive step-by-step tutorials that will drive the students to a complete, functional code. These tutorials are very directive to make sure that students keep progressing. When the tutorials are over, additional challenges are given to advance code through printed instructions. Tutorials contain supporting videos as shown with the [blink tutorial](/microbit/lessons/blink/tutorial). + +### @video td/videos/blink-0 + +3) Quiz + +Expand your knowledge of computational thinking and computer science literacy with lots of great quizzes. All the tutorials come with quiz questions that will encourage the students to process and evaluate the concepts being introduced throughout the lesson. The quiz questions are mapped to the concepts being introduced in the lesson to make sure that students understand the computer science concepts. Quizzes apply the concepts taught in the tutorial as shown with the [blink quiz](/microbit/lessons/blink/quiz). + +4) Quiz Answers + +The quiz answers provide responses to the quiz. This will allow teachers to accurately review and grade student responses. Please review a sample of the quiz answers provided with the [blink quiz answers](/microbit/lessons/blink/quiz-answers). + +5) Challenges + +After the student completes the quiz, tutorial, and compiles the code onto the BBC micro:bit, distribute the lesson’s challenges. Challenges are additional customising and exercises for the students. Challenges reinforce the concepts followed in the tutorial and quiz responses as shown with the [blink challenges](/microbit/lessons/blink/challenges). + +## Teacher Directions + +1) Teacher select a lesson from the [lessons](/microbit/lessonss) + +2) Print the quiz and the challenges for each student + +3) Print the quiz answers from you + +4) Distribute the printed quiz for every student + +5) Complete quiz questions by following the the guided tutorials + +6) Compile the code from the tutorial onto the BBC micro:bit + +7) Distribute the challenges for additional coding through paper instructions + +## Teacher Supplies + +1) Print: Lesson Quiz (1 copy per student) + +2) Print: Lesson Challenge (1 copy per student) + +## Lesson Timeline + +``00:00`` Introduce Lesson Objectives (as mentioned in the lesson plan) + +``05:00`` Distribute Lesson Quiz + +``07:00`` Access BBC micro:bit website + +``10:00`` Start Lesson Tutorial & Lesson Quiz + +``30:00`` Finish Lesson Tutorial & Lesson Quiz + +``35:00`` Start Lesson Challenges + +``55:00`` Finish Lesson + +``60:00`` Homework: Complete Challenges + diff --git a/docs/reference/js/lessons/telegraph.md b/docs/reference/js/lessons/telegraph.md new file mode 100644 index 00000000..adcd5537 --- /dev/null +++ b/docs/reference/js/lessons/telegraph.md @@ -0,0 +1,25 @@ +# telegraph lesson + +display beautiful images on the BBC micro:bit #var #pause #docs + +## Topic + +Telegraph + +## Quick Links + +* [activity](/microbit/lessons/telegraph/activity) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to convert your BBC micro:bit into a telegraph using a second BBC micro:bit as well as pin P1, P2, 3V, GND, and crocodile clips (or spring clips). The connect BBC micro:bit uses pins P1, P2, 3V, GND. + +## Objectives + +* learn how to setup the BBC micro:bit with crocodile clips +* learn how to telegraph to another BBC micro:bit + diff --git a/docs/reference/js/lessons/telegraph/activity.md b/docs/reference/js/lessons/telegraph/activity.md new file mode 100644 index 00000000..a77182b3 --- /dev/null +++ b/docs/reference/js/lessons/telegraph/activity.md @@ -0,0 +1,76 @@ +# telegraph activity + +build a telgraph #microbit #docs + +# BBC micro:bit telegraph + +![](/static/mb/lessons/telegraph-0.png) + +In this project, you will build your telegraph between BBC micro:bits. Project duration: 15 minutes. + +## Materials + +* BBC 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 BBC micro:bit. + +### Step 2 + +![](/static/mb/lessons/ornament-chain-2.png) + +Using the 2nd crocodile clip, connect the end of the crocodile clip onto the 3V pin on the BBC micro:bit. + +### Step 3 + +![](/static/mb/lessons/ornament-chain-3.png) + +Using the 3rd crocodile clip, connect the end of the crocodile clip onto pin 1 of the BBC micro:bit. + +### Step 4 + +![](/static/mb/lessons/ornament-chain-4.png) + +Using the 4th crocodile clip, connect the end of the crocodile clip onto pin 2 of the BBC micro:bit. + +### Step 5 + +![](/static/mb/lessons/ornament-chain-5.png) + +Using the 1st crocodile clip, connect the unattached end of the crocodile clip onto the GND on the 2nd BBC micro:bit. + +### Step 6 + +![](/static/mb/lessons/ornament-chain-6.png) + +Using the 2nd crocodile clip, connect the unattached end of the crocodile clip onto the 3V pin on the 2nd BBC micro:bit. + +### Step 7 + +![](/static/mb/lessons/ornament-chain-7.png) + +Using the 3rd crocodile clip, connect the unattached end of the crocodile clip onto pin 2 of the 2nd BBC micro:bit. + +### Step 8 + +![](/static/mb/lessons/ornament-chain-8.png) + +Using the 4th crocodile clip, connect the unattached end of the crocodile clip onto pin 1 of the 2nd BBC micro:bit + +### Step 9 + +![](/static/mb/lessons/telegraph-0.png) + +Your telegraph is ready! + +### Step 10 + +* Connect the first BBC micro:bit to your computer using your USB cable and run the [telegraph](/microbit/xvmxti) script on it. +* Connect the second BBC micro:bit to your computer using your USB cable and run the [telegraph](/microbit/xvmxti) script on it. +* The first person and second person take turns pressing button A to play the telegraph game! diff --git a/docs/reference/js/lessons/temperature.md b/docs/reference/js/lessons/temperature.md new file mode 100644 index 00000000..6e551c86 --- /dev/null +++ b/docs/reference/js/lessons/temperature.md @@ -0,0 +1,77 @@ +# temperature lesson + +measure the temperature on the BBC micro:bit #temp #var #docs + +## Topic + +Temperature + +## Quick Links + +* [activity](/microbit/lessons/temperature/activity) +* [challenges](/microbit/lessons/temperature/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit. We will be learning how to get the temperature using on shake, local variables, as well as simple commands such as show number. + +## Documentation + +* **on shake** : [read more...](/microbit/reference/input/on-gesture) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **temperature** : [read more...](/microbit/reference/input/temperature) +* **show number** : [read more...](/microbit/reference/basic/show-number) +* **show string** : [read more...](/microbit/reference/basic/show-string) + +## Objectives + +* learn how to create a variable to store data +* learn how to get the ambient temperature (degree Celsius °C). The temperature is inferred from the the surface temperature of the various chips on the micro:bit. +* learn how to show a number on the LED screen + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* 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) +* Recognises that different algorithms exist for the same problem (AL) (GE) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Understands the difference between, and appropriately uses if and if, then and else statements(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) +* 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/temperature/activity) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/temperature/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/temperature/challenges) + diff --git a/docs/reference/js/lessons/the-hat-game.md b/docs/reference/js/lessons/the-hat-game.md new file mode 100644 index 00000000..66fd98c4 --- /dev/null +++ b/docs/reference/js/lessons/the-hat-game.md @@ -0,0 +1,71 @@ +# the hat game lesson + +make a game to test your focus on the moving ball #function #on-button-pressed #if #show-animation #mod #random #Boolean #docs + +## Topic + +Functions + +## Quick Links + +* [tutorial](/microbit/lessons/the-hat-game/tutorial) +* [quiz](/microbit/lessons/the-hat-game/quiz) +* [quiz answers](/microbit/lessons/the-hat-game/quiz-answers) +* [challenges](/microbit/lessons/the-hat-game/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, `function()` as a unit of code that performs a specific task and returns a result. We will be learning how to create the hat game app using functions, global variables, input on button pressed, if (conditionals), mod, random, Boolean, as well as simple commands such as show animation. + +## Documentation + +* **functions** : [read more...](/microbit/js/function) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **for** : [read more...](/microbit/reference/loops/for) +* **if** : [read more...](/microbit/reference/logic/if) +* **mod** : [read more...](/microbit/js/math) +* **show animation** : [read more...](/microbit/reference/basic/show-animation) + +## Objectives + +* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks +* learn how to learn how to conditionally run code depending on whether a condition is true or false +* learn how to return the modulus +* learn how to show a series of image frames on the LED 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) +* Represents solutions using a structured notation (AL) (AB) + +#### Programming & Development + +* Creates programs that implement algorithms to achieve given goals (AL) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### Data & Data Representation + +* Understands the difference between data and information(AB) +* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV) +* Defines data types: real numbers and Boolean (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + diff --git a/docs/reference/js/lessons/the-hat-game/challenges.md b/docs/reference/js/lessons/the-hat-game/challenges.md new file mode 100644 index 00000000..7b3a4bd0 --- /dev/null +++ b/docs/reference/js/lessons/the-hat-game/challenges.md @@ -0,0 +1,174 @@ +# the hat game challenges + +The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to chose the hat with the ball after the hats have finished swapping. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/the-hat-game/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +initializeGame() +playLevel() +input.onButtonPressed("A", () => { + selectHat() +}) +input.onButtonPressed("B", () => { + chooseHat() +}) +``` + +### Challenge 1 + +Modify `play level()` to customize your difficulty levels. Simply increase the `swap speed` to make the game easier, or decrease it to make the game harder. + +``` +/** + * **. . .** + */ +export function playLevel_() { + let swaps = 5 + 10 * level + if (level == 1) { + swaps = 100 // *** + } else if (level == 2) { + swapSpeed = 40 // *** + } + else { + swapSpeed = 20 // *** + } + // **. . .** +} +``` + +### Challenge 2 + +Let's make the game a little more fun and devious! Let's add a `fake swap` function that pretends to swap the hats, but doesn't actually swap them. + +``` +export function fakeSwap(hat_1: number, hat_2: number, pauseDifficulty: number) { + if (hat_1 == 0 && hat_2 == 1) { + basic.showAnimation(` +. . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . . . +. . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . . . +# . # . # . . . . # . . . . # . . . . # . . . . # . . . . # # . # . # +. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . +. . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . . . +`, pauseDifficulty) + } + if (hat_1 == 1 && hat_2 == 0) { + basic.showAnimation(` +. . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . . . +. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . +# . # . # . . . . # . . . . # . . . . # . . . . # . . . . # # . # . # +. . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . . . +. . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . . . +`, pauseDifficulty) + } + if (hat_1 == 1 && hat_2 == 2) { + basic.showAnimation(` +. . . . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . +. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . +# . # . # # . . . . # . . . . # . . . . # . . . . # . . . . # . # . # +. . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . +. . . . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . +`, pauseDifficulty) + } + if (hat_1 == 2 && hat_2 == 1) { + basic.showAnimation(` +. . . . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . +. . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . +# . # . # # . . . . # . . . . # . . . . # . . . . # . . . . # . # . # +. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . +. . . . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . +`, pauseDifficulty) + } + if (hat_1 == 0 && hat_2 == 2) { + basic.showAnimation(` +. . . . . . . . . . # . . . . . # . . . . . # . . . # . . . # . . . . . . . . . . . . . . +. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . +# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . # +. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . +. . . . . . . . . . . . . . # . . . # . . . # . . . . . # . . . . . # . . . . . . . . . . +`, pauseDifficulty) + } + if (hat_1 == 2 && hat_2 == 0) { + basic.showAnimation(` +. . . . . . . . . . . . . . # . . . # . . . # . . . . . # . . . . . # . . . . . . . . . . +. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . +# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . # +. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . +. . . . . . . . . . # . . . . . # . . . . . # . . . # . . . # . . . . . . . . . . . . . . +`, pauseDifficulty) + } +} +``` + +### Challenge 3 + +Now let's implement our `fake swap` function inside `play level`. Let's make a third of the swaps fake. This can be most efficiently accomplished through mod. + +``` +/** + * **. . .** + */ +export function playLevel_1() { + let swaps = 5 + 10 * level + // **. . .** + for (let i = 0; i < swaps; i++) { + let swapType = Math.random(3) // *** + let not = Math.random(3) + if (swapType < 2) { + swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // *** + } else { + fakeSwap(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // *** + } + } + index = -1 + choosingHat = true +} +``` + +### Challenge 4 + +For a swap of two given hats, one of the hats will always go up while the other goes down. For example, if the first and third hats are swapping, the first hat will always go down and the third will go up. Let's randomize the orientation of each swap by switching the parameters of each swap function half the time. + +``` +/** + * **. . .** + */ +export function playLevel_2() { + let swaps = 5 + 10 * level + // **. . .** + for (let i = 0; i < swaps; i++) { + let swapType = Math.random(3) + let not = Math.random(3) + let swapOrientation = Math.random(2) // *** + if (swapType < 2) { + if (swapOrientation == 0) { + swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // *** + } else { + swapHats(math.mod(not + 2, 3), math.mod(not + 1, 3), swapSpeed) // *** + } + } + else { + swapOrientation = Math.random(2) // *** + if (swapOrientation == 0) { + fakeSwap(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // *** + } + else { + fakeSwap(math.mod(not + 2, 3), math.mod(not + 1, 3), swapSpeed) // *** + } + } + } + index = -1 + choosingHat = true +} +``` + +### Challenge 5 + +Create your own swap animation. See if you can get all three hats to move at the same time! + diff --git a/docs/reference/js/lessons/the-hat-game/quiz-answers.md b/docs/reference/js/lessons/the-hat-game/quiz-answers.md new file mode 100644 index 00000000..54671518 --- /dev/null +++ b/docs/reference/js/lessons/the-hat-game/quiz-answers.md @@ -0,0 +1,87 @@ +# the hat game quiz answers + +The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to chose the hat with the ball after the hats have finished swapping. #LED #number #math #functions #return #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [the hat game tutorial](/microbit/lessons/the-hat-game/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is the name of the first function you created? What does it do? + +
+ +Initialize game() is the name of the first function. It helps set up the game state. + +## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2). + +
+ +``` +for (let i = 0; i < 3; i++) { + led.plot(i * 2, 2) +} +``` + +## 3. How can you increase the difficulty of the game? + +
+ +Decrease the swap speed value. This will reduce the pause between each frame, and will thus make the game run faster. + +## 4. Consider the following code + +``` +cupSelect = "LMR" +index = -1 +``` + +Write the code that displays the next letter of the string in "cup select" when button A is pressed. + +
+ +
+ +``` +input.onButtonPressed("A", () => { + index = index + 1 + if (index > 2) { + index = 0 + } + basic.showString(cupSelect[index], 150) +}) +``` + +## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2. + +
+ +``` +basic.showAnimation(` +. . . . . . . . . . # . . . . . # . . . . . # . . . . . # . . . . . # . . . . . . . . . . +. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . +# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . # +. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . . +. . . . . . . . . . . . . . # . . . # . . . # . . . # . . . # . . . . . . . . . . . . . . +`, 400) +``` + +## 6. Consider the following code + +``` +let not = Math.random(3) +``` + +Given the hat we are not going to swap, how can we calculate the other two hats that we are going to swap? Use these two values to call "swap hats()" with a swap speed of 50. + +
+ +``` +swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), 50) +``` + +
+ diff --git a/docs/reference/js/lessons/the-hat-game/quiz.md b/docs/reference/js/lessons/the-hat-game/quiz.md new file mode 100644 index 00000000..d0073d18 --- /dev/null +++ b/docs/reference/js/lessons/the-hat-game/quiz.md @@ -0,0 +1,59 @@ +# the hat game quiz + +The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to choose the hat with the ball after the hats have finished swapping. #LED #number #math #functions #return #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [the hat game tutorial](/microbit/lessons/the-hat-game/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is the name of the first function you created? What does it do? + +
+ +## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2). + +
+ +## 3. How can you increase the difficulty of the game? + +
+ +## 4. Consider the following code + +``` +cupSelect = "LMR" +index = -1 +``` + +Write the code that displays the next letter of the string in "cup select" when button A is pressed. + +
+ +
+ +
+ +
+ +
+ +## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2. + +
+ +## 6. Consider the following code + +``` +let not = Math.random(3) +``` + +Given the hat we are not going to swap, how can we calculate the other two hats that we are going to swap? Use these two values to call "swap hats()" with a swap speed of 50. + +
+ +
+ diff --git a/docs/reference/js/lessons/the-watch.md b/docs/reference/js/lessons/the-watch.md new file mode 100644 index 00000000..9888172a --- /dev/null +++ b/docs/reference/js/lessons/the-watch.md @@ -0,0 +1,26 @@ +# the watch lesson + +display beautiful images on the BBC micro:bit #var #pause #docs + +![](/static/mb/lessons/the-watch-0.png) + +## Topic + +The Watch + +## Quick Links + +* [activity](/microbit/lessons/the-watch/activity) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to design the BBC micro:bit watch with household supplies. + +## Objectives + +* learn how to design and make the watch with the BBC micro:bit + diff --git a/docs/reference/js/lessons/the-watch/activity.md b/docs/reference/js/lessons/the-watch/activity.md new file mode 100644 index 00000000..e8fb9e7e --- /dev/null +++ b/docs/reference/js/lessons/the-watch/activity.md @@ -0,0 +1,160 @@ +# The watch activity + +control images with variables. #microbit #docs + +# BBC micro:bit watch + +![](/static/mb/lessons/the-watch-0.png) + +In this project, you will build your own wearable BBC micro:bit watch from an old pair of jeans and T-shirt. Project duration: 15 minutes. + +![](/static/mb/lessons/the-watch-1.png) + +## Materials + +* BBC micro:bit, battery holder and 2 AAA batteries +* Old T-shirt +* Old Jeans +* Velcro with sticky back – 5cm x 5cm +* Double-sided tape – 22cm x 5cm. You can find carpet tape in your local hardware shop +* Ruler and pen +* Scissors + +![](/static/mb/lessons/the-watch-2.png) + +## Steps + +### Step 1 + +![](/static/mb/lessons/the-watch-3.png) + +Using the ruler and pen, mark a rectangle of more or less 26cm x 5cm on the T-shirt. Don’t worry if you don’t get it quite right, we’ll tidy things up later on. + +### Step 2 + +![](/static/mb/lessons/the-watch-4.png) + +Cut the rectangle using the scissors. Don’t worry about the quality of the cut, we’ll trim it later on. + +### Step 3 + +![](/static/mb/lessons/the-watch-5.png) + +Cut a piece of cloth from the pair of jeans. Cut straight by the seam. + +![](/static/mb/lessons/the-watch-6.png) + +### Step 4 + +![](/static/mb/lessons/the-watch-7.png) + +Using the ruler and pen, mark a rectangle of 22cm x 5cm (adults should use 24cm x 5cm) on the jeans cloth. + +### Step 5 + +![](/static/mb/lessons/the-watch-8.png) + +Stretch the cloth using your hands and apply the double-side tape on the rectangle marked on the jeans. You might need the help of a friend to achieve this step. Don’t worry if the tape is larger than the rectangle, we will trim it later. Make sure to apply pressure to the tape to secure it firmly. + +### Step 6 + +![](/static/mb/lessons/the-watch-9.png) + +Using the scissors, cut the rectangle of jeans. + +### Step 7 + +![](/static/mb/lessons/the-watch-10.png) + +Peal the tape protective layer from the rectangle. + +### Step 8 + +![](/static/mb/lessons/the-watch-11.png) + +Place the BBC micro:bit pins on the tape at more or less **7** cm from the left border. Then lower the BBC micro:bit on the tape and press **gently**. + +### Step 9 + +![](/static/mb/lessons/the-watch-12.png) + +Connect the battery holder and place it on the right of the BBC micro:bit. Tuck the cables away on the tape to protect them. + +### Step 10 + +![](/static/mb/lessons/the-watch-13.png) + +Stick the T-shirt rectangle from the top of the BBC micro:bit, over the battery cables. + +### Step 11 + +![](/static/mb/lessons/the-watch-14.png) + +Use your fingers to push the T-shirt cloth under the BBC micro:bit to give access to the micro-USB plug. + +### Step 12 + +![](/static/mb/lessons/the-watch-15.png) + +Place the T-shirt over the battery holder and stick it up to the end. + +### Step 13 + +![](/static/mb/lessons/the-watch-16.png) + +Turn over the watch and cut the extra T-shirt material. + +### Step 14 + +![](/static/mb/lessons/the-watch-17.png) + +Stick the T-shirt cloth on the other side of the watch. Lift the BBC micro:bit pins to slide the cloth under and leave them free from the tape. + +### Step 15 + +![](/static/mb/lessons/the-watch-18.png) + +Turn over the watch and cut left over T-shirt cloth. + +### Step 16 + +![](/static/mb/lessons/the-watch-19.png) + +Cut a 5cm x 5cm square of Velcro **loops**. + +### Step 17 + +![](/static/mb/lessons/the-watch-20.png) + +Cut a 5cm x 5cm square of Velcro **hooks**. + +### Step 18 + +![](/static/mb/lessons/the-watch-21.png) + +Stick the Velcro hooks on the right side of the battery holder on the T-shirt cloth. + +### Step 19 + +![](/static/mb/lessons/the-watch-22.png) + +Stick the Velcro loops on the other end on the jeans fabric. + +### Step 20 + +Trim any leftover fabric, threads or tape. + +### Step 21 + +![](/static/mb/lessons/the-watch-23.png) + +Your watch is ready! + +### Step 23 + +Connect your BBC micro:bit to your computer using your USB cable and upload the [rock paper scissors](/microbit/bedihg) script on it. Shake your watch to play against... the BBC micro:bit! + +### Acknowledgements + +Artistic design by Melinda Hoeneisen. + diff --git a/docs/reference/js/lessons/timing-game.md b/docs/reference/js/lessons/timing-game.md new file mode 100644 index 00000000..129cab98 --- /dev/null +++ b/docs/reference/js/lessons/timing-game.md @@ -0,0 +1,9 @@ +# timing game + +make a game to test hand-eye coordination #docs #functions #var + +### @video td/videos/timing-game-0 + +Make a game to test hand-eye coordination + +* [tutorial](/microbit/lessons/timing-game/tutorial) diff --git a/docs/reference/js/lessons/transformer/quiz.md b/docs/reference/js/lessons/transformer/quiz.md new file mode 100644 index 00000000..4da707b1 --- /dev/null +++ b/docs/reference/js/lessons/transformer/quiz.md @@ -0,0 +1,44 @@ +# transformers quiz + +Use functions to return values #LED #number #math #functions #return #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [transformer tutorial](/microbit/lessons/transformer/tutorial) + +Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs! + +## 1. What is a 'function'? + +## 2. Consider the following directions + +Write the line of code to create a number variable that is initially 5. + +
+ +## 3. Consider the following directions + +Write the line of code to use the condition 'on button pressed ("A")' + +
+ +## 4. Consider the following directions + +Write the code that creates a function. + +
+ +## 5. Consider the following directions + +Write the code to call the function that doubles the input number. (the function is going to provide the doubled value after it is called). The code will assign the new value (10) to a variable which we will call `doubled`. + +
+ +## 6. Consider the following picture + +Write the code to show number 20 on the BBC micro:bit. Please add the variable called `doubled` Refer to the finished code on the tutorial. + +
+ diff --git a/docs/reference/js/lessons/transformers.md b/docs/reference/js/lessons/transformers.md new file mode 100644 index 00000000..90eb18e8 --- /dev/null +++ b/docs/reference/js/lessons/transformers.md @@ -0,0 +1,125 @@ +# transformers lesson + +use functions to return values #var #button #number #function #docs + +### @video td/videos/transformers-0 + +## Topic + +Return + +## Quick Links + +* [tutorial](/microbit/lessons/transformers/tutorial) +* [quiz](/microbit/lessons/transformers/quiz) +* [quiz answers](/microbit/lessons/transformers/quiz-answers) +* [challenges](/microbit/lessons/transformers/challenges) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to create **functions**, ` function() ` to make your code easier to read, debug, and update. We will be learning how to create functions as well as a global variable, input on button pressed as well simple commands such as show number. + +## What the teacher needs to know + +* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective. +* Command: An instruction for the computer to execute, written in a particular programming language. +* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information. +* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately. +* Hardware: The physical systems and components of digital devices; see also software. +* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors. +* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems. +* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program. +* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output. +* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character. +* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met. +* Sequence: To place program instructions in order, with each executed one after the other. +* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games. +* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name. + +**QuickStart Computing Glossary + +## Documentation + +* **function** : [read more...](/microbit/js/function) +* **return** : [read more...](/microbit/js/return) +* **call** : [read more...](/microbit/js/call) +* **global variable** : [read more...](/microbit/js/data) +* **on button pressed** : [read more...](/microbit/reference/input/on-button-pressed) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Resources + +* Activity: [tutorial](/microbit/lessons/transformers/tutorial) +* Activity: [quiz](/microbit/lessons/transformers/quiz) +* Extended Activity: [challenges](/microbit/lessons/transformers/challenges) + +## Objectives + +* learn how to create a function that performs a specific task to make your code easier to read, debug, and update +* learn how the return statement exits a function and returns a value to the code +* learn how to call an existing function in your script +* learn how to create a global variable to store data so that you can use it later in your code and accessible across functions and in nested code blocks +* learn how to run code when an input button is pressed +* learn how to create a local variable to store data, so that you can use it in your code +* learn how to show a number on the LED screen + +## Links to the National Curriculum Programmes of Study for Computing + +## Progression Pathways / Computational Thinking Framework + +#### Algorithms + +* Uses diagrams to express solutions.(AB) +* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL) +* 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) +* 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 + +* Uses filters or can perform single criteria searches for information.(AL) +* Defines data types: real numbers and Boolean (AB) + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +#### Information Technology + +* Collects, organizes, and presents data and information in digital content (AB) +* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV) +* Recognises ethical issues surrounding the application of information technology beyond school. + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [tutorial](/microbit/lessons/transformers/tutorial) +* [quiz](/microbit/lessons/transformers/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/transformers/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/transformers/challenges) + +## Intended follow on + +Publish script to the classroom. + diff --git a/docs/reference/js/lessons/transformers/challenges.md b/docs/reference/js/lessons/transformers/challenges.md new file mode 100644 index 00000000..51631489 --- /dev/null +++ b/docs/reference/js/lessons/transformers/challenges.md @@ -0,0 +1,54 @@ +# transformers challenges + +Coding challenges for the transformers tutorial. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/transformers/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +let inital = 5 +input.onButtonPressed("A", () => { + let doubled1 = double(initial) + basic.showNumber(doubled1, 150) // *** +}) +``` + +### Challenge 1 + +Create a new function called `square` that returns the square of the number passed into the function. + +(Squaring means that you multiply the number by itself) + +``` +export function square(n: number) : number { + let num: number + return n * n + return num +} +``` + +### Challenge 2 + +### @video td/videos/transformers-2 + +Add a condition for when button `B` is pressed. We will use this condition in the last challenge. + +``` +initial = 5 +input.onButtonPressed("A", () => { + let doubled = double(initial) + basic.showNumber(doubled, 150) +}) +input.onButtonPressed("B", () => { +}) // *** +``` + +**Challenge 3** + +When the `B` button is pressed, display the square of the initial value. Use the function `square`. You should get the value 25. + diff --git a/docs/reference/js/lessons/transformers/quiz-answers.md b/docs/reference/js/lessons/transformers/quiz-answers.md new file mode 100644 index 00000000..61086a89 --- /dev/null +++ b/docs/reference/js/lessons/transformers/quiz-answers.md @@ -0,0 +1,65 @@ +# transformers quiz answers + +Use functions to return values #LED #number #math #functions #return #docs + +This is the answer key for the [transformers quiz](/microbit/lessons/transformers/quiz). + +## 1. What is a 'function'? + +A function is a unit of code that performs a specific task and returns a result. + +## 2. Write the line of code to create a number variable called "x" is equal to 5. + +
+ +``` +let x = 5 +``` + +## 3. Write the line of code to create a condition for 'on button pressed ("A")' + +
+ +``` +input.onButtonPressed("A", () => { +}) +``` + +## 4. Write the steps to create a function. + +
+ +Click on `script`, then `add new`, and select `function`. + +## 5. Create a function called double that will double whatever input parameter is passed into it. + +
+ +``` +export function double(n: number) : number { + let r: number + return n * 2 + return r +} +``` + +## 6. Consider the following directions + +Call the `function` that doubles the variable **x**. (The `function` is going to return the doubled value after it is called). Assign the new value (10) to a variable which we will call `doubled`. + +
+ +``` +let doubled = double(x) +``` + +## 7. Refer to Question 6 + +Write the code to call the function that doubles our new `variable` doubled. Assign the new value 20 to a variable we will call doubled twice. + +
+ +``` +let doubleTwice = double(doubled) +``` + diff --git a/docs/reference/js/lessons/transformers/quiz.md b/docs/reference/js/lessons/transformers/quiz.md new file mode 100644 index 00000000..68d0fa8b --- /dev/null +++ b/docs/reference/js/lessons/transformers/quiz.md @@ -0,0 +1,40 @@ +# transformers quiz + +Use functions to return values #LED #number #math #functions #return #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [transformers tutorial](/microbit/lessons/transformers/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is a 'function'? + +
+ +## 2. Write the line of code to create a number variable called **x** that is equal to 5. + +
+ +## 3. Write the line of code to create a condition for 'on button pressed ("A")' + +
+ +## 4. Write the steps to create a function. + +
+ +## 5. Create a function called **double** that will double whatever input parameter is passed into it. + +
+ +## 6. Consider the following directions. Call the function that doubles the variable original. The function is going to return the doubled value after it is called. Assign the new value (10) to a variable which we will call doubled. + +
+ +## 7. Refer to Question 6. Write the code to call the function that doubles our new variable doubled. Assign the new value 20 to a variable we will call doubled twice. + +
+ diff --git a/docs/reference/js/lessons/truth-or-dare.md b/docs/reference/js/lessons/truth-or-dare.md new file mode 100644 index 00000000..f0b58295 --- /dev/null +++ b/docs/reference/js/lessons/truth-or-dare.md @@ -0,0 +1,83 @@ +# truth or dare lesson + +create a love meter with the BBC micro:bit #button #pressed #math #random #var #string #if #docs + +## Topic + +If (Conditionals) + +## Quick Links + +* [activity](/microbit/lessons/truth-or-dare/activity) +* [challenges](/microbit/lessons/truth-or-dare/challenges) +* [quiz](/microbit/lessons/truth-or-dare/quiz) +* [quiz answers](/microbit/lessons/truth-or-dare/quiz-answers) +* [tutorial](/microbit/lessons/truth-or-dare/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to use an if statement to run code run code depending on whether a condition is true or not. We will be learning how to create the game truth or dare using input an if statement, a local variable, math random as well as simple commands, such as show string and plot image. + +## Documentation + +* **show LEDs** : [read more...](/microbit/reference/basic/show-leds) +* **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/assignment) +* **math random** : [read more...](/microbit/js/math) +* **If** : [read more...](/microbit/reference/logic/if) +* **show string** : [read more...](/microbit/reference/basic/show-string) + +## Objectives + +* learn how to display an image on the BBC micro:bit +* learn how to run code when an input button is pressed +* learn how to a create a variable for a place where you can store and retrieve data +* 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 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 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 + +#### Hardware & Processing + +* Knows that computers collect data from various input devices, including sensors and application software (AB) + +Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation + +## Activity + +* time: 20 min. +* [activity](/microbit/lessons/truth-or-dare/activity) +* [tutorial](/microbit/lessons/truth-or-dare/tutorial) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/truth-or-dare/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/truth-or-dare/challenges) + diff --git a/docs/reference/js/lessons/truth-or-dare/activity.md b/docs/reference/js/lessons/truth-or-dare/activity.md new file mode 100644 index 00000000..9d2a69b9 --- /dev/null +++ b/docs/reference/js/lessons/truth-or-dare/activity.md @@ -0,0 +1,106 @@ +# truth or dare activity + +a multi-player game that forces each player to reveal a secret or something funny. #docs + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**. + +Begin by plotting an "up-arrow" image, which will point to someone. + +``` +basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) +``` + +* Run your program and look at the arrow! + +Now let's create a condition to know when button `A` is pressed so that we can display "truth" or "dare" on the BBC micro:bit. + +``` +basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) +input.onButtonPressed("A", () => { +}) +``` + +We want the BBC micro:bit to randomly choose whether to display "truth" or display "dare". We can use accomplish this by using `math->random(2)`. + +``` +basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) +input.onButtonPressed("A", () => { + let random = Math.random(2) +}) +``` + +Now let's display the appropriate message for each scenario of `random`. + +``` +basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) +input.onButtonPressed("A", () => { + let random1 = Math.random(2) + if (random1 == 0) { + basic.showString("TRUTH", 150) + } else { + basic.showString("DARE", 150) + } +}) +``` + +* Run your program: Press button A! + +Notice how the arrow didn't display again after pressing button `A`. Let's add a line of code that displays the arrow again. + +``` +basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) +input.onButtonPressed("A", () => { + let random2 = Math.random(2) + if (random2 == 0) { + basic.showString("TRUTH", 150) + } else { + basic.showString("DARE", 150) + } + basic.showLeds(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`, 400) +}) +``` + +* Run your program: Press button A! + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/truth-or-dare/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/truth-or-dare/challenges.md b/docs/reference/js/lessons/truth-or-dare/challenges.md new file mode 100644 index 00000000..e7dca020 --- /dev/null +++ b/docs/reference/js/lessons/truth-or-dare/challenges.md @@ -0,0 +1,104 @@ +# truth or dare challenges + +a multi-player game that forces each player to reveal a secret or something funny. #docs + +## Before we get started + +Complete the following guided tutorial: + +* [tutorial](/microbit/lessons/truth-or-dare/tutorial) + +At the end of the tutorial, click `keep editing`. Your code should look like this: + +``` +basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +input.onButtonPressed("A", () => { + let random = Math.random(2) + if (random == 0) { + basic.showString("TRUTH", 150) + } else { + basic.showString("DARE", 150) + } + basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +}) +``` + +### Challenge 1 + +Let's make the word "DARE" appear a little more often than "TRUTH". Change the line of code with `math->random(2)` to `math->random(3)`. + +``` +basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +input.onButtonPressed("A", () => { + let random1 = Math.random(3) // *** + if (random1 == 0) { + basic.showString("TRUTH", 150) + } else { + basic.showString("DARE", 150) + } + basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +}) +``` + +### Challenge 2 + +Instead of just saying "TRUTH" or "DARE", let's sometimes say "SKIP". This would allow the skipped person to spin the BBC micro:bit without completing a truth or dare. Modify the if statement as shown. + +``` +basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +input.onButtonPressed("A", () => { + let random2 = Math.random(3) + if (random2 == 0) { + basic.showString("TRUTH", 150) // *** + } else if (random2 == 1) { + basic.showString("DARE", 150) // *** + } + else { + basic.showString("SKIP", 150) // *** + } + basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +}) +``` + +* Run your code to see if it works as expected + +### Challenge 3 + +Add some other messages, such as "TWO DARES" for the BBC micro:bit to show. You will need to modify the parameter inside `math->random(3)` as well as adding another `if` condition. + diff --git a/docs/reference/js/lessons/truth-or-dare/quiz-answers.md b/docs/reference/js/lessons/truth-or-dare/quiz-answers.md new file mode 100644 index 00000000..346d89cb --- /dev/null +++ b/docs/reference/js/lessons/truth-or-dare/quiz-answers.md @@ -0,0 +1,38 @@ +# truth or dare quiz answers + +a multi-player game that forces each player to reveal a secret or something funny #math #random #docs #shake + +This is the answer key for the [truth or dare quiz](/microbit/lessons/truth-or-dare/quiz). + +## 1. Write the code that will randomly return 0 through 3 and stores the value inside a local variable called 'random'. + +``` +let random = Math.random(4) +``` + +## 2. Write an if statement that will display the message "TRUTH" on the BBC micro:bit if the local variable 'random' equals 0. + +``` +if (random == 0) { + basic.showString("TRUTH", 150) +} +``` + +## 3. If the local variable 'random' equals 1, write the string that will be displayed. + +DARE + +## 4.Write the code that will display this up arrow after pressing button "A". + +![](/static/mb/lessons/truth-or-dare-0.png) + +``` +basic.plotImage(` +. . # . . +. # # # . +# # # # # +. . # . . +. . # . . +`) +``` + diff --git a/docs/reference/js/lessons/truth-or-dare/quiz.md b/docs/reference/js/lessons/truth-or-dare/quiz.md new file mode 100644 index 00000000..c7e783d1 --- /dev/null +++ b/docs/reference/js/lessons/truth-or-dare/quiz.md @@ -0,0 +1,36 @@ +# truth or dare quiz + +a multi-player game that forces each player to reveal a secret or something funny #math #random #docs #shake + +## Name + +## Directions + +Use this activity document to guide your work in the [truth or dare tutorial](/microbit/lessons/truth-or-dare/tutorial). + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. Write the code that will randomly return 0 through 3 and stores the value inside a local variable called 'random'. + +
+ +
+ +## 2. Write an if statement that will display the message "TRUTH" on the BBC micro:bit if the local variable 'random' equals 0. + +
+ +
+ +## 3. If the local variable 'random' equals 1, write the string that will be displayed. + +
+ +
+ +## 4.Write the code that will display this up arrow after pressing button "A". + +![](/static/mb/lessons/truth-or-dare-0.png) + +
+ diff --git a/docs/reference/js/lessons/typing-game/challenges.md b/docs/reference/js/lessons/typing-game/challenges.md new file mode 100644 index 00000000..77879414 --- /dev/null +++ b/docs/reference/js/lessons/typing-game/challenges.md @@ -0,0 +1,80 @@ +# typing game challenges + +My script. #docs + +**Challenge 0** + +This [guided tutorial](/microbit/lessons/typing-game/tutorial) will teach you how to use the method concat to connect to pieces of text together. + +``` +alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +index = 0 +name = "" +input.onButtonPressed("A", () => { + led.showString(alphabet.substr(index, 1), 0) + index = index + 1 +}) +if (index > 25) { + index = 0 +} +input.onButtonPressed("B", () => { + name = name.concat(alphabet.substr(index - 1, 1)) +}) +input.onGesture(Gesture.Shake, () => { + led.showString(name, 150) +}) +``` + +**Challenge 1** + +After you have shown the string in the condition `on shake`, make the name variable hold nothing in it again so people can add a new name after they have shaken it. + +``` +alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +index = 0 +name = "" +input.onButtonPressed("A", () => { + led.showString(alphabet.substr(index, 1), 0) + index = index + 1 +}) +if (index > 25) { + index = 0 +} +input.onButtonPressed("B", () => { + name = name.concat(alphabet.substr(index - 1, 1)) +}) +input.onGesture(Gesture.Shake, () => { + led.showString(name, 150) + name = "" // *** +}) +``` + +**Challenge 2** + +After you have cleared the name variable to hold nothing, make `index := 0` so that when button `A` is pressed, the first letter of the alphabet will be displayed. + +``` +alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +index = 0 +name = "" +input.onButtonPressed("A", () => { + led.showString(alphabet.substr(index, 1), 0) + index = index + 1 +}) +if (index > 25) { + index = 0 +} +input.onButtonPressed("B", () => { + name = name.concat(alphabet.substr(index - 1, 1)) +}) +input.onGesture(Gesture.Shake, () => { + led.showString(name, 150) + name = "" + index = 0 // *** +}) +``` + +**Challenge 3** + +Give Micro a nickname and display it on the micro:bit! + diff --git a/docs/reference/js/lessons/while-counting/challenges.md b/docs/reference/js/lessons/while-counting/challenges.md new file mode 100644 index 00000000..d6d2c78b --- /dev/null +++ b/docs/reference/js/lessons/while-counting/challenges.md @@ -0,0 +1,65 @@ +# digi yoyo challenges + +These challenges will teach you how to create a counter 10 to 1. #docs + +**Challenge 0** + +### @video vimeo/134459911 + +[This guided tutorial](/microbit/lessons/digi-yoyo/tutorial) will teach you how to make a counter from 0-9 using a while loop. + +``` +count = 1 +while (count < 10) { + basic.pause(1000) + basic.showNumber(count, 150) + count = count + 1 +} +``` + +**Challenge 1** + +How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0. + +``` +count = 1 +while (count < 10) { + basic.pause(1000) + basic.showNumber(count, 150) + count = count + 1 +} +while (count > 0) { +} +``` + +**Challenge 2** + +Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`! + +``` +count = 1 +while (count < 10) { + basic.pause(1000) + basic.showNumber(count, 150) + count = count + 1 +} +while (count > 0) { + basic.pause(1000) // *** + basic.showNumber(count, 150) // *** +} +``` + +* Run the code to see if it works as expected. + +**Challenge 3** + +### @video vimeo/134449661 + +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: + +``` +count = count - 1 +``` + diff --git a/docs/reference/js/lessons/yes-no/challenges.md b/docs/reference/js/lessons/yes-no/challenges.md new file mode 100644 index 00000000..57f6d10a --- /dev/null +++ b/docs/reference/js/lessons/yes-no/challenges.md @@ -0,0 +1,49 @@ +# yes no challenges + +My script. #docs + +**Challenge 0** + +This [guided tutorial](/microbit/lessons/yes-no/challenges) will show you how to display text on the micro:bit! + +``` +basic.showString("ASK ME A QUESTION", 150) +``` + +**Challenge 1** + +### @video vimeo/134142879 + +Now we need to reply after someone asks Micro 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`. + +``` +basic.showString("ASK ME A QUESTION", 150) +input.onButtonPressed("A", () => { + basic.showString("YES", 150) // *** +}) // *** +``` + +* `Run` the code to see if it works as expected. + +**Challenge 2** + +### @video vimeo/134142673 + +What if Micro'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`. + +``` +basic.showString("ASK ME A QUESTION", 150) +input.onButtonPressed("A", () => { + basic.showString("YES", 150) +}) +input.onButtonPressed("B", () => { + basic.showString("NO", 150) // *** +}) // *** +``` + +* `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`. + diff --git a/docs/reference/js/lessons/zoomer.md b/docs/reference/js/lessons/zoomer.md new file mode 100644 index 00000000..16553261 --- /dev/null +++ b/docs/reference/js/lessons/zoomer.md @@ -0,0 +1,95 @@ +# zoomer lesson + +measure the acceleration on the micro:bit in the "z" direction #acceleration #var #docs #if #show #pause + +### @video td/videos/zoomer-0 + +## Topic + +Acceleration + +## Quick Links + +* [activity](/microbit/lessons/zoomer/activity) +* [challenges](/microbit/lessons/zoomer/challenges) +* [quiz](/microbit/lessons/zoomer/quiz) +* [quiz answers](/microbit/lessons/zoomer/quiz-answers) +* [tutorial](/microbit/lessons/zoomer/tutorial) + +## Class + +Year 7 + +## Prior learning/place of lesson in scheme of work + +Learn how to get the **acceleration**, `input->acceleration` in one of three specified dimensions. We will be learning how to get the acceleration using a forever loop, local variables, input on button pressed, as well as simple commands, such as show number and pause. + +## Documentation + +* **forever** : [read more...](/microbit/reference/basic/forever) +* **local variable** : [read more...](/microbit/reference/variables/var) +* **acceleration** : [read more...](/microbit/reference/input/acceleration) +* **if** : [read more...](/microbit/reference/logic/if) +* **button is pressed** : [read more...](/microbit/reference/input/button-is-pressed) +* **show number** : [read more...](/microbit/reference/basic/show-number) + +## Objectives + +* learn how to repeat code in the background forever +* learn how to create a variable to store data +* learn how to get the acceleration value (g-force), in one of three specified dimensions +* 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 get the state of an input button +* learn how to show a number 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 logical reasoning to predict outputs, showing an awareness of inputs (AL) +* Shows an awareness of tasks best completed by humans or computers (EV) +* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (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) +* Declares and assigns variables(AB) +* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL) +* Understands the difference between, and appropriately uses if and if, then and else statements(AL) +* Uses a variable and relational operators within a loop to govern termination (AL) (GE) +* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL) +* Selects the appropriate data types(AL) (AB + +#### 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/zoomer/activity) +* [tutorial](/microbit/lessons/zoomer/tutorial) +* [quiz](/microbit/lessons/zoomer/quiz) + +## Extended Activity + +* time: 20 min. +* [challenges](/microbit/lessons/zoomer/challenges) + +## Homework + +* Extended Activity: [challenges](/microbit/lessons/zoomer/challenges) + diff --git a/docs/reference/js/lessons/zoomer/activity.md b/docs/reference/js/lessons/zoomer/activity.md new file mode 100644 index 00000000..2ef3d780 --- /dev/null +++ b/docs/reference/js/lessons/zoomer/activity.md @@ -0,0 +1,44 @@ +# zoomer activity + +measure the acceleration on the BBC micro:bit in the "z" direction. #microbit #docs + +### ~avatar avatar + +### @video td/videos/zoomer-0 + +Welcome! This tutorial will teach how to measure the acceleration on the micro:bit in the "z" direction. Let's get started! + +### ~ + +To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**. + +We want to display the acceleration forever. In order to do so, we need a `basic->forever` loop. + +``` +basic.forever(() => { +}) +``` + +Let's measure the acceleration and then store in it a variable `az`. The acceleration is measured in **milli-gravities**, so a value of `-1000` is equivalent to `-1g` or `-9.81m/s^2`. + +``` +basic.forever(() => { + let az = input.acceleration("z") +}) +``` + +Show the value of `az` on the screen. + +``` +basic.forever(() => { + let az_ = input.acceleration("z") + basic.showNumber(az_, 150) +}) +``` + +### ~avatar avatar + +Excellent, you're ready to continue with the [challenges](/microbit/lessons/zoomer/challenges)! + +### ~ + diff --git a/docs/reference/js/lessons/zoomer/challenges.md b/docs/reference/js/lessons/zoomer/challenges.md new file mode 100644 index 00000000..10e56c2e --- /dev/null +++ b/docs/reference/js/lessons/zoomer/challenges.md @@ -0,0 +1,39 @@ +# zoomer challenges + +Coding challenges for the zoomer tutorial.#acceleration #docs #input + +## Before we get started + +Complete the following [guided tutorial](/microbit/lessons/zoomer/tutorial) and your finished code should look like this: + +``` +basic.forever(() => { + let az = input.acceleration("z") + basic.showNumber(az, 150) +}) +``` + +### Challenge 1 + +### @video td/videos/zoomer-2 + +We'll modify the code to display the `x` acceleration if the `A` button is pressed. For that, we need to store `input->acceleration(x)` in a new variable `ax` and use a `input->button is pressed(A)` to detect if the button is pressed. + +``` +basic.forever(() => { + let az1 = input.acceleration("z") + let ax = input.acceleration("x") + if (input.buttonIsPressed("A")) { + basic.showNumber(ax, 150) // *** + } else { + basic.showNumber(az1, 150) // *** + } +}) +``` + +* Run the code to see if it works as expected. + +### Challenge 2 + +Display the `y` acceleration when `B` is pressed by adding another `if` statement using `input->button is pressed(B)`. + diff --git a/docs/reference/js/lessons/zoomer/quiz-answers.md b/docs/reference/js/lessons/zoomer/quiz-answers.md new file mode 100644 index 00000000..fb6995ac --- /dev/null +++ b/docs/reference/js/lessons/zoomer/quiz-answers.md @@ -0,0 +1,35 @@ +# zoomer quiz answers + +Measure the acceleration on the micro:bit in the "z" direction #LED #number #math #acceleration #docs + +This is the answer key for the [zoomer quiz](/microbit/lessons/zoomer/quiz). + +## 1. What is 'acceleration'? + +Acceleration is amount of force being applied to the BBC micro:bit in one of three specified directions. + +## 2. Consider the following directions + +Write the line of code to measure the acceleration and then store in it a variable. + +
+ +``` +let accX_ = input.acceleration("x") +``` + +Note: acceleration does not have be measured in the "x" direction. It can also be in the "y" or "z" direction. + +## 3. Consider the following directions + +After storing the acceleration in a variable, write the code to show acceleration on the BBC micro:bit as a number + +
+ +``` +let accX = input.acceleration("x") +basic.showNumber(accX_, 150) +``` + +Note: make sure the same variable name ("acc x" in this case) is the same in both lines of code.. + diff --git a/docs/reference/js/lessons/zoomer/quiz.md b/docs/reference/js/lessons/zoomer/quiz.md new file mode 100644 index 00000000..3a9f293b --- /dev/null +++ b/docs/reference/js/lessons/zoomer/quiz.md @@ -0,0 +1,24 @@ +# zoomer quiz + +Measure the acceleration on the micro:bit in the "z" direction #LED #number #math #acceleration #docs + +## Name + +## Directions + +Use this activity document to guide your work in the [zoomer tutorial](/microbit/lessons/zoomer/tutorial) + +Answer the questions while completing the tutorial. Pay attention to the dialogues! + +## 1. What is 'acceleration'? + +
+ +## 2. Write the line of code to measure the acceleration and then store in it a variable. + +
+ +## 3. After storing the acceleration in a variable, write the code to show acceleration on the BBC micro:bit as a number. + +
+ diff --git a/docs/reference/js/libraries.md b/docs/reference/js/libraries.md new file mode 100644 index 00000000..afbfe696 --- /dev/null +++ b/docs/reference/js/libraries.md @@ -0,0 +1,64 @@ +# Create and Use Libraries + +Libraries are scripts with functions that you can use in other scripts. #docs #libraries #language #library + +### @parent js/language + +Libraries are scripts with functions that you can use in other scripts. For example, `game` is a library of game-related functions that you can use in your scripts. + +Benefits of using libraries: + +* **reuse code** between scripts +* **collaborate** with other people on a project by combining scripts into a library + +### Add a library + +To add a library to a script: + +1. Open a script in the [Touch Develop editor](/microbit/js/editor) and then click `script` (in the upper-right corner). + +2. Click `+` **add new**. + +3. Click `library`. + +4. Choose the library you want to use or search for a library (such as `game`). + +Once you've added a library to your script, you can use any of the library's non-private [functions](/microbit/js/function). Here's how: + +* on the [Code Keyboard](/microbit/js/editor) click the button with the library's name (for example, `micro:bit` and `micro:bit game` are library buttons). The functions in the library have a button on the Code Keyboard. + +### Create a library + +Creating and publishing a script as a library is easy. Here's how: + +1. Open a script in the [Touch Develop editor](/microbit/js/editor), and then click `script`. + +2. Click the script name to open the script properties. + +3. Mark the `this script is a library` check box. + +4. Click `script`. + +5. Click `publish`. + +Once a script is marked as a _library_ and published, it's immediately available to other people. + +### Visibility + +The following library items are not accessible by other scripts: + +* data (global variables) +* functions marked as `private` + +If you want to access global library variables from other scripts, you need to create [functions](/microbit/js/function) that pass values in and out of the library script. + +### Library and function documentation + +Be sure to document the purpose of your functions and libraries. Add a [comment](/microbit/js/comment) at the beginning of a library to describe the purpose of the library. + +Use [comments](/microbit/js/comment) at the beginning of your [functions](/microbit/js/function) to describe the function's purpose. Comment text shows in the help area of the Code Keyboard when you insert the function. + +### See also + +[functions](/microbit/js/function), [Touch Develop Documentation](/microbit/js/contents) + diff --git a/docs/reference/js/markdown.md b/docs/reference/js/markdown.md new file mode 100644 index 00000000..76b9ffa5 --- /dev/null +++ b/docs/reference/js/markdown.md @@ -0,0 +1,175 @@ +# Markdown Syntax + +Syntax to create formatted text in Touch Develop. #docs #markdown + +### @parent td/comment + + +Markdown is a popular syntax used by developers to describe and annotate documents. Touch Develop supports a large subset of the markdown syntax, and adds a few new features. Markdown syntax applies to [comments](/microbit/js/comment) added using the [Touch Develop editor](/microbit/js/editor). + +## Basic markdown syntax + +### Headings + +Use #, ##, or ### at the beginning of a line to specify a heading: + +* ``use # for heading 1`` +* ``use ## for heading 2`` +* ``use ### for heading 3`` + +### Bulleted lists + +Use a * for a bullet: + +``* this is a bullet`` + +### Numbered lists + +Type a number, a period, and a space before each item in a numbered list. Like this: + +> `1. first item` + +> `2. second item` + +> `3. third item` + +The numbers in a numbered list appear as 1. in the Touch Develop editor, however, the numbers will update when the script is previewed or published. + +### Character formatting + +Use a single `*` for italic and `**` for bold: + +``*italic*`` => *italic* + +``**bold**`` => **bold** + +### Links + +* to add a link, type the URL: ``http://touchdevelop.com`` => http://touchdevelop.com +* to specify link text (instead of the URL), put the link text in [ ] brackets and the link in ( ) + +For example: + +``[TouchDevelop website](http://touchdevelop.com)`` => [TouchDevelop website](http://touchdevelop.com) + +### Columns + +To format text into columns, insert ``### ~column `` at the start of each column and ``### ~`` at the end of the column. + +## Touch Develop syntax + +The markdown syntax in this section is non-standard and specific to Touch Develop. + +### Inline code + +Use this syntax: ```basic => show number``` + +To show code like this: `basic-> show number` + +(``->`` is replaced with `->`) + +### HTML entities + +You can use HTML entities like ``&amp;``, ``&lt;``, or ``&#123;``. You can also use ``&`` verbatim if it cannot be confused with HTML entity. + +### Pictures + +You can include pictures in a script by adding an art resource to your script. All pictures must first be uploaded to the Touch Develop cloud before they can be used in a script. Here's how: + +1. Click `script`, **+ add new**, and then click **picture resource**. + +2. You can upload a new picture or search existing pictures. + +3. Give it a name, let's say you call it ``alien``. + +2. In your script, use ``(picture ...)`` with the picture name (in this case, alien) and an optional caption: +WARN: missing picture: ... +WARN: unknown picture: ... + +* ``![](/static/mb/image-0.png)`` + +![](/static/mb/image-0.png) + +By default, pictures are 12x12. You can specify a different size as in `![](/static/mb/image-0.png)`, up to 30x20. + +![](/static/mb/image-0.png) + +To insert a picture inline with text ![](/static/mb/image-0.png), use: `(picture ...)` without any size information. For example: ``![](/static/mb/image-0.png)`` +WARN: missing picture: ... +WARN: unknown picture: ... + +You can skip adding an art resource, and instead use the publication ID of a picture directly. + +### Declarations + +Any named declaration from a script can be rendered in a script using `{decl:name}`. For example, you can render global variables, functions, etc... +WARN: no such decl: name + +* ` +``` +var v: number = 0 +``` + +` where `v` is a global variable in the script: + +``` +var v: number = 0 +``` + +### Code snippets + +Any code that is not a comment is treated as a snippet. + +You can use ``{highlight}`` comment to start highlighting statements in the snippet. Use ``{/highlight}`` to stop. The comment needs to have ``{highlight}`` or ``{/highlight}`` and nothing else. +MACRO: highlightMACRO: /highlightMACRO: highlightMACRO: /highlight + +If you want to render some comments inside the snippets as comments (and not regular text), then surround the snippet with ``{code}`` ... ``{/code}``, for example: +MACRO: codeMACRO: /code + +``` +let theAnswer = 42 // *** +// and now show the answer: +basic.showNumber(theAnswer, 150) +``` + +Note that comments inside block structures are always rendered as regular comments, not text. For example: + +``` +if (false) { + // This code is never executed. +} +``` + +### Boxes and frames + +You can use `### ~ ` and `### ~` (each on separate comment line) to enclose a block of text in a coloured box. For example: + +### ~hint + +This is how `### ~hint ` looks like. Some helpful information goes here. + +### ~ + +The following box types are supported: + +* `hint`, `exercise`, `example` - self-explanatory +* `nointernet` - block with heading "no internet?" for giving instructions for offline operations +* `screen` - does not show in print +* `print` - does not show when not printing +* `portrait` - shows (with no frame or heading) when device is held in portrait orientation; in print it shows with heading "device in portrait" and a frame +* `landscape` - likewise + +### Special tutorial features + +You'll use markdown syntax when creating Touch Develop tutorials. See [create a tutorial](/microbit/js/create-tutorials) for more info. + +### ~hide + +### Embedding videos + +* any video: ``{video::}`` where ```` is a screenshot of the video, and ```` is the video url that plays +MACRO: video +If you want to include documents, slides, and videos from other sites, just use regular `http://...` link. + +### ~ + diff --git a/docs/reference/js/math.md b/docs/reference/js/math.md new file mode 100644 index 00000000..e16ab2e4 --- /dev/null +++ b/docs/reference/js/math.md @@ -0,0 +1,101 @@ +# Math Library + +Functions in the math library. #docs #math #random #abs #mod #pow #max #min #clamp + +### @parent js/language + +The math library includes math related functions that you can use with [Numbers](/microbit/reference/types/number). + +* In the [TouchDevelop editor](/microbit/js/editor), click `math` to access the functions described below +* In the [Block editor](/microbit/blocks/editor), click **maths** on the left to see the available blocks + +The functions available in Touch Develop are: + +### abs + +math `->` abs (x : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the absolute value of input parameter `x` + +``` +basic.showNumber(math.abs(-7), 150) +``` + +### clamp + +math `->` clamp (min : [Number](/microbit/reference/types/number), max : [Number](/microbit/reference/types/number), value : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +limits a number to a range (between a min and max number); returns `min` if `value` is < `min`; returns `max` if `value` is > `max`; otherwise, returns `value`. + +``` +basic.showNumber(td.clamp(5, 9, 12), 150) +``` + +### max + +math `->` max (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the larger of two input numbers (`x` and `y`) + +``` +basic.showNumber(Math.max(9, 7), 150) +``` + +### min + +math `->` min (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the smaller of two input numbers (`x` and `y`) + +``` +basic.showNumber(Math.min(9, 7), 150) +``` + +### mod + +math `->` mod (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the integer modulus/remainder resulting from the division of the number `x` by the number `y` + +``` +basic.showNumber(math.mod(9, 7), 150) +``` + +### pow + +math `->` pow (base : [Number](/microbit/reference/types/number), exp : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the value of the number `base` raised to the power `exp` + +``` +basic.showNumber(math.pow(3, 3), 150) +``` + +### random + +math `->` random (limit : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns a random [Number](/microbit/reference/types/number) between 0 and the parameter *limit* - 1 + +``` +basic.showNumber(Math.random(10), 150) +``` + +### sign + +math `->` sign (x : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the sign of input parameter `x` + +``` +basic.showNumber(math.sign(-7), 150) +``` + +### Lessons + +[flipping bird](/microbit/lessons/flipping-bird), [catch the egg game](/microbit/lessons/catch-the-egg-game) + +### See also + +[Bits library](/microbit/js/bits), [TouchDevelop documentation](/microbit/js/contents), [Number](/microbit/reference/types/number) + diff --git a/docs/reference/js/micro-bit-api.md b/docs/reference/js/micro-bit-api.md new file mode 100644 index 00000000..a193f93c --- /dev/null +++ b/docs/reference/js/micro-bit-api.md @@ -0,0 +1,69 @@ +# micro:bit + +The micro:bit device api. #microbit + +Initialize the library. + +{shim:} +MACRO: shim + +``` +if (board == null) { + compassHeadingValue = (null) + startTime = new Date() + board = media.createPortraitBoard(612, 498 + 100) + wall.setBackground(colors.transparent()) + let picture = microbitSchema.clone() + let padding = 27 + let left = 205 + let top = 156 + picture.fillRect(left - padding, top, 205 + padding + 4, 200 + padding + 4, 0, colors.black()) + picture.fillRect(274, 74, 63, 16, 0, colors.black()) + bkg = board.createPicture(picture) + bkg.width() = board.width() + bkg.left() = 0 + bkg.top() = 0 + createButtons() + finger = board.createEllipse(20, 20) + finger.setOpacity(0) + ledOnColor = "#ff4f4f".toColor() + ledOffColor = colors.transparent() + boardColor = colors.fromRgb(0.85, 0.95, 0.85) + backLeds = board.createSpriteSet() + leds = board.createSpriteSet() + let backLedColor = "#202020".toColor() + let ledOpacity = 127 / 255 + let ledW = 10 + let ledOffset = 48 + let ledH = 20 + for (let i = 0; i < 5; i++) { + let ledTop = i * ledOffset + top + for (let j = 0; j < 5; j++) { + let ledLeft = j * ledOffset + left + let backLed = board.createRectangle(ledW, ledH) + backLed.setColor(backLedColor) + let led = board.createRectangle(ledW + 8, ledH + 8) + backLed.left() = ledLeft + backLed.top() = ledTop + led.x() = backLed.x() + led.y() = backLed.y() + led.setOpacity(ledOpacity) + led.setColor(ledOffColor) + led.setShadow(10, colors.red(), 0, 0) + ledIndexAnim(backLed, j, i) + backLeds.add(backLed) + leds.add(led) + } + } + initEyes() + initAxis() + initPins() + updateAxis() + backgroundAnimation() + board.onEveryFrame(() => { + updateBoard() + }) + board.postToWall() +} +``` + diff --git a/docs/reference/js/number.md b/docs/reference/js/number.md new file mode 100644 index 00000000..90c2d2fc --- /dev/null +++ b/docs/reference/js/number.md @@ -0,0 +1,84 @@ +# Number + +An integer number. #docs #Number #var + +### @parent js/language + +A *Number* is an integer such as `42` or `-42`. More precisely, a *Number* is a signed 32-bit integer (two's complement). + +### Declare a number variable + +Use the [var statement](/microbit/reference/variables/var) and the [assignment operator](/microbit/reference/variables/assign) `:=` to declare a *local* number variable. Like this: + +``` +let number1 = 2 +let number2 = 2 +``` + +To declare a *global* number variable, see [global variables](/microbit/js/data). + +### Arithmetic operators + +The following arithmetic operators work on numbers and return a [Number](/microbit/reference/types/number): + +* addition: `1 + 3` +* subtraction: `1 - 3 ` +* multiplication: `3 * 2` +* integer division: `7 / 3` +* modulo is available through the [math library](/microbit/js/math) + +### Relational operators + +The following relational operators work on numbers and return a [Boolean](/microbit/reference/types/boolean): + +* equality: `(3 + 1) = 4` +* inequality: `3 != 4` +* less or equal than: `3 <= 4` +* less than: `3 < 4` +* greater or equal than : `4 >= 3` +* greater than: `4 > 3` + +### Show number + +The [show number](/microbit/reference/basic/show-number) function displays a number on the [LED screen](/microbit/device/screen). For example, this code displays the number 42: + +``` +basic.showNumber(42, 100) +``` + +### Functions that return a number + +Some functions return a number, which you can store in a variable. For example the following code gets the display brightness (using the [brightness function](/microbit/reference/led/brightness)) and stores the value in a variable named `brightness`: + +``` +let brightness = led.brightness() +``` + +### Math functions + +The [math library](/microbit/js/math) includes math related functions. In the [Touch Develop editor](/microbit/js/editor), click `math` on the Code Keyboard to see the math functions. For example, the `mod` function returns the modulus (division of one number by another number): + +``` +number1 = math.mod(4, 3) +``` + +### Convert a number to a string + +The `to string` function converts a Number into a [String](/microbit/reference/types/string). The following code converts `number1` to a string and stores the string in the `str` variable: + +``` +let str = number1.toString() +``` + +### Bit-level manipulation + +The [bits library](/microbit/js/bits) includes functions for bit-level manipulation of integers. In the [Touch Develop editor](/microbit/js/editor), click `bits` on the Code Keyboard to see these functions. + +### Lessons + +[counter](/microbit/lessons/counter), [love meter](/microbit/lessons/love-meter), [flipping bird](/microbit/lessons/flipping-bird), [catch the egg game](/microbit/lessons/catch-the-egg-game) + +### See also + +[math library](/microbit/js/math), [var](/microbit/reference/variables/var), [bits library](/microbit/js/bits), [Boolean](/microbit/reference/types/boolean), [show number](/microbit/reference/basic/show-number) + diff --git a/docs/reference/js/object-disclaimer.md b/docs/reference/js/object-disclaimer.md new file mode 100644 index 00000000..f47a2164 --- /dev/null +++ b/docs/reference/js/object-disclaimer.md @@ -0,0 +1,25 @@ +# Objects disclaimer + +Touch Develop docs for the micro:bit #docs #contents #apis #functions #language #statements + +### Memory management on the micro-bit + +New user-defined object types are allocated on the heap and are ref-counted. Our ref-counting algorithm does *not* have a cycle collector. (See Wikipedia.) + +### Practical consequences + +This means that the following script will result in an out-of-memory error. + +![](/static/mb/object-disclaimer-0.png) + +``` +while (true) { + let l = new List() + l.next = l +} +``` + +### How to avoid this? + +Don't do it. It's bad. + diff --git a/docs/reference/js/object-types.md b/docs/reference/js/object-types.md new file mode 100644 index 00000000..37954712 --- /dev/null +++ b/docs/reference/js/object-types.md @@ -0,0 +1,57 @@ +# Custom object types + +Touch Develop docs for the micro:bit #docs #contents #apis #functions #language #statements + +### What is an object? + +An object allows you to bundle several related pieces of data. For instance, if you have a player on the screen, there are two pieces of data that make up the object: its `x` position, and its `y` position. Therefore, we will define a player to be an *object* with two *fields*: the `x` field and the `y` field. By grouping related variables together in a single object, you reduce confusion in your script and eliminate some errors. + +### What is an object type? + +In order to use objects, we must first define an object type. More concretely, in order to create a new player, we must define what a player *is*. In our case, the type of players is the type of objects with two fields `x` and `y` of type `Number`. + +Creating an object type is done in the following manner. Hit "add new", then hit "object type". + +![](/static/mb/object-types-0.png)(picture foobar2) +WARN: unknown picture: foobar2 + +You can change the name of the type by clicking on it (i.e. replace `Thing` with `Player`). You can also add two fields of type number. Once this is done, here's what you should see. + +![](/static/mb/object-types-1.png) + +We have now defined what a player is (it has an `x` field and a `y` field). `Player` is a type, just like `Number` and `String`. However, we have not created any player yet. + +### Creating objects and using them + +To create a new *variable* of a given type, you can call the `create` operation on `Player`. + +``` +let p = new Player() +``` + +Just like `var x := 3` creates a new variable (`x`) of type `Number`, the line above creates a new variable (`p`) of type `Player`. We say that `p` is an *instance* of `Player`. + +If you want to *modify* (mutate) `p`, here's how you do it. + +``` +p.x = 5 +``` + +You can read the *fields* of `p` as follows. + +``` +basic.showString("My player is at x = ", 150) +basic.showNumber(p.x, 150) +``` + +That is, the generic syntax for accessing a field `x` of an object `p` is `p → x`. + +If there are multiple players in your game, you may want to create a collection of them. + +``` +let c = ([]) +c.push(new Player()) +``` + +A good example of using objects is in the game pac-man runaway. Search for it, read it and clone it! + diff --git a/docs/reference/js/operators.md b/docs/reference/js/operators.md new file mode 100644 index 00000000..bdf6b8cf --- /dev/null +++ b/docs/reference/js/operators.md @@ -0,0 +1,9 @@ +# Operators + +Built-in operators. #docs #operators #language + +### @parent js/language + + +### to be removed: has been combined into [statements and operators](/microbit/js/statements) + diff --git a/docs/reference/js/orientation.md b/docs/reference/js/orientation.md new file mode 100644 index 00000000..b7e4760b --- /dev/null +++ b/docs/reference/js/orientation.md @@ -0,0 +1,46 @@ +# micro:bit orientation + +A #microbit library that exposes accelerometer events. + +A simple library that exposes events to detect + +* detect that the screen is facing up and the board is horizontal + +``` +onScreenUp(() => { + micro_bit.showString("screen up", 100) +}) +``` + +* detect that the screen is facing down and the board is horizontal + +``` +onScreenDown(() => { + micro_bit.showString("screen down", 100) +}) +``` + +* detect when the logo is up and the board is vertical + +``` +onLogoUp(() => { + micro_bit.showString("logo up", 100) +}) +``` + +* detect when the logo is down and the board is vertical + +``` +onLogoDown(() => { + micro_bit.showString("r", 100) +}) +``` + +* detect that the device is shaken + +``` +onShake(() => { + micro_bit.showString("shake", 100) +}) +``` + diff --git a/docs/reference/js/publishing.md b/docs/reference/js/publishing.md new file mode 100644 index 00000000..7b5c098e --- /dev/null +++ b/docs/reference/js/publishing.md @@ -0,0 +1,52 @@ +# Publish a Script + +How to publish scripts. #docs #publishing + +### @parent js/contents + + +Scripts that you create are periodically saved in the cloud, but only published scripts can be seen by other people. Once you publish a script, other people can run your script, post comments on it, tweak and re-publish it, or rate your script with a heart. + +### How to publish a script + +To publish a script from the TouchDevelop Editor: + +* when you're editing a script, click `script` and then click `publish` + +To publish a script from `My Scripts`: + +* go to **My Scripts* +* click a script on the left and then click `Publish` on the right + +**Publish options:** + +**Share with everyone**: click `publish` to publish your script so that anyone can find it using search or by browsing scripts. + +**Share with people you choose**: click `publish as hidden` to publish your script in a way that it is not discoverable by search (users will need to know your script's id to access it). + +When you publish a script, a url with a unique script id is created so that you can share your script with other people. To share a *publish as hidden* script, copy the url and give it to select people. There is also a `share` button in [script options](/microbit/js/editor). + +You can add a short publication note if you'd like. This note appears with the publishing history (on the script overview page). + +### Hidden scripts + +A hidden script is + +* not indexed by the search (so are never visible in search results) +* hidden from various lists, unless the person viewing the list is the user who created the script +* accessible to anyone who knows the hidden script's id +* accessible when it is the base of a public script + +The lists include: + +* list of scripts by the user +* list of derived scripts + +### Published scripts are public! + +**Do not store passwords or other confidential information** in your script code. Everyone will be able to see your script on the Internet forever once it is published. + +### Updates + +If you are working on a script, you might want to publish multiple updates of the same script. As long as you do not change the script name (and you are the author of the previous version), the published version will automatically be considered as the latest version of this script. + diff --git a/docs/reference/js/quick-start.md b/docs/reference/js/quick-start.md new file mode 100644 index 00000000..f38337ff --- /dev/null +++ b/docs/reference/js/quick-start.md @@ -0,0 +1,34 @@ +# The Quick Start Guide for Teachers + +The Quick Start Guide for Teachers #docs + +### ~hint + +**Spotty internet? No problem!** (1) When online, go to https://www.microbit.co.uk/app/ and bookmark this URL; (2) use the bookmark to reload the web app, even without the internet. + +### ~ + +The Quick Start Guide for Teachers is available in [PDF](https://microbit0.blob.core.windows.net/pub/tovulwsd/Quick-Start-Guide-for-Teachers.pdf). + +### Resources + +The currently available on-line resources from the Quick Start Guide are the + +* [scroll text tutorial](/microbit/js/tutorials/scroll-text) +* [flashing heart tutorial](/microbit/js/tutorials/flashing-heart) +* [button light tutorial](/microbit/js/tutorials/button-light) +* [digital key chain tutorial](/microbit/js/tutorials/digital-key-chain) +* [rock paper scissors tutorial](/microbit/lessons/rock-paper-scissors/tutorial) and [rock paper scissors challenges](/microbit/lessons/rock-paper-scissors/challenges) +* [digital pet tutorial](/microbit/lessons/digital-pet/tutorial) and [digital pet challenges](/microbit/lessons/digital-pet/challenges) +* [catch the egg game tutorial](/microbit/lessons/catch-the-egg-game/tutorial) and [catch the egg game challenges](/microbit/lessons/catch-the-egg-game/challenges) + +### Errata + +* compilation to the BBC micro:bit now works [off line](/microbit/offline), based on a new compiler in the web browser. The text and picture below replaces the text and picture on page 10 of the Guide: + +### How does my program get onto the BBC micro:bit? + +For your program to work on the BBC micro:bit, first it has to be compiled. Compiling means to translate a program into a more efficient computer language. When you hit the compile button on the Microsoft Touch Develop Editor interface, your program is compiled into a hex file that contains the machine code in the instruction set used by the ARM processor that is on your BBC micro:bit. Compiling to ARM machine code actually happens in the web browser, where the code from script is joined with the machine code of the micro:bit runtime. + +![](/static/mb/quick-start-0.png) + diff --git a/docs/reference/js/reactive.md b/docs/reference/js/reactive.md new file mode 100644 index 00000000..73837e34 --- /dev/null +++ b/docs/reference/js/reactive.md @@ -0,0 +1,149 @@ +# The BBC micro:bit - a reactive system + +The BBC micro:bit is a reactive system. #docs + +### Computing systems + +What sort of a *computing system* is the BBC 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 Google’s 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 BBC micro:bit is a *reactive system* – it reacts continuously to external events, such as a person pressing the A button of the BBC 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, that’s 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, it’s frustrating if you press a button to make a character jump, but it doesn’t 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. + +Let’s consider a simple example: you want to program your BBC 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. + +Let’s 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 BBC 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 BBC 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. + +Let’s think about three sequences of instructions: + +* Sequence S1 contains the instructions (let’s 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: + +![](/static/mb/device/reactive-0.png) + +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: + +![](/static/mb/device/reactive-1.png) + +As we’ll soon see, there are other choices for how the sequences can be ordered to achieve the desired result. + +### The BBC micro:bit scheduler and queuing up subprograms + +The BBC micro:bit’s *scheduler* provides the capability to concurrently execute different code sequences, relieving us of a lot of low-level programming. In fact, scheduling is so useful that it is a part of every *operating system*! + +The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses. + +``` +export function countButtonPresses() { + let count = 0 + input.onButtonPressed("A", () => { + count = count + 1 + }) + basic.forever(() => { + basic.showNumber(count, 150) + }) +} +``` + +The program above contains three statements that execute in order from top to bottom. The first statement + +``` +let count1 = 0 +``` + +initializesthe variable `count`. The second statement + +``` +input.onButtonPressed("A", () => { + count1 = count1 + 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 variable `count` by one. The second statement + +``` +basic.forever(() => { + basic.showNumber(count1, 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 variable `count` on the LED screen. + +The function ends after the execution of these three statements, but this is not the end of program execution! That’s 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 hadn’t 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 Alice’s subprogram (and remembering where it stopped) and starting/resuming execution of Bob’s subprogram. + +We will call this “passing control of execution” rather than “passing the ball”. However, in the world of the BBC micro:bit, the concurrently executing subprograms are not aware of each other, so they don’t 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. + +Let’s 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 subprogram’s 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 + +Let’s go back to the `count button presses` function and revisit its execution based on what we have learned about the BBC micro:bit scheduler. As detailed before, the function executes three steps to: (1) initialize the variable `count` to zero; (2) set up the event handler for each press of button A; (3) queue the forever loop to the run queue. + +The function then ends execution and control passes back to the scheduler. Let’s assume the user has not pressed any buttons . The scheduler finds the `forever` loop in the run queue and passes control to it. The loop first calls `basic -> show number(0,150)`. In the diagram below, we use “Show 0” to refer to the execution of this function: + +![](/static/mb/device/reactive-3.png) + +While "Show 0" (the blue sequence) is running, periodic interrupts by the scheduler (every 6 milliseconds) poll for button presses and queue an event handler for each press of button A. Let’s say that one button press takes place during this time, as shown above. This will cause an event handler (labelled “inc”) to be queued for later execution by the scheduler. Once the "Show 0" has completed, the loop then calls `basic -> pause(20)` to put the forever loop to sleep for 20 milliseconds and give the scheduler an opportunity to run any newly queued event handler. Control passes to the “inc” event handler which will increment the 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 BBC 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() { + let count = 0 + input.onButtonPressed("A", () => { + count = count + 1 + }) + basic.forever(() => { + basic.showNumber(count, 150) + }) + input.onButtonPressed("B", () => { + count = 0 + }) +} +``` + diff --git a/docs/reference/js/return.md b/docs/reference/js/return.md new file mode 100644 index 00000000..b1354693 --- /dev/null +++ b/docs/reference/js/return.md @@ -0,0 +1,49 @@ +# Return + +Exit a function. #docs #return #language #function + +### @parent js/statement + + +The return statement exits a [function](/microbit/js/function) and returns a value to the code that called the function. + +### Touch Develop syntax + +return *expression* + +### Square function + +``` +/** + * // return the value x * x + * @param x TODO + */ +export function square(x: number) : number { + let result: number + return x * x + return result +} +``` + +### The type of *expression* + +The type of *expression* should match the declared return type of the function; in the above example, the return type is Number and we see that the return expression `x * x` is a Number since the input parameter `x` is a Number. + +### Storing the returned value + +The following code calls the `square` function with the number 42 and stores the output parameter in the `result` variable: + +``` +let result1 = square(42) +``` + +`result` is the default variable name for the function output, as specified in the function + +### Lessons + +[transformers](/microbit/lessons/transformers) + +### See also + +[function](/microbit/js/function), [calling functions](/microbit/js/call), [function parameters](/microbit/js/functionparameters) + diff --git a/docs/reference/js/scriptid.md b/docs/reference/js/scriptid.md new file mode 100644 index 00000000..7f9c7bf7 --- /dev/null +++ b/docs/reference/js/scriptid.md @@ -0,0 +1,31 @@ +# script id + +What is the script id? #docs + +### @parent js/contents + + +the *script id* is a unique identifier that is given to each [published](/microbit/js/publishing) script. This way you can share your scripts with other people. + +### where can I find the script id? + +when your looking at your list of scripts (**My Scripts** area), the *script id* is displayed under the author name (it begins with a forward slash: /). + +TODO Diagram + +the script id in the example above is `/tuxi`. + +### search by script id + +you can type the script id directly into the search in the hub to find it. + +### sharing your scripts + +when you [publish a script](/microbit/js/publishing), you can copy the url (which includes the script id) and send it to people. + +if you forget to copy the url when you publish, there's also a `share` button in [script options](/microbit/js/editor). + +### see also + +[publish a script](/microbit/js/publishing) + diff --git a/docs/reference/js/senses.md b/docs/reference/js/senses.md new file mode 100644 index 00000000..c266d4ca --- /dev/null +++ b/docs/reference/js/senses.md @@ -0,0 +1,46 @@ +# micro:bit senses + +A #microbit library that exposes orientation and movement events. + +A library that exposes orientation and movement events. + +* detect that the screen is facing up and the board is horizontal + +``` +onScreenUp(() => { + micro_bit.showString("screen up", 100) +}) +``` + +* detect that the screen is facing down and the board is horizontal + +``` +onScreenDown(() => { + micro_bit.showString("screen down", 100) +}) +``` + +* detect when the logo is up and the board is vertical + +``` +onLogoUp(() => { + micro_bit.showString("logo up", 100) +}) +``` + +* detect when the logo is down and the board is vertical + +``` +onLogoDown(() => { + micro_bit.showString("r", 100) +}) +``` + +* detect that the device is shaken + +``` +onShake(() => { + micro_bit.showString("shake", 100) +}) +``` + diff --git a/docs/reference/js/serial-library.md b/docs/reference/js/serial-library.md new file mode 100644 index 00000000..e32f17e2 --- /dev/null +++ b/docs/reference/js/serial-library.md @@ -0,0 +1,140 @@ +# Serial Library + +The serial library #docs + +The **serial library** supports [serial communication](https://en.wikipedia.org/wiki/Serial_port) between the BBC micro:bit and another computer. Basically, this allows you to send data from the micro:bit to your own computer. This is very useful for debugging purposes: you can add `write line` statements in your code and see them display on your computer as the program executes. + +The code below shows a simple script that sends a line when the BBC micro:bit starts and another line each time the button ``A`` is pressed. + +``` +serial.writeLine("started...") +input.onButtonPressed("A", () => { + serial.writeLine("A pressed") +}) +``` + +## How to read the micro:bit's serial output from your computer + +Unfortunately, using the serial library requires quite a bit of a setup. + +### Windows + +You must install a device driver (for the computer to recognize the serial interface of the micro:bit); then, you must also install a terminal emulator (which is going to connect to the micro:bit and read its output). Here's how to do it: + +* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver +* Install a terminal emulator; we recommend [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer. + +Once both the driver and the terminal emulator are installed, plug in the micro:bit and wait until the device is fully setup. Then, open TeraTerm. + +* Hit `File` > `New Connection` +* Check "Serial"; in the dropdown menu, pick the COM port that says "mbed Serial Port". Hit `Ok`. +* In the menus, hit `Setup` > `Serial Port` and set the baud rate to `115200`. + +You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to erase the default configuration file with a new one so that you don't have to type in the settings again. + +Please note that Windows will assign you a different COM port if you plug in another micro:bit. If you're juggling between micro:bits, you'll have to change the COM port every time. + +### Alternative Windows setup with Putty + +If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions. + +* Open Windows's [Device Manager](https://windows.microsoft.com/en-us/windows/open-device-manager); expand the section called "Ports (COM & LPT)"; write down the com number for "mbed Serial Port" (e.g. COM14) +* Open PuTTY; on the main screen, use the following settings: Serial / COM14 / 115200. Replace COM14 with the COM port number you wrote down previously. Feel free to type in a name and hit "Save" to remember this configuration. + +![](/static/mb/serial-library-0.png) + +* (optional): in the "Terminal" section, check "implicit cr in every lf" + +![](/static/mb/serial-library-1.png) + +### Linux + +(Untested). + +* Plug in the micro:bit +* Open a terminal +* `dmesg | tail` will show you which `/dev/` node the micro:bit was assigned (e.g. `/dev/ttyUSB0`) +* Then, do: `screen /dev/ttyUSB0 115200` (install the `screen` program if you don't have it). To exit, run `Ctrl-A` `Ctrl-D`. + +Alternative programs include minicom, etc. + +### Mac OS + +* Plug in the micro:bit +* Open a terminal +* `ls /dev/cu.*` will return to you a list of serial devices; one of them will look like `/dev/cu.usbmodem1422` (the exact number depends on your computer) +* `screen /dev/cu.usbmodem1422 115200` will open up the micro:bit's serial output. To exit, hit `Ctrl-A` `Ctrl-D`. + +## Using the serial library in your programs + +If the ``serial`` button is not available, you will need first to add the ``micro:bit serial`` library to your script: + +* tap on `add new` +* tap on `library` +* select `micro:bit serial` + +### Writing data + +This is basically what you will use the serial library for: debugging purposes. + +* write a number + +``` +serial.writeNumber(42) +``` + +* write a string + +``` +serial.writeString("hello") +``` + +* write a line of text + +``` +serial.writeLine("this is a line") +``` + +Theoretically, you can dump more sophisticated data and then read it back in the event that two micro:bits should be connected to each other over serial. We have not tested this scenario yet as we have yet to expose functionality that allows re-routing the serial ports to the edge connector. + +* write an image + +``` +let img = images.createImage(` +. . . . . +. # . # . +. . . . . +. . . . . +# # # # # +`) +serial.writeImage(img) +``` + +* write the current screen LED status + +``` +serial.writeScreen() +``` + +### Reading data + +This is useful if you have something connected at the other end. As explained above, this is not yet a scenario. + +* reads a line of text + +``` +let msg = serial.readString() +``` + +* reads an image + +``` +img = serial.readImage() +``` + +* reads the state of the screen from serial + +``` +serial.readScreen() +``` + diff --git a/docs/reference/js/showcase.md b/docs/reference/js/showcase.md new file mode 100644 index 00000000..5c32d3f0 --- /dev/null +++ b/docs/reference/js/showcase.md @@ -0,0 +1,16 @@ +# Showcase Scripts + +#docs + +## Get Started with These Hex Files! + +If you have a BBC micro:bit and would like to explore a few scripts, we've created the following hex files for you to copy to your BBC micro:bit + +### Flashing Heart + +This script introduces you to the LED display: + +* {hex:xzlzgl:hex file} +MACRO: hex* [Block Editor script](/microbit/jxislh) +* [Touch Develop script](/microbit/xzlzgl) + diff --git a/docs/reference/js/simulator.md b/docs/reference/js/simulator.md new file mode 100644 index 00000000..bf02b266 --- /dev/null +++ b/docs/reference/js/simulator.md @@ -0,0 +1,45 @@ +# Run Code in your Browser + +Run scripts in a web browser. #docs #simulator #run + +While you're writing and testing your scripts, you'll mostly be running scripts in your browser by clicking the `run` button. Both the [Microsoft Block editor](/microbit/blocks/editor) and the [Touch Develop editor](/microbit/js/editor) have a `run` button above the coding area. + +*Note*: in the Touch Develop editor, the button actually is named `run main`, reflecting the fact that execution of a Touch Develop script always beings in the `main` function + +When you click `run main` in the Touch Develop editor, your code executes and the results are simulated on-screen, using an image of the BBC micro:bit device, like this: + +![](/static/mb/simulator-0.png) + +In the picture above, [plot image](/microbit/reference/led/plot-image) create a heart image that appears on the BBC micro:bit simulator. + +The BBC micro:bit simulator let's you... + +* write and test code, even if you don't have a BBC micro:bit device +* test your code throughly before downloading and running your script on the BBC micro:bit + +### What does the simulator support? + +The BBC micro:bit simulator supports the Touch Develop [functions](/microbit/js/contents) and Microsoft [blocks](/microbit/blocks/contents), including those related to the LED screen, input buttons, the compass, accelerometer, and the digital I/O pins. + +* **LED screen**: the [LED screen](/microbit/device/screen) that appears on-screen shows you what you'll see on the BBC micro:bit device +* **input buttons**: when running code with [button is pressed](/microbit/reference/input/button-is-pressed) or [on button pressed](/microbit/reference/input/on-button-pressed) functions, click the on-screen A or B button +* **compass**: when running code that includes [compass heading](/microbit/reference/input/compass-heading), click and drag the on-screen compass needle to change the heading +* **accelerometer**: move your mouse over the on-screen micro:bit device to simulate [acceleration](/microbit/reference/input/acceleration). The x and y axis values are shown on-screen. +* **digital pins**: you can click the on-screen digital pins (0 , 1, or 2) to turn them on or off (see [digital write pin](/microbit/reference/pins/digital-write-pin) and [digital read pin](/microbit/reference/pins/digital-read-pin) for more info). + +**Can't see the red LEDs on the simulator?** + +If you click on the white THEME button in the top right corner of the simulator, it will switch to an accessible version of the simulator, where the LEDs are displayed in blue on a white background. + +### All done? + +Once you're done writing and testing your code on the simulator, compile and run your script on your BBC micro:bit device. To find out how to do this, see [run scripts on the micro:bit](/microbit/device/usb). + +### Simulator vs micro:bit + +Running your scripts in a web browser is a *simulation* of how your code will run on the BBC micro:bit device. When you run your script on your BBC micro:bit device, the results may differ slightly. For example, the timing may be subtly different when your script runs on the BBC micro:bit device (you may need to adjust your [pause](/microbit/reference/basic/pause) functions). For this reason, be sure to test your scripts on the BBC micro:bit device. + +### See also + +[run scripts on the micro:bit](/microbit/device/usb), [Microsoft Block editor](/microbit/blocks/editor), [Touch Develop editor](/microbit/js/editor) + diff --git a/docs/reference/js/statements.md b/docs/reference/js/statements.md new file mode 100644 index 00000000..c17e1141 --- /dev/null +++ b/docs/reference/js/statements.md @@ -0,0 +1,41 @@ +# statements, operators, and libaries + +Statements, operators, and libraries. #docs #statements #operators #library + +### @parent js/language + + +TouchDevelop functions include statements and operators. + +### Statements + +TouchDevelop statements include: + +* [break](/microbit/js/break), to exit a loop before it has completed, usually used in conjunction with an [if](/microbit/reference/logic/if) statement +* [if](/microbit/reference/logic/if) conditional statement +* [for](/microbit/reference/loops/for) and [while](/microbit/js/while) loops +* [function](/microbit/js/function) +* [return](/microbit/js/return) +* [var](/microbit/reference/variables/var) (local variable declaration) + +### Operators + +TouchDevelop operators include: + +* [assignment operator](/microbit/reference/variables/assign) `:=` (to update variables) +* arithmetic operators (`+`, `-`, `*`, `/`, mod) operate on [Numbers](/microbit/reference/types/number) +* comparison operators (such as `>`, `=`) operate on [Numbers](/microbit/reference/types/number) +* boolean operators (`not`, `or`, `and`) operate on [Booleans](/microbit/reference/types/boolean) +* concat operator combines [Strings](/microbit/reference/types/string) + +### Libraries + +Libraries provide additional functions: + +* the [micro:bit library](/microbit/js/contents) +* the [math](/microbit/js/math) and [bits](/microbit/js/bits) libraries + +### see also + +[TouchDevelop Documentation](/microbit/js/contents), [comments](/microbit/js/comment) + diff --git a/docs/reference/js/string-functions.md b/docs/reference/js/string-functions.md new file mode 100644 index 00000000..e728fe22 --- /dev/null +++ b/docs/reference/js/string-functions.md @@ -0,0 +1,178 @@ +# String Functions + +string-related functions. #docs #String #equals #concat #at #substring #toCharactercode #count + +### @parent js/language + +The following string related functions are available in Touch Develop for the BBC micro:bit: + +* **equals** - find out if two strings are the same +* **at** - get a character within a string +* **concat** - combine two strings +* **count** - get the number of characters in a string +* **substring** - get a portion of a string +* **to character code** - converts a character into a character code +* **to number** - converts a string into a number + +Select a string variable in the [Touch Develop editor](/microbit/js/editor) to see the following string functions: + +``` +/* placeholder */ +``` + +### ~hide + +``` +let str = "hi" +``` + +### ~ + +### equals + +find out if two strings are the same + +#### Syntax + +[String](/microbit/reference/types/string) `->` **equals** (other : [String](/microbit/reference/types/string)) *returns* [Boolean](/microbit/reference/types/boolean) + +#### Parameters + +* other - [String](/microbit/reference/types/string); a string + +#### Example + +the following code does something if `str` = "Hi": + +``` +if (str == "Hi") { + // add code to do something here +} +``` + +### at + +get a character within a string, using the specified index + +#### Syntax + +[String](/microbit/reference/types/string) `->` **at** (index: [Number](/microbit/reference/types/number)) *returns* [String](/microbit/reference/types/string) + +#### Parameters + +* index- [Number](/microbit/reference/types/number); the character number within a string (0 returns the first character) + +#### Example + +The following code gets the first character from the `str` string and stores it in the `first char` variable: + +``` +let firstChar = str[0] +``` + +### The `||` operator + +To combine two strings you can use the string concatenation operation `||` as shown below: + +``` +let s = "abc" + "def" +let evaluatesToTrue = s == "abcdef" +``` + +NOTE: position the cursor outside of the string quotes, right after the string, for the || operator to appear in the keyboard. + +### concat + +combine two strings; like the concat operator (`||`) + +#### Syntax + +[String](/microbit/reference/types/string) `->` **concat** (other : [String](/microbit/reference/types/string)) *returns* [String](/microbit/reference/types/string) + +#### Parameters + +* other- [String](/microbit/reference/types/string); a string + +#### Example + +The following code combines two strings and displays the string on screen: + +``` +str = "Hi " +str = str.concat("there") +basic.showString(str, 100) +``` + +### count + +get the number of characters in a string + +#### Syntax + +[String](/microbit/reference/types/string) `->` **count** *returns* [Number](/microbit/reference/types/number) + +#### Example + +The following example gets the length of the `str` variable and stores it in the `x` variable: + +``` +let x = str.length +``` + +### Substring + +get a portion of a string, using a starting point and length + +#### Syntax + +[String](/microbit/reference/types/string) `->` **substring** (start : [Number](/microbit/reference/types/number), length : [Number](/microbit/reference/types/number)) *returns* [String](/microbit/reference/types/string) + +#### Parameters + +* start - [Number](/microbit/reference/types/number); the starting character number (0 is the first character number in a string) +* length - [Number](/microbit/reference/types/number); the string length + +#### Example + +The following code gets characters 6, 7, and 8 from the `str` string: + +``` +let asubstring = str.substr(5, 3) +``` + +### to character code + +converts the first character of a string into a character code number (unicode) + +#### Syntax + +[String](/microbit/reference/types/string) `->` **to character code** *returns* [Number](/microbit/reference/types/number) + +#### Example + +The following code converts the first character of `str` into a character code and stores the code in `x`: + +``` +x = str.toCharacterCode() +``` + +### to number + +converts a string into a number + +#### Syntax + +[String](/microbit/reference/types/string) `->` **to number** *returns* [Number](/microbit/reference/types/number) + +#### Example + +The following code converts `str` into a number and stores it in `x`: + +``` +x = parseFloat(str) +``` + +### See also + +[string](/microbit/reference/types/string), [number](/microbit/reference/types/number), [show string](/microbit/reference/basic/show-string) + diff --git a/docs/reference/js/string.md b/docs/reference/js/string.md new file mode 100644 index 00000000..f080f7b0 --- /dev/null +++ b/docs/reference/js/string.md @@ -0,0 +1,60 @@ +# String + +a piece of text. #docs #String + +### @parent js/language + +A *String* is a sequence of characters. For the BBC micro:bit, ASCII character codes 32 to 126 are supported; letters, digits, punctuation marks, and a few symbols. All other character codes appear as a ? on the [LED screen](/microbit/device/screen). + +### Declare a string + +Use the [var statement](/microbit/reference/variables/var) and the [assignment operator](/microbit/reference/variables/assign) `:=` to declare a new *local* string variable. Like this: + +``` +let str = "this is a string" +``` + +To declare a string using the [Touch Develop editor](/microbit/js/editor): + +1. Click `var` (on the Code Keyboard). + +2. Type a name for your new string variable. + +2. Click on the right side of the `:=` operator. + +3. Type `"` (or click `"abc"`) and then type a string like `hello`. + +4. Click the check mark. + +Your code should look something like this: + +``` +let salutation = "Hello" +``` + +### The function `show string` + +Use [show string](/microbit/reference/basic/show-string) to display a string on the [LED screen](/microbit/device/screen). If the string is multiple characters, the string scrolls right to left. The following example displays `Hello world!` on the micro:bit screen: + +``` +basic.showString("Hello world!", 100) +``` + +The first parameter of `show string` specifies the string, and the second parameter specifies the number of milliseconds between scrolling by one LED column - the larger the value, the slower the scroll will be. + +### More string functions + +Want to compare or concatenate strings? Check out the [string functions](/microbit/reference/types/string-functions). + +### Global string variables + +Unlike [local variables](/microbit/reference/variables/var), global variables are accessible across functions and in nested code blocks. To find out how to declare a global string variable, see [global variables](/microbit/js/data). + +### Lessons + +[letter up](/microbit/lessons/letter-up) + +### See also + +[local variables](/microbit/reference/variables/var), [global variables](/microbit/js/data), [string functions](/microbit/reference/types/string-functions), [Number](/microbit/reference/types/number), [show string](/microbit/reference/basic/show-string) + diff --git a/docs/reference/js/types.md b/docs/reference/js/types.md new file mode 100644 index 00000000..3172b9fa --- /dev/null +++ b/docs/reference/js/types.md @@ -0,0 +1,19 @@ +# types + +Touch Develop types #docs #variables #var #types #data + +### @parent language + + +A *type* refers to a class of data and the operations permitted on that data. The following types are supported by Touch Develop for the BBC micro:bit: + +* **[String](/microbit/reference/types/string)**: a sequence of characters +* **[Number](/microbit/reference/types/number)**: an integer number (32-bit signed) +* **[Boolean](/microbit/reference/types/boolean)**: true or false +* **[Image](/microbit/reference/image/image)**: a collection of [micro:bit LED states](/microbit/device/screen) (on/off) +* *more types coming!!!* + +### see also + +[local variables](/microbit/reference/variables/var), [global variables](/microbit/js/data), [assignment operator](/microbit/reference/variables/assign) + diff --git a/docs/reference/js/var.md b/docs/reference/js/var.md new file mode 100644 index 00000000..e376d8e6 --- /dev/null +++ b/docs/reference/js/var.md @@ -0,0 +1,144 @@ +# Local Variables + +How to define and use local variables. #docs #var #language #variables + +### @parent language + + +A variable is a place where you can store and retrieve data. Variables have a name, a [type](/microbit/js/types), and value: + +* *name* is how you'll refer to the variable +* *type* refers to the kind of data a variable can store +* *value* refers to what's stored in the variable + +### `var` and `let` statement + +Use the Touch Develop *var* statement to create a local variable and the [assignment operator](/microbit/reference/variables/assign) `=` to store something in the variable. + +For example, this code stores the number `2` in the `num1` variable: + +``` +let num1 = 2 +``` + +Here's how to define a variable in the Touch Develop editor: + +1. Click `var`. + +2. Change the default variable name if you like. + +3. Click on the right-side of the [assignment operator](/microbit/reference/variables/assign) `:=` and type or click what you want to store in the variable. + +The resulting code should look something like this: + +// string variable + +``` +let name = "Mike" +``` + +// number variable + +``` +let counter = 1 +``` + +// boolean variable + +``` +let bool = true +``` + +// image variable + +``` +let img = images.createImage(` +. . # . . +. # # # . +# # # # # +. # # # . +. . # . . +`) +``` + +See [Image](/microbit/reference/image/image) for info on creating and using image variables. + +### Store in var button + +Another way to define a variable is to use the `store in var` button. Here's how: + +* in the [Touch Develop editor](/microbit/js/editor), click a function button that returns a value (i.e. `led` `->` `brightness`) +* click `store in var` +* click `rename` to change the default variable name + +The resulting code should look something like this: + +``` +let brightness = led.brightness() +``` + +A variable is created for the number returned by the [brightness](/microbit/reference/led/brightness) function. + +### Using variables + +Once you've defined a variable, just use the variable's name whenever you need what's stored in the variable. For example, the following code shows the value stored in `counter` on the LED screen: + +``` +basic.showNumber(counter, 100) +``` + +To change the contents of a variable use the assignment operator `:=`. The following code sets `counter` to 1 and then increments `counter` by 10: + +``` +counter = 1 +counter = counter + 10 +``` + +### Why use variables? + +Variables help simplify your code. For example, instead of turning on LEDs one by one like this: + +``` +led.plot(0, 0) +led.plot(1, 1) +led.plot(2, 2) +led.plot(3, 3) +led.plot(4, 4) +``` + +You can use a variable (`i`) and a [for loop](/microbit/reference/loops/for) to plot the same series of points (`i` is incremented by 1, each time the loop repeats): + +``` +for (let i = 0; i < 5; i++) { + led.plot(i, i) +} +``` + +### Local vs global variables + +Local variables exist only within the function or block of code where they're defined. Local variables don't exist outside of where they're defined. For example: + +``` +if (led.brightness() > 127) { + let y = 1 + // `y` variable exists here +} else { + // `y` variable does not exist here +} +``` + +Use [global variables](/microbit/js/data) when you need to access a variable in nested code blocks or across multiple functions. + +#### Notes + +* You can use the default variable names if you'd like, however, it's best to use descriptive variable names. To change a variable name in the editor, select the variable and then click `rename`. +* Be careful not to confuse the assignment `:=` operator with the equals `=` operator. + +### Lessons + +[guess the number](/microbit/lessons/guess-the-number), [digi yoyo](/microbit/lessons/digi-yoyo), [rock paper scissors](/microbit/lessons/rock-paper-scissors), [love meter](/microbit/lessons/love-meter) + +### See also + +[global variables](/microbit/js/data), [types](/microbit/js/types), [assignment operator](/microbit/reference/variables/assign) + diff --git a/docs/reference/js/while.md b/docs/reference/js/while.md new file mode 100644 index 00000000..1a3f3419 --- /dev/null +++ b/docs/reference/js/while.md @@ -0,0 +1,74 @@ +# While + +Repeat code in a loop while a condition is true. #docs #while #language + +### @parent js/language + + +Repeat code while a [Boolean](/microbit/reference/types/boolean) `condition` is true. + +### ~hide + +``` +let condition = false +``` + +### ~ + +### Block Editor + +![](/static/mb/string-0.png) + +### Touch Develop + +``` +while (condition) { + // This code runs if `condition` is `true` +} +``` + +The while loop has a *condition* that evaluates to a [Boolean](/microbit/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`. + +The condition is tested before any code runs. Which means that if the condition is false, the code inside the loop doesn't execute. Use the [break statement](/microbit/js/break) to exit a while loop before it's complete. + +### Example: diagonal line + +The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`). + +// index is set to 4 + +``` +let index = 4 +while (index >= 0) { + led.plot(index, index) + // // subtract 1 from `index` each time through loop + index = index - 1 +} +``` + +### Example: count until A button pressed + +The following example shows numbers on the screen(0, 1, 2, 3...), until the "A" button is pressed. + +``` +let x = 0 +while (true) { + basic.showNumber(x, 100) + let pressed = input.buttonIsPressed("A") + if (pressed) { + break + } else { + x = x + 1 + } + basic.pause(1000) +} +``` + +### Lessons + +[rotation animation](/microbit/lessons/rotation-animation), [digi yoyo](/microbit/lessons/digi-yoyo) + +### See also + +[on button pressed](/microbit/reference/input/on-button-pressed), [for](/microbit/reference/loops/for), [if](/microbit/reference/logic/if), [break](/microbit/js/break), [forever](/microbit/reference/basic/forever), [in background](/microbit/reference/control/in-background) + diff --git a/docs/reference/led/brightness.md b/docs/reference/led/brightness.md new file mode 100644 index 00000000..8a441053 --- /dev/null +++ b/docs/reference/led/brightness.md @@ -0,0 +1,26 @@ +# Brightness + +Set the brightness of the [LED screen](/microbit/device/screen). + +```sig +led.brightness(); +``` + +### Returns + +* [Number](/microbit/reference/types/number) - returns the LCD screen brightness as a number from 0 to 255. A return value of 255 means the screen brightness is at 100% and 127 is about 50% brightness. + +### Example: maximum brightness + +If the screen brightness is < 100%, the following code sets the brightness to 100% (255): + +```blocks +if (led.brightness() < 255) { + led.setBrightness(255) +} +``` + +### See also + +[set brightness](/microbit/reference/led/set-brightness), [fade in](/microbit/reference/led/fade-in), [fade out](/microbit/reference/led/fade-out) + diff --git a/docs/reference/led/fade-in.md b/docs/reference/led/fade-in.md new file mode 100644 index 00000000..ef65030a --- /dev/null +++ b/docs/reference/led/fade-in.md @@ -0,0 +1,34 @@ +# Fade in + +Gradually increase the [LED screen](/microbit/device/screen) brightness until the LED lights are at full brightness. + +```sig +led.fadeIn(700); +``` + +### Parameters + +* ms - [Number](/microbit/reference/types/number); the speed by which the screen brightness is increased, expressed in milliseconds (1,000 milliseconds = 1 second). The smaller the number the faster the screen brightness increased. + +### Example: fading dot + +The following code turns on centre LED and then gradually increases and decreases the screen brightness (the centre LED pulses 5 times): + +```blocks +led.plot(2, 2) +for (let i = 0; i < 5; i++) { + led.setBrightness(0) + led.fadeIn(100) + basic.pause(100) + led.fadeOut(100) +} +``` + +### Lessons + +[glowing sword](/microbit/lessons/glowing-sword) + +### See also + +[brightness](/microbit/reference/led/brightness), [fade out](/microbit/reference/led/fade-out), [set brightness](/microbit/reference/led/set-brightness) + diff --git a/docs/reference/led/fade-out.md b/docs/reference/led/fade-out.md new file mode 100644 index 00000000..f01c926c --- /dev/null +++ b/docs/reference/led/fade-out.md @@ -0,0 +1,30 @@ +# Fade out + +Gradually decrease the [LED screen](/microbit/device/screen) brightness until the LED lights are turned off. + +```sig +led.fadeOut(700); +``` + +### Parameters + +* ms - [Number](/microbit/reference/types/number); the speed that the screen brightness is decreased, expressed in milliseconds (1,000 milliseconds = 1 second). The smaller the number the faster the screen brightness decreased. + +### Example: fade away letter A + +The following example sets the screen brightness to the maximum brightness, displays the letter A, and then gradually fades the letter away: + +```blocks +led.setBrightness(255) +basic.showString("A", 1000) +led.fadeOut(1000) +``` + +### Lessons + +[glowing sword](/microbit/lessons/glowing-sword) + +### See also + +[brightness](/microbit/reference/led/brightness), [fade in](/microbit/reference/led/fade-in), [set brightness](/microbit/reference/led/set-brightness) + diff --git a/docs/reference/led/plot-all.md b/docs/reference/led/plot-all.md new file mode 100644 index 00000000..88056202 --- /dev/null +++ b/docs/reference/led/plot-all.md @@ -0,0 +1,16 @@ +# Plot All + +Turn on all the 25 LEDs on the [LED screen](/microbit/device/screen). + +```sig +led.plotAll() +``` + +### Lessons + +[night light](/microbit/lessons/night-light) + +### See also + +[LED screen](/microbit/device/screen), [clear screen](/microbit/reference/basic/clear-screen) + diff --git a/docs/reference/led/plot-bar-graph.md b/docs/reference/led/plot-bar-graph.md new file mode 100644 index 00000000..ca7709ce --- /dev/null +++ b/docs/reference/led/plot-bar-graph.md @@ -0,0 +1,25 @@ +# Plot Bar Graph + +Displays a vertical bar graph based on the value and high value. + +```sig +led.plotBarGraph(2, 20); +``` + +### Parameters + +* value: [Number](/microbit/reference/types/number) , high : [Number](/microbit/reference/types/number) displays a vertical bar graph based on the value and high value + +### Example: chart acceleration + +```blocks +basic.forever(() => { + let a = input.acceleration(Dimension.X); + led.plotBarGraph(a, 1023) +}) +``` + +### See also + +[brightness](/microbit/reference/led/brightness), [fade in](/microbit/reference/led/fade-in), [fade out](/microbit/reference/led/fade-out), [LED screen](/microbit/device/screen), [stop animation](/microbit/reference/led/stop-animation) + diff --git a/docs/reference/led/plot-leds.md b/docs/reference/led/plot-leds.md new file mode 100644 index 00000000..ebdad47f --- /dev/null +++ b/docs/reference/led/plot-leds.md @@ -0,0 +1,40 @@ +# Plot LEDs + +Display an [Image](/microbit/reference/image/image) on the BBC micro:bit's [LED screen](/microbit/device/screen). NOTE: `basic -> plot image` has been replaced by `basic -> show leds`. + +### KindScript syntax + +```sig +basic.plotLeds(` +. . . . . +. # . # . +. . # . . +# ; . . # +. # # # . +`) +``` + +### Parameters + +* leds - a series of LED on/off states that form an image (see steps below) + +### Example: simley + +```blocks +basic.plotLeds(` +. . . . . +. # . # . +. . # . . +# ; . . # +. # # # . +`) +``` + +### Lessons + +[smiley](/microbit/lessons/smiley), [flashing heart](/microbit/lessons/flashing-heart), [magic logo](/microbit/lessons/magic-logo) + +### See also + +[show animation](/microbit/reference/basic/show-animation), [image](/microbit/reference/image/image), [show image](/microbit/reference/images/show-image), [scroll image](/microbit/reference/images/scroll-image) + diff --git a/docs/reference/led/plot.md b/docs/reference/led/plot.md new file mode 100644 index 00000000..26b1b9ac --- /dev/null +++ b/docs/reference/led/plot.md @@ -0,0 +1,51 @@ +# Plot + +Turn on a LED light on the [LED screen](/microbit/device/screen). Specify which LED using x, y coordinates. Use [unplot](/microbit/reference/led/unplot) to turn a LED off. + +```sig +led.plot(0,0); +``` + +### Parameters + +* x - [Number](/microbit/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4) +* y - [Number](/microbit/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4) + +If a parameter is [out of bounds](/microbit/reference/out-of-bounds) (a value other than 0-4), then this function will do nothing. + +### x, y coordinates? + +The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/microbit/device/screen). + +This code turns on the centre LED: + +```blocks +led.plot(2, 2) +``` + +### Get the LED on/off state + +Use the [point](/microbit/reference/led/point) function to find out if a LED is on or off. + +### Example: a square + +The following example uses a [for loop](/microbit/reference/loops/for) and the `plot` function to turn on the LED lights along the edge of the screen, making a square: + +```blocks +for (let i = 0; i < 5; i++) { + led.plot(0, i) + led.plot(4, i) + led.plot(i, 0) + led.plot(i, 4) + basic.pause(500) +} +``` + +### Lessons + +[blink](/microbit/lessons/blink), [beautiful image](/microbit/lessons/beautiful-image), [strobe light](/microbit/lessons/strobe-light) + +### See also + +[unplot](/microbit/reference/led/unplot), [point](/microbit/reference/led/point), [LED screen](/microbit/device/screen) + diff --git a/docs/reference/led/point.md b/docs/reference/led/point.md new file mode 100644 index 00000000..c940a219 --- /dev/null +++ b/docs/reference/led/point.md @@ -0,0 +1,37 @@ +# Point + +Get the on/off state of a LED on the [LED screen](/microbit/device/screen). Specify the LED using x, y coordinates. + +```sig +led.point(0,0); +``` + +### Parameters + +* x - [Number](/microbit/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4) +* y - [Number](/microbit/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4) + +If a parameter is [out of bounds](/microbit/reference/out-of-bounds) (a value other than 0-4), then this function will return `false`. + +### Returns + +* [Boolean](/microbit/reference/types/boolean) - `true` if the LED is *on* and `false` if the LED is *off* + +### x, y coordinates? + +The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/microbit/device/screen). + +### Example: toggle off + +If `point(1, 1)` returns `true`, then the following code turns off the LED: + +```blocks +if (led.point(1, 1)) { + led.unplot(1, 1) +} +``` + +### See also + +[unplot](/microbit/reference/led/unplot), [plot](/microbit/reference/led/plot), [LED screen](/microbit/device/screen), [create image](/microbit/reference/images/create-image) + diff --git a/docs/reference/led/screenshot.md b/docs/reference/led/screenshot.md new file mode 100644 index 00000000..6923ebb2 --- /dev/null +++ b/docs/reference/led/screenshot.md @@ -0,0 +1,20 @@ +# Screenshot + +Make an [Image](/microbit/reference/image/image) out of the current state of the [LED screen](/microbit/device/screen). + +```sig +led.screenshot(); +``` + +### Parameters + +* none + +### Returns + +* an [Image](/microbit/reference/image/image) of what is currently visible on the [LED screen](/microbit/device/screen) + +### See also + +[create image](/microbit/reference/images/create-image), [LED screen](/microbit/device/screen), + diff --git a/docs/reference/led/set-brightness.md b/docs/reference/led/set-brightness.md new file mode 100644 index 00000000..682f5bb1 --- /dev/null +++ b/docs/reference/led/set-brightness.md @@ -0,0 +1,31 @@ +# Set Brightness + +Sets the brightness of the [LED screen](/microbit/device/screen). + +```sig +led.setBrightness(121) +``` + +### Parameters + +* value : [Number](/microbit/reference/types/number) - the brightness of the LED screen expressed as a number between 0 and 255 + +### Example: change brightness + +The following example sets the screen brightness to 100% (255), turns on LED `2, 2`, waits for a second and then sets the screen brightness to 50% (127): + +```blocks +led.setBrightness(255) +led.plot(2, 2) +basic.pause(1000) +led.setBrightness(127) +``` + +### Lessons + +[night light](/microbit/lessons/night-light) + +### See also + +[brightness](/microbit/reference/led/brightness), [fade in](/microbit/reference/led/fade-in), [fade out](/microbit/reference/led/fade-out), [LED screen](/microbit/device/screen) + diff --git a/docs/reference/led/set-display-mode.md b/docs/reference/led/set-display-mode.md new file mode 100644 index 00000000..8246b470 --- /dev/null +++ b/docs/reference/led/set-display-mode.md @@ -0,0 +1,8 @@ +# Set Display Mode + +Sets the display mode between black and white and greyscale for rendering [LEDs](/microbit/device/screen). + +```sig +led.setDisplayMode(DisplayMode.Greyscale) +``` + diff --git a/docs/reference/led/stop-animation.md b/docs/reference/led/stop-animation.md new file mode 100644 index 00000000..e07599ae --- /dev/null +++ b/docs/reference/led/stop-animation.md @@ -0,0 +1,8 @@ +# Stop Animation + +Cancels the current animation and clears other pending animations . + +```sig +led.stopAnimation() +``` + diff --git a/docs/reference/led/toggle-all.md b/docs/reference/led/toggle-all.md new file mode 100644 index 00000000..07aad80c --- /dev/null +++ b/docs/reference/led/toggle-all.md @@ -0,0 +1,28 @@ +# Toggle All + +Toggle all the 25 LEDs on the [LED screen](/microbit/device/screen) - if an LED is on before the function is called, it will be off after; if an LED is off before the function is called, it will be on after. + +```sig +led.toggleAll() +``` + +### Parameters + +* none + +### Example + +The following code will result in every LED being on except for the LED at coordinate (2,2) + +```blocks +basic.clearScreen() +led.plot(2, 2) +led.toggleAll() +``` + +![](/static/mb/toggle-all-0.png) + +### See also + +[toggle](/microbit/reference/led/toggle), [LED screen](/microbit/device/screen), [clear screen](/microbit/reference/basic/clear-screen) + diff --git a/docs/reference/led/toggle.md b/docs/reference/led/toggle.md new file mode 100644 index 00000000..849e6168 --- /dev/null +++ b/docs/reference/led/toggle.md @@ -0,0 +1,31 @@ +# Toggle + +Toggle a LED light on the [LED screen](/microbit/device/screen), meaning to turn it on (off) if it is off (on). Specify which LED using x, y coordinates. + +```sig +led.toggle(0,0) +``` + +### Parameters + +* x - [Number](/microbit/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4) +* y - [Number](/microbit/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4) + +If a parameter is [out of bounds](/microbit/reference/out-of-bounds) (a value other than 0-4), then this function will do nothing. + +### x, y coordinates? + +The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/microbit/device/screen). + +### Example + +This code toggles the centre LED: + +```blocks +led.toggle(2, 2) +``` + +### See also + +[toggle all](/microbit/reference/led/toggle-all), [plot](/microbit/reference/led/plot), [unplot](/microbit/reference/led/unplot), [point](/microbit/reference/led/point), [LED screen](/microbit/device/screen), + diff --git a/docs/reference/led/unplot.md b/docs/reference/led/unplot.md new file mode 100644 index 00000000..4e0e6547 --- /dev/null +++ b/docs/reference/led/unplot.md @@ -0,0 +1,53 @@ +# Unplot + +Turn off a LED light on the [LED screen](/microbit/device/screen). Specify which LED using x, y coordinates. Use [plot](/microbit/reference/led/plot) to turn a LED on. + +```sig +led.unplot(0,0) +``` + +### Parameters + +* x - [Number](/microbit/reference/types/number); the *x coordinate* or horizontal position (0, 1, 2, 3, 4) +* y - [Number](/microbit/reference/types/number); the *y coordinate* or vertical position (0, 1, 2, 3, 4) + +If a parameter is [out of bounds](/microbit/reference/out-of-bounds) (a value other than 0-4), this function will do nothing. + +### x, y coordinates? + +The LED screen is made up of 25 LEDs arranged in a 5x5 grid. To figure out the ``x``, ``y`` coordinates, see [LED screen](/microbit/device/screen). + +This code turns off centre LED: + +```blocks +led.unplot(2, 2) +``` + +### Get the LED on/off state + +Use the [point](/microbit/reference/led/point) function to find out if a LED is on or off. + +### Example: toggle off + +This code creates and shows an image on the micro:bit screen, and then clears the centre LED using `unplot`: + +```blocks +basic.showLeds(` +. . # . . +. . # . . +# # # # # +. . # . . +. . # . . +`) +basic.pause(500) +led.unplot(2, 2) +``` + +### Lessons + +[strobe light](/microbit/lessons/strobe-light) + +### See also + +[plot](/microbit/reference/led/plot), [point](/microbit/reference/led/point), [LED screen](/microbit/device/screen), [create image](/microbit/reference/images/create-image) + diff --git a/docs/reference/logic/if.md b/docs/reference/logic/if.md new file mode 100644 index 00000000..f3d3bb08 --- /dev/null +++ b/docs/reference/logic/if.md @@ -0,0 +1,29 @@ +# If + +Run code based on a condition. #docs #if #then #else #endif #language #elseif + +### @parent blocks/language + + +Conditionally run code depending on whether a [Boolean](/microbit/reference/types/boolean) condition is true or false. + +### Block Editor + +![](/static/mb/hourofcode-0.png) + +In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block. + +### Example: adjusting screen brightness + +![](/static/mb/blocks/game-library/pic0.png) + +If the screen [brightness](/microbit/reference/led/brightness) is `< 100`, this code sets the brightness to `255`: + +### Lessons + +[love meter](/microbit/lessons/love-meter), [zoomer](/microbit/lessons/zoomer) + +### See also + +[while loop](/microbit/reference/loops/while), [for](/microbit/reference/loops/for), [boolean](/microbit/reference/types/boolean) + diff --git a/docs/reference/loops/for.md b/docs/reference/loops/for.md new file mode 100644 index 00000000..a5937383 --- /dev/null +++ b/docs/reference/loops/for.md @@ -0,0 +1,28 @@ +# For + +Repeat code a preset number of times. #docs #for #endfor #language + +### @parent blocks/language + + +Repeat code a fixed number of times. + +### Block Editor + +![](/static/mb/events-0.png) + +The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times: + +``` +for (let k = 0; k < 4; k++) { +} +``` + +### Lessons + +[looper](/microbit/lessons/looper) + +### See also + +[while](/microbit/reference/loops/while), [if](/microbit/blocks/if) + diff --git a/docs/reference/loops/repeat.md b/docs/reference/loops/repeat.md new file mode 100644 index 00000000..bae51d5a --- /dev/null +++ b/docs/reference/loops/repeat.md @@ -0,0 +1,21 @@ +# Repeat + +Repeat code a preset number of times. #docs #repeat #language + +Repeat code a fixed number of times. + +### Block Editor + +![](/static/mb/blocks/contents-0.png) + +### Touch Develop + +Touch Develop has no `repeat` loop. Instead you can used a for loop + +``` +for (let i = 0; i < 5; i++) { +} +``` + +The loop above will repeat five (5) times. + diff --git a/docs/reference/loops/while.md b/docs/reference/loops/while.md new file mode 100644 index 00000000..9a8063d6 --- /dev/null +++ b/docs/reference/loops/while.md @@ -0,0 +1,43 @@ +# While + +Repeat code in a loop while a condition is true. #docs #while #language + +### @parent blocks/language + + +Repeat code while a [Boolean](/microbit/reference/types/boolean) `condition` is true. + +### ~hide + +``` +let condition = false +``` + +### ~ + +### Block Editor + +![](/static/mb/string-0.png) + +The while loop has a *condition* that evaluates to a [Boolean](/microbit/reference/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`. + +The condition is tested before any code runs. Which means that if the condition is false, the code inside the loop doesn't execute. + +### Example: diagonal line + +The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`). + +// index is set to 4 + +![](/static/mb/blocks/var-10.png) + +// subtract 1 from `index` each time through loop + +### Lessons + +[rotation animation](/microbit/lessons/rotation-animation) + +### See also + +[on button pressed](/microbit/reference/input/on-button-pressed), [for](/microbit/reference/loops/for), [if](/microbit/blocks/if), [forever](/microbit/reference/basic/forever) + diff --git a/docs/reference/math/math.md b/docs/reference/math/math.md new file mode 100644 index 00000000..c7f2d007 --- /dev/null +++ b/docs/reference/math/math.md @@ -0,0 +1,52 @@ +# Math Library + +Functions in the math library. #docs #math #random #abs #mod #pow #max #min #clamp + +### @parent blocks/language + +The math library includes math related functions that you can use with [Numbers](/microbit/reference/types/number). + +* In the [Block editor](/microbit/blocks/editor), click **maths** on the left to see the available blocks + +The functions available in Block Editor are: + +### abs + +math `->` abs (x : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the absolute value of input parameter `x` + +![](/static/mb/blocks/math-0.png) + +### max + +math `->` max (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the larger of two input numbers (`x` and `y`) + +![](/static/mb/blocks/math-1.png) + +### min + +math `->` min (x : [Number](/microbit/reference/types/number), y : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns the smaller of two input numbers (`x` and `y`) + +![](/static/mb/blocks/math-2.png) + +### random + +math `->` random (limit : [Number](/microbit/reference/types/number)) *returns* [Number](/microbit/reference/types/number) + +returns a random [Number](/microbit/reference/types/number) between 0 and the parameter *limit* + +![](/static/mb/blocks/math-3.png) + +### Lessons + +[love meter](/microbit/lessons/love-meter) + +### See also + +[Block Editor documentation](/microbit/blocks/contents), [Number](/microbit/reference/types/number) + diff --git a/docs/reference/music/change-tempo.md b/docs/reference/music/change-tempo.md new file mode 100644 index 00000000..a7c93408 --- /dev/null +++ b/docs/reference/music/change-tempo.md @@ -0,0 +1,20 @@ +# Change Tempo By + +Change the tempo by the specified amount + +## Simulator + +Simulation of this function is available in many, but not all browsers. + +```sig +music.changeTempoBy(20) +``` + +### Parameters + +* `bpm` : [Number](/microbit/reference/types/number) - change the tempo by beats per minute + +### See also + +[play tone](/microbit/reference/music/play-tone), [ring tone](/microbit/reference/music/ring-tone) + diff --git a/docs/reference/music/play-tone.md b/docs/reference/music/play-tone.md new file mode 100644 index 00000000..e002130f --- /dev/null +++ b/docs/reference/music/play-tone.md @@ -0,0 +1,28 @@ +# Play Tone + +Plays a music tone through pin ``P0`` for the given duration. + +## Simulator + +Simulation of this function is available in many, but not all browsers. + +```sig +music.playTone(440, 120) +``` + +### Parameters + +* `frequency` : [Number](/microbit/reference/types/number) - the frequency of the note (in Herz) +* `ms`: [Number](/microbit/reference/types/number) - the duration of the note (milliseconds) + +## Example + +```blocks +let freq = music.noteFrequency(Note.C) +music.playTone(freq, 1000) +``` + +### See also + +[rest](/microbit/reference/music/rest), [ring tone](/microbit/reference/music/ring-tone) , [tempo](/microbit/reference/music/tempo), [set tempo](/microbit/reference/music/set-tempo), [change tempo by](/microbit/reference/music/change-tempo-by) + diff --git a/docs/reference/music/rest.md b/docs/reference/music/rest.md new file mode 100644 index 00000000..066f2ef1 --- /dev/null +++ b/docs/reference/music/rest.md @@ -0,0 +1,28 @@ +# Rest + +Rests (plays nothing) for a specified time through pin PO. + +## Simulator + +Simulation of this function is available in many, but not all browsers. + +```sig +music.rest(400) +``` + +### Parameters + +* `ms`: [Number](/microbit/reference/types/number) - the duration of the rest (milliseconds) + +## Example + +```blocks +let frequency = music.noteFrequency(Note.C) +music.playTone(frequency, 1000) +music.rest(1000) +``` + +### See also + +[play tone](/microbit/reference/music/play-tone), [ring tone](/microbit/reference/music/ring-tone) , [tempo](/microbit/reference/music/tempo), [set tempo](/microbit/reference/music/set-tempo), [change tempo by](/microbit/reference/music/change-tempo-by) + diff --git a/docs/reference/music/ring-tone.md b/docs/reference/music/ring-tone.md new file mode 100644 index 00000000..dd1df69e --- /dev/null +++ b/docs/reference/music/ring-tone.md @@ -0,0 +1,30 @@ +# Ring Tone + +Play a continuous tone through pin P0. + +## Simulator + +Simulation of this function is available in many, but not all browsers. + +```sig +music.ringTone(440) +``` + +### Parameters + +* `frequency` : [Number](/microbit/reference/types/number) - Plays a tone in (Hz) + +### Example + +Play a sound based on the tile of the device + +```blocks +basic.forever(() => { + music.ringTone(input.acceleration(Dimension.X)) +}) +``` + +### See also + +[rest](/microbit/reference/music/rest), [play tone](/microbit/reference/music/play-tone) , [tempo](/microbit/reference/music/tempo), [set tempo](/microbit/reference/music/set-tempo), [change tempo by](/microbit/reference/music/change-tempo-by) + diff --git a/docs/reference/music/set-tempo.md b/docs/reference/music/set-tempo.md new file mode 100644 index 00000000..93c45a90 --- /dev/null +++ b/docs/reference/music/set-tempo.md @@ -0,0 +1,16 @@ +# Set Tempo + +Sets the tempo to the specified amount + +```sig +music.setTempo(60) +``` + +### Parameters + +* Returns : [Number](/microbit/reference/types/number) - sets the tempo in beats per minute + +### See also + +[play tone](/microbit/reference/music/play-tone), [ring tone](/microbit/reference/music/ring-tone) , [rest](/microbit/reference/music/rest), [tempo](/microbit/reference/music/tempo), [change tempo by](/microbit/reference/music/change-tempo-by) + diff --git a/docs/reference/music/tempo.md b/docs/reference/music/tempo.md new file mode 100644 index 00000000..c6c7b844 --- /dev/null +++ b/docs/reference/music/tempo.md @@ -0,0 +1,16 @@ +# Tempo + +Returns the tempo in beats per minute. + +```sig +music.tempo() +``` + +### Parameters + +* Returns : [Number](/microbit/reference/types/number) - returns the tempo in beats per minute + +### See also + +[play tone](/microbit/reference/music/play-tone), [ring tone](/microbit/reference/music/ring-tone) , [rest](/microbit/reference/music/rest), [set tempo](/microbit/reference/music/set-tempo), [change tempo by](/microbit/reference/music/change-tempo-by) + diff --git a/docs/reference/offline.md b/docs/reference/offline.md new file mode 100644 index 00000000..27a83389 --- /dev/null +++ b/docs/reference/offline.md @@ -0,0 +1,34 @@ +# Off-line support + +The micro:bit pins #docs #gnd #p1 #p2 #p3 #3V + +## We listened to your feedback! + +Following the feedback from teachers, the following improvements were made: + +* compile without signing in +* compile offline +* save and load code using files + +## How to work offline + +If you have loaded the web app at some time in the past (by clicking on "my scripts" from the home page), then if you later open the same browser (whether you are online or offline) and type in the URL KINDSCRIPTWEBSITE, you will be able to access all the features of the web app. Note that it is important to end the URL with "/". + +## Save and load code using files + +![](/static/mb/offline-0.png) + +The micro:bit automatically saves and synchronises scripts for signed-in users through the cloud. We also decided to also support file save/load for offline support and sharing via email and other storage providers. Users are now able to import and export scripts as files. For example, they can simply email it or submit them in their classroom portal. + +![](/static/mb/offline-1.png) + +## The new in-browser compiler + +The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The micro:bit compilation process (see page 10 in the [Quick Start Guide](/microbit/js/quick-start)) has been updated below to reflect the new compiler architecture, as shown below: + +![](/static/mb/offline-2.png) + +The C++ compiler is now only used to compile the micro:bit runtime - this is done offline by the micro:bit team and the pre-compiled runtime is linked with your compiled script in the browser. + +Compiled .hex files can also be imported back into the web site. This make it easy for a teacher to review the source of a script by simply drag and dropping the file into the editor. + diff --git a/docs/reference/out-of-bounds.md b/docs/reference/out-of-bounds.md new file mode 100644 index 00000000..4ad0a935 --- /dev/null +++ b/docs/reference/out-of-bounds.md @@ -0,0 +1,43 @@ +# out of bounds + +The behavior of functions whose parameter values are out of bounds. + +Many of the BBC micro:bit functions have parameters. If a parameter is an unexpected value, the parameter is considered *out of bounds*. + +For example, the [plot](/microbit/reference/led/plot) function has two parameters: + +### syntax + +``` +export function plot(x: number, y: number) +``` + +### parameters + +* x - the *x coordinate* or horizontal position (0, 1, 2, 3, 4) +* y - the *y coordinate* or vertical position (0, 1, 2, 3, 4) + +### out of bounds + +here's an example of code with an out of bounds parameter (the *x* and *y* parameters are outside the expected range of 0-4): + +``` +led.plot(9, -21) +``` + +### what happens? + +Typically, when a parameter supplied to a function is out of bounds that function does nothing (as if the function never executed). So, in the above case, the LED screen will not change. + +### return value + +If you call the `point` function with an out of bounds parameter, the function returns `false`: + +``` +let on = led.point(5, -5) +``` + +### see also + +For more information on the out-of-bounds behavior of a function, see the documentation for that [function](/microbit/js/contents). + diff --git a/docs/reference/pins/analog-pitch.md b/docs/reference/pins/analog-pitch.md new file mode 100644 index 00000000..62213a90 --- /dev/null +++ b/docs/reference/pins/analog-pitch.md @@ -0,0 +1,31 @@ +# Analog Pitch + +Emits a Pulse With Modulation (PWM) signal to the current pitch [pin](/microbit/device/pins). Use [analog set pitch pin](/microbit/reference/pins/analog-set-pitch-pin) to set the pitch pin. + +```sig +pins.analogPitch(440, 300) +``` + +### Parameters + +* `frequency` : [Number](/microbit/reference/types/number) +* `ms`: [Number](/microbit/reference/types/number) + +### Example + +``` +pins.analogSetPitchPin("P0") +let frequency1 = 440 +let duration = 1000 +pins.analogPitch(frequency1, duration) +``` + +### Some common notes + +* 440 = A4 on piano +* see [piano key frequencies ](https://en.wikipedia.org/wiki/Piano_key_frequencies) for more information + +### See also + +[micro:bit pins](/microbit/device/pins), [analog set period](/microbit/reference/pins/analog-set-period), [analog set pitch pin](/microbit/reference/pins/analog-set-pitch-pin) + diff --git a/docs/reference/pins/analog-read-pin.md b/docs/reference/pins/analog-read-pin.md new file mode 100644 index 00000000..0f07d0ae --- /dev/null +++ b/docs/reference/pins/analog-read-pin.md @@ -0,0 +1,29 @@ +# Analog Read Pin + +Read the specified [pin](/microbit/device/pins) (P0, P1, P2) as analog. + +```sig +pins.analogReadPin(AnalogPin.P0) +``` + +### Parameters + +* name - the pin name (`P0`, `P1`, or `P2`) + +### Returns + +* [Number](/microbit/reference/types/number) - a number between 0 and 1023 (included) + +The following code reads `P1` and charts it on the screen: + +```blocks +basic.forever(() => { + let value = pins.analogReadPin(AnalogPin.P1) + led.plotBarGraph(value, 1023) +}); +``` + +### See also + +[micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [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) + diff --git a/docs/reference/pins/analog-set-period.md b/docs/reference/pins/analog-set-period.md new file mode 100644 index 00000000..5c49ad27 --- /dev/null +++ b/docs/reference/pins/analog-set-period.md @@ -0,0 +1,24 @@ +# Analog Set Period + +Configures the period of the Pulse Width Modulation (PWM) on the specified analog [pin](/microbit/device/pins) (``P0``, ``P1`` or ``P2``). Prior to calling this function, the given pin should be set as analog. + +```sig +pins.analogSetPeriod(AnalogPin.P0, 20000) +``` + +### Parameters + +* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2") +* `micros` - a [Number](/microbit/reference/types/number) representing the micro-seconds of the analog period. + +The following code + +```blocks +pins.analogWritePin(AnalogPin.P0, 512) +pins.analogSetPeriod(AnalogPin.P0, 20000) +``` + +### See also + +[micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin) + diff --git a/docs/reference/pins/analog-set-pitch-pin.md b/docs/reference/pins/analog-set-pitch-pin.md new file mode 100644 index 00000000..172b31b0 --- /dev/null +++ b/docs/reference/pins/analog-set-pitch-pin.md @@ -0,0 +1,30 @@ +# Analog Set Pitch Pin + +Specify which [pin](/microbit/device/pins) (P0, P1, P2) is used to generate tones. + +```sig +pins.analogSetPitchPin(AnalogPin.P0) +``` + +### Parameters + +* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2") + +### Example + +``` +pins.analogSetPitchPin(AnalogPin.P0) +let frequency = 440 +let duration = 1000 +pins.analogPitch(frequency, duration) +``` + +### Some common notes + +* 440 = A4 on piano +* see [piano key frequencies ](https://en.wikipedia.org/wiki/Piano_key_frequencies) for more information + +### See also + +[micro:bit pins](/microbit/device/pins), [analog set period](/microbit/reference/pins/analog-set-period), [analog pitch](/microbit/reference/pins/analog-pitch) + diff --git a/docs/reference/pins/analog-write-pin.md b/docs/reference/pins/analog-write-pin.md new file mode 100644 index 00000000..d1a354cb --- /dev/null +++ b/docs/reference/pins/analog-write-pin.md @@ -0,0 +1,23 @@ +# Analog Write Pin + +Write to the specified [pin](/microbit/device/pins) (P0, P1, P2) as analog. + +```sig +pins.analogWritePin(AnalogPin.P0, 400) +``` + +### Parameters + +* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2") +* `value` - a [Number](/microbit/reference/types/number) between 0 and 1023 included + +The following code writes `1023` to the `P0` pin: + +```blocks +pins.analogWritePin(AnalogPin.P0, 1023) +``` + +### See also + +[micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin) + diff --git a/docs/reference/pins/digital-read-pin.md b/docs/reference/pins/digital-read-pin.md new file mode 100644 index 00000000..bba96c12 --- /dev/null +++ b/docs/reference/pins/digital-read-pin.md @@ -0,0 +1,40 @@ +# Digital Read Pin + +The digital read pin function. #digitalreadpin #docs + +Digitally read the specified [pin](/microbit/device/pins) (``P0``, ``P1``, ``P2``, ...) as digital. **Some pins are also used by the display, read the [pin documentation ](/microbit/device/pins) carefully.** + +```sig +pins.digitalReadPin(DigitalPin.P3) +``` + +### Parameters + +* name - the pin name ``P0``, ``P1``, ``P2``, ... + +### Returns + +* [Number](/microbit/reference/types/number) - 0 or 1 + +### Example: football score keeper + +The following example reads `P0` to determine when a goal is scored. When `P0 = 1`, the code uses `digital write pin` to play a buzzer sound: + +```blocks +let score = 0 +basic.showNumber(score) +basic.forever(() => { + if (pins.digitalReadPin(DigitalPin.P0) == 1) { + score++; + pins.digitalWritePin(DigitalPin.P2, 1) + basic.showNumber(score) + basic.pause(1000) + pins.digitalWritePin(DigitalPin.P2, 0) + } +}) +``` + +### See also + +[micro:bit pins](/microbit/device/pins), [digital write pin](/microbit/reference/pins/digital-write-pin), [analog read pin](/microbit/reference/pins/analog-read-pin), [analog write pin](/microbit/reference/pins/analog-write-pin), [on pin pressed](/microbit/reference/input/on-pin-pressed), [pin is pressed](/microbit/reference/input/pin-is-pressed) + diff --git a/docs/reference/pins/digital-write-pin.md b/docs/reference/pins/digital-write-pin.md new file mode 100644 index 00000000..0cab9667 --- /dev/null +++ b/docs/reference/pins/digital-write-pin.md @@ -0,0 +1,35 @@ +# Digital Write Pin + +Write the value ``0`` or ``1`` to the specified (digital) [pin](/microbit/device/pins). **Some pins are also used by the display, read the [pin documentation ](/microbit/device/pins) carefully.** + +```sig +pins.digitalWritePin(DigitalPin.P1, 1) +``` + +### Parameters + +* name - the pin name (``P0``, ``P1``, ``P2``, ...) +* value - [Number](/microbit/reference/types/number); 0 or 1 + +### Example: football score keeper + +The following example reads `P0` to determine when a goal is scored. When `P0 = 1`, the code uses `digital write pin` to play a buzzer sound: + +```blocks +let score = 0 +basic.showNumber(score) +basic.forever(() => { + if (pins.digitalReadPin(DigitalPin.P0) == 1) { + score++; + pins.digitalWritePin(DigitalPin.P2, 1) + basic.showNumber(score) + basic.pause(1000) + pins.digitalWritePin(DigitalPin.P2, 0) + } +}) +``` + +### See also + +[micro:bit pins](/microbit/device/pins), [digital read pin](/microbit/reference/pins/digital-read-pin), [analog read pin](/microbit/reference/pins/analog-read-pin), [analog write pin](/microbit/reference/pins/analog-write-pin), [on pin pressed](/microbit/reference/input/on-pin-pressed), [pin is pressed](/microbit/reference/pins/pin-is-pressed) + diff --git a/docs/reference/pins/map.md b/docs/reference/pins/map.md new file mode 100644 index 00000000..cfd8bfe9 --- /dev/null +++ b/docs/reference/pins/map.md @@ -0,0 +1,32 @@ +# Map + +Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc. + +Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The `math->clamp` function may be used either before or after this function, if limits to the ranges are desired. + +```sig +pins.map(0, 0, 4, 0, 1023); +``` + +### Parameters + +* ``value``: [Number](/microbit/reference/types/number) - the value to map +* ``from low``: [Number](/microbit/reference/types/number) - lower bound of the origin interval +* ``from high``: [Number](/microbit/reference/types/number) - upper bound of the origin interval +* ``to low``: [Number](/microbit/reference/types/number) - lower bound of the target interval +* ``to high``: [Number](/microbit/reference/types/number) - upper bound of the target interval + +## Example + +Map the value read from the analog pin ``P0`` to an LED index between ``0`` and ``4``. + +```blocks +let value1 = pins.analogReadPin(AnalogPin.P0) +let index = pins.map(value1, 0, 1023, 0, 4) +led.plot(0, index) +``` + +### See also + +[analog read pin](/microbit/reference/pins/analog-read-pin) + diff --git a/docs/reference/pins/servo-set-pulse.md b/docs/reference/pins/servo-set-pulse.md new file mode 100644 index 00000000..92e82def --- /dev/null +++ b/docs/reference/pins/servo-set-pulse.md @@ -0,0 +1,25 @@ +# Servo Set Pulse + +Configures the pin [pin](/microbit/device/pins) (``P0``, ``P1`` or ``P2``) as an analog/PWM output if it isn't already, configures the period to be 20ms, and sets the pulse width, based on the value it is given. + +```sig +pins.servoSetPulse(AnalogPin.P1, 1500) +``` + +### Parameters + +* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2") +* `micros` - a [Number](/microbit/reference/types/number) representing the micro-seconds of the pulse width. + +### Example + +The following code sets the servo pulse to ``1000`` micro seconds. + +```blocks +pins.servoSetPulse(AnalogPin.P0, 1000) +``` + +### See also + +[BBC micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin) + diff --git a/docs/reference/pins/servo-write-pin.md b/docs/reference/pins/servo-write-pin.md new file mode 100644 index 00000000..fad1f4e0 --- /dev/null +++ b/docs/reference/pins/servo-write-pin.md @@ -0,0 +1,45 @@ +# Servo Write Pin + +Writes a value to the servo on to the specified [pin](/microbit/device/pins) (``P0``, ``P1``, ``P2``), controlling the shaft accordingly. + +* on a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. +* on a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement). + +```sig +pins.servoWritePin(AnalogPin.P0, 180) +``` + +### Parameters + +* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2") +* `value` - a [Number](/microbit/reference/types/number) between 0 and 180 included + +### Examples + +* setting the shaft angle to mid point on a servo + +```blocks +pins.servoWritePin(AnalogPin.P0, 90) +``` + +* control the shaft by using the tilt information of the accelerometer + +```blocks +basic.forever(() => { + let millig = input.acceleration(Dimensions.X) + // map accelerometer readings to angle + let angle = pins.map(millig, -1023, 1023, 0, 180) + pins.servoWritePin(AnalogPin.P0, angle) +}) +``` + +* setting the full speed on a continuous servo + +```blocks +pins.servoWritePin(AnalogPin.P0, 0) +``` + +### See also + +[BBC micro:bit pins](/microbit/device/pins), [servo set pulse](/microbit/reference/pins/servo-set-pulse) + diff --git a/docs/reference/radio/on-data-received.md b/docs/reference/radio/on-data-received.md new file mode 100644 index 00000000..9929d501 --- /dev/null +++ b/docs/reference/radio/on-data-received.md @@ -0,0 +1,35 @@ +# On Data Received + +Registers code to run when a packet is received over ``radio``. + +## Important Security Consideration + +The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits. + +This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. + +For serious applications, BLE should be considered a substantially more secure alternative. + +```sig +radio.onDataReceived(() => {}) +``` + +### Parameters + +* body - is an action + +### Example + +```blocks +basic.forever(() => { + radio.sendNumber(input.acceleration(Dimension.X)); +}) +radio.onDataReceived(() => { + led.plotBarGraph(radio.receiveNumber(), 1023); +}) +``` + +### See also + +[receive number](/microbit/radio/receive-number), [send number](/microbit/radio/send-number), [set group](/microbit/reference/radio/set-group) + diff --git a/docs/reference/radio/receive-number.md b/docs/reference/radio/receive-number.md new file mode 100644 index 00000000..2c43f86b --- /dev/null +++ b/docs/reference/radio/receive-number.md @@ -0,0 +1,34 @@ +# Receive Number + +Reads the next radio packet if any and returns the first number. + +## Important Security Consideration + +The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits. + +This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. + +For serious applications, BLE should be considered a substantially more secure alternative. + +```sig +radio.receiveNumber() +``` + +### Return value + +* the first number [number](/microbit/reference/types/number) of the packet if any. `0` otherwise. + +### Examples + +Read the number broadcasted by other micro:bits. + +```blocks +radio.onDataReceived(() => { + led.plotBarGraph(radio.receiveNumber(), 1023); +}) +``` + +### See also + +[receive number](/microbit/input/receive-number), [on data received](/microbit/reference/radio/on-data-received) + diff --git a/docs/reference/radio/send-number.md b/docs/reference/radio/send-number.md new file mode 100644 index 00000000..7cf7432c --- /dev/null +++ b/docs/reference/radio/send-number.md @@ -0,0 +1,34 @@ +# Send Number + +Broadcasts a number data packet to other micro:bits connected via ``radio``. + +## Important Security Consideration + +The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits. + +This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. + +For serious applications, BLE should be considered a substantially more secure alternative. + +```sig +radio.sendNumber(0) +``` + +### Parameters + +* packet - a number to be transmitted. + +### Examples + +Broadcasts the value of ``acceleration`` x to other micro:bits. + +```blocks +input.onButtonPressed(Button.A, () => { + radio.sendNumber(input.acceleration(Dimension.X)) +}) +``` + +### See also + +[receive number](/microbit/input/receive-number), [on data received](/microbit/reference/radio/on-data-received) + diff --git a/docs/reference/radio/set-group.md b/docs/reference/radio/set-group.md new file mode 100644 index 00000000..38031c34 --- /dev/null +++ b/docs/reference/radio/set-group.md @@ -0,0 +1,34 @@ +# Set Group + +Sets the group id for ``radio`` communications. A micro:bit can only listen to one group ID at any time. + +Unless specified, the group id is automatically inferred from the script source. Every script with the same exact source code with start with the same group id. + +## Important Security Consideration + +The functions in the ``radio`` namespace allow the BBC micro:bit to communicate with other micro:bits. + +This API does not contain any form of encryption, authentication or authorization. It's purpose is solely for use as a teaching aid to demonstrate how simple communications operates, and to provide a sandpit through which learning can take place. + +For serious applications, BLE should be considered a substantially more secure alternative. + +```sig +radio.setGroup(1) +``` + +### Parameters + +* ``id`` -- a [number](/microbit/number) between ``0`` and ``255``. + +### Example + +Sets the group to 128. + +```blocks +radio.setGroup(128) +``` + +### See also + +[receive number](/microbit/radio/receive-number), [send number](/microbit/radio/send-number), [on data received](/microbit/radio/on-data-received) + diff --git a/docs/reference/types.md b/docs/reference/types.md new file mode 100644 index 00000000..704e39e7 --- /dev/null +++ b/docs/reference/types.md @@ -0,0 +1,17 @@ +# types + +Touch Develop types #docs #variables #var #types #data + +### @parent language + +A *type* refers to a class of data and the operations permitted on that data. The following types are supported by Block Editor for the BBC micro:bit: + +* **[String](/microbit/reference/types/string)**: a sequence of characters +* **[Number](/microbit/reference/types/number)**: an integer number (32-bit signed) +* **[Boolean](/microbit/reference/types/boolean)**: true or false +* **[Image](/microbit/blocks/image)**: a collection of [micro:bit LED states](/microbit/device/screen) (on/off) + +### see also + +[local variables](/microbit/reference/variables/var), [assignment operator](/microbit/reference/variables/assign) + diff --git a/docs/reference/types/boolean.md b/docs/reference/types/boolean.md new file mode 100644 index 00000000..0b5b2584 --- /dev/null +++ b/docs/reference/types/boolean.md @@ -0,0 +1,108 @@ +# Boolean + +true or false. #docs #boolean #var + +### @parent blocks/language + +A Boolean has one of two possible values: `true`; `false`. Boolean (logical) operators (*and*, *or*, *not*) take Boolean inputs and yields a Boolean value. Comparison operators on other types ([numbers](/microbit/reference/types/number), [strings](/microbit/reference/types/string) yields a Boolean value. + +The following blocks represent the true and false Boolean values, which can be plugged in anywhere a Boolean value is expected: + +```blocks +true; +false; +``` + +The next three blocks represent the three Boolean (logic) operators: + +```blocks +true && false; +true || false; +!true; +``` + +The next six blocks represent comparison operators that yield a Boolean value. Most comparisons you will do involve [numbers](/microbit/reference/types/number): + +```blocks +42 == 0; +42 != 0; +42 < 0; +42 > 0; +42 <= 0; +42 >= 0; +``` + +Boolean values and operators are often used with an [if](/microbit/blocks/if) or [while](/microbit/reference/loops/while) statement to determine which code will execute next. For example: + +### Functions that return a Boolean + +Some functions return a Boolean value, which you can store in a Boolean variable. For example, the following code gets the on/off state of `point (1, 2)` and stores this in the Boolean variable named `on`. Then the code clears the screen if `on` is `true`: + +### Boolean operators + +Boolean operators take Boolean inputs and evaluate to a Boolean output: + +### Conjunction: `A and B` + +`A and B` evaluates to `true` if-and-only-if both A and B are true: + +```blocks +false && false == false; +false && true == false; +true && false == false; +true && true == true; +``` + +### Disjunction: `A or B` + +`A or B` evaluates to `true` if-and-only-if either A is true or B is true: + +```blocks +false || false == false; +false || true == true; +true || false == true; +true || true == true; +``` + +### Negation: `not A` + +`not A` evaluates to the opposite (negation) of A: + +```blocks +!false == true; +!true == false; +``` + +### Example + +This example turns on LED `3 , 3`, if LEDs `1 , 1` and `2 , 2` are both on: + +```blocks +if (led.point(1,1) && led.point(2,2)) { + led.plot(3,3) +} +``` + +### Comparisons of numbers and strings + +When you compare two Numbers, you get a Boolean value, such as the comparison `x < 5` in the code below: + +```blocks +let x = math.random(5) +if(x < 5) { + basic.showString("low"); +} else { + basic.showString("high"); +} +``` + +See the documentation on [Numbers](/microbit/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/microbit/reference/types/string-functions) using the `equals` function. + +### Lessons + +[rotation animation](/microbit/lessons/rotation-animation), [love meter](/microbit/lessons/love-meter), [zoomer](/microbit/lessons/zoomer) + +### See also + +[if](/microbit/blocks/if), [while](/microbit/reference/loops/while), [number](/microbit/reference/types/number) + diff --git a/docs/reference/types/number.md b/docs/reference/types/number.md new file mode 100644 index 00000000..311f1e4b --- /dev/null +++ b/docs/reference/types/number.md @@ -0,0 +1,61 @@ +# Number + +An integer number. #docs #Number #var + +### @parent blocks/language + +A *Number* is an integer such as `42` or `-42`. More precisely, a *Number* is a signed 32-bit integer (two's complement). + +### Declare a number variable + +Use the [var statement](/microbit/reference/variables/var) and the [assignment operator](/microbit/reference/variables/assign) declare a *local* number variable. Like this: + +![](/static/mb/blocks/number-0.png) + +### Arithmetic operators + +The following arithmetic operators work on numbers and return a [Number](/microbit/reference/types/number): + +* addition: `1 + 3` +* subtraction: `1 - 3 ` +* multiplication: `3 * 2` +* integer division: `7 / 3` +* modulo is available through the [math library](/microbit/blocks/math) + +### Relational operators + +The following relational operators work on numbers and return a [Boolean](/microbit/reference/types/boolean): + +* equality: `(3 + 1) = 4` +* inequality: `3 != 4` +* less or equal than: `3 <= 4` +* less than: `3 < 4` +* greater or equal than : `4 >= 3` +* greater than: `4 > 3` + +### Show number + +The [show number](/microbit/reference/basic/show-number) function displays a number on the [LED screen](/microbit/device/screen). For example, this code displays the number 42: + +![](/static/mb/blocks/number-1.png) + +### Functions that return a number + +Some functions return a number, which you can store in a variable. For example the following code gets the display brightness (using the [brightness function](/microbit/reference/led/brightness)) and stores the value in a variable named `brightness`: + +![](/static/mb/blocks/number-2.png) + +### Math functions + +The [math library](/microbit/blocks/math) includes math related functions. In the [Block Editor](/microbit/blocks/editor), click `math` on the Code Keyboard to see the math functions. For example, the `absolute` function returns the returns the absolute value of input parameter `x`: + +![](/static/mb/blocks/number-3.png) + +### Lessons + +[game counter](/microbit/lessons/game-counter), [love meter](/microbit/lessons/love-meter) + +### See also + +[math library](/microbit/blocks/math), [var](/microbit/reference/variables/var), [Boolean](/microbit/reference/types/boolean), [show number](/microbit/reference/basic/show-number) + diff --git a/docs/reference/types/string.md b/docs/reference/types/string.md new file mode 100644 index 00000000..46e829e3 --- /dev/null +++ b/docs/reference/types/string.md @@ -0,0 +1,44 @@ +# String + +a piece of text. #docs #String + +### @parent blocks/language + +A *String* is a sequence of characters. For the BBC micro:bit, ASCII character codes 32 to 126 are supported; letters, digits, punctuation marks, and a few symbols. All other character codes appear as a ? on the [LED screen](/microbit/device/screen). + +### Declare a string + +Use the [var statement](/microbit/reference/variables/var) and the [assignment operator](/microbit/reference/variables/assign) to declare a new *local* string variable. Like this: + +![](/static/mb/blocks/string-0.png) + +To declare a string using the [Block Editor](/microbit/blocks/editor): + +1. Click `Variables` (as the Block drawer). + +2. Type a name for your new string variable by clicking the down arrow, then click New Variable. Then type the variable name "salutation" + +2. Drag a string block on the right side of the operator. + +3. Click `"Hello"` and then type a string like `hello`. + +Your code should look something like this: + +![](/static/mb/blocks/string-1.png) + +### The function `show string` + +Use [show string](/microbit/reference/basic/show-string) to display a string on the [LED screen](/microbit/device/screen). If the string is multiple characters, the string scrolls right to left. The following example displays `Hello world!` on the micro:bit screen: + +![](/static/mb/blocks/string-2.png) + +The parameter of `show string` specifies the string + +### Lessons + +[glowing pendulum](/microbit/lessons/glowing-pendulum), [zoomer](/microbit/lessons/zoomer), [temperature](/microbit/lessons/temperature) + +### See also + +[variables](/microbit/reference/variables/var), [string functions](/microbit/reference/types/string-functions), [Number](/microbit/reference/types/number), [show string](/microbit/reference/basic/show-string) + diff --git a/docs/reference/variables/assign.md b/docs/reference/variables/assign.md new file mode 100644 index 00000000..5a764935 --- /dev/null +++ b/docs/reference/variables/assign.md @@ -0,0 +1,40 @@ +# Assignment Operator + +Set the value for local and global variables #docs #assignment #language #var #data + +### @parent blocks/operators + +Set or change the value of a variable + +````blocks +let item = 0 +```` + +Use the assignment operator to set or change the value of a [variable](/microbit/reference/variables/var). + +### Declare a variable + +Declare a new *local* variable using the [variable](/microbit/reference/variables/var) statement and the assignment operator. Like this: + +````blocks +let num1 = 42; +let name = "Joe"; +```` + +The variable's name is on the left of the assignment operator and the variable's value is on the right: + +````blocks +let num1 = 42 +```` +### Notes + +* You can use the assignment operator with variables of each of the supported [types](/microbit/blocks/types). + +### Lessons + +[rotation animation](/microbit/lessons/rotation-animation) + +### See also + +[variable](/microbit/reference/variables/var), [types](/microbit/blocks/types) + diff --git a/docs/reference/variables/change-var.md b/docs/reference/variables/change-var.md new file mode 100644 index 00000000..52c0fb3e --- /dev/null +++ b/docs/reference/variables/change-var.md @@ -0,0 +1,40 @@ +# Change Value + +Set the value for local and global variables #docs #assignment #language #var #data + +### @parent blocks/change-value + +Change the value of a variable + +```blocks +let x = 0 +x += 1 +``` + +### Declare a variable + +Use the assignment operator to set the value of a [variable](/microbit/reference/variables/var). Change the value of a variable from 0 to 1 using the change item block. Like this: + +```blocks +let x = 0 +x += 1 +``` + +### Example + +Use the assignment operator to set the value of a [variable](/microbit/reference/variables/var). Change the value of a variable from 0 to 1 using the change item block. Then display the new value of the variable on the LED screen. Like this: + +```blocks +let x = 0; +x += 1; +basic.showNumber(x); +``` + +### Notes + +* You can use the assignment operator with variables of each of the supported [types](/microbit/blocks/types). + +### See also + +[variable](/microbit/reference/variables/var), [types](/microbit/blocks/types) + diff --git a/docs/reference/variables/var.md b/docs/reference/variables/var.md new file mode 100644 index 00000000..2b759d70 --- /dev/null +++ b/docs/reference/variables/var.md @@ -0,0 +1,92 @@ +# Local Variables + +How to define and use local variables. #docs #var #language #variables + +### @parent language + +A variable is a place where you can store and retrieve data. Variables have a name, a [type](/microbit/blocks/types), and value: + +* *name* is how you'll refer to the variable +* *type* refers to the kind of data a variable can store +* *value* refers to what's stored in the variable + +### Var statement + +Use the Block Editor variable statement to create a local variable and the [assignment operator](/microbit/reference/variables/assign) to store something in the variable. + +For example, this code stores the number `2` in the `num1` variable: + +![](/static/mb/blocks/var-0.png) + +Here's how to define a variable in the Block Editor: + +1. Click `variables`. + +2. Change the default variable name if you like. + +3. Drag a block type on the right-side of the [assignment operator](/microbit/reference/variables/assign) and click the down arrow to change the variable name. + +The resulting code should look something like this: + +// string variable + +![](/static/mb/blocks/var-1.png) + +// number variable + +![](/static/mb/blocks/var-2.png) + +// boolean variable + +![](/static/mb/blocks/var-3.png) + +// image variable + +![](/static/mb/blocks/var-4.png) + +See [Image](/microbit/blocks/image) for info on creating and using image variables. + +The resulting code should look something like this: + +![](/static/mb/blocks/var-5.png) + +A variable is created for the number returned by the [brightness](/microbit/reference/led/brightness) function. + +### Using variables + +Once you've defined a variable, just use the variable's name whenever you need what's stored in the variable. For example, the following code shows the value stored in `counter` on the LED screen: + +![](/static/mb/blocks/var-6.png) + +To change the contents of a variable use the assignment operator. The following code sets `counter` to 1 and then increments `counter` by 10: + +![](/static/mb/blocks/var-7.png) + +### Why use variables? + +Variables help simplify your code. For example, instead of turning on LEDs one by one like this: + +![](/static/mb/blocks/var-8.png) + +You can use a variable (`i`) and a [for loop](/microbit/reference/loops/for) to plot the same series of points (`i` is incremented by 1, each time the loop repeats): + +![](/static/mb/blocks/var-9.png) + +### Local variables + +Local variables exist only within the function or block of code where they're defined. For example: + +![](/static/mb/blocks/comment-0.png) + +#### Notes + +* You can use the default variable names if you'd like, however, it's best to use descriptive variable names. To change a variable name in the editor, select the down arrow next to the variable and then click "new variable". + +### Lessons + +[glowing pendulum](/microbit/lessons/glowing-pendulum), [love meter](/microbit/lessons/love-meter), [temperature](/microbit/lessons/temperature), [zoomer](/microbit/lessons/zoomer) + +### See also + +[types](/microbit/blocks/types), [assignment operator](/microbit/reference/variables/assign) + diff --git a/docs/static/mb/acceleration-0.png b/docs/static/mb/acceleration-0.png new file mode 100644 index 00000000..d4f5620c Binary files /dev/null and b/docs/static/mb/acceleration-0.png differ diff --git a/docs/static/mb/analog-read-pin-0.png b/docs/static/mb/analog-read-pin-0.png new file mode 100644 index 00000000..9681a18e Binary files /dev/null and b/docs/static/mb/analog-read-pin-0.png differ diff --git a/docs/static/mb/analog-set-period-0.png b/docs/static/mb/analog-set-period-0.png new file mode 100644 index 00000000..dc86ea58 Binary files /dev/null and b/docs/static/mb/analog-set-period-0.png differ diff --git a/docs/static/mb/antenna-0.png b/docs/static/mb/antenna-0.png new file mode 100644 index 00000000..a8852657 Binary files /dev/null and b/docs/static/mb/antenna-0.png differ diff --git a/docs/static/mb/blocks/comment-0.png b/docs/static/mb/blocks/comment-0.png new file mode 100644 index 00000000..937f29dc Binary files /dev/null and b/docs/static/mb/blocks/comment-0.png differ diff --git a/docs/static/mb/blocks/contents-0.png b/docs/static/mb/blocks/contents-0.png new file mode 100644 index 00000000..5dd3fe48 Binary files /dev/null and b/docs/static/mb/blocks/contents-0.png differ diff --git a/docs/static/mb/blocks/contents-21.png b/docs/static/mb/blocks/contents-21.png new file mode 100644 index 00000000..26fb1302 Binary files /dev/null and b/docs/static/mb/blocks/contents-21.png differ diff --git a/docs/static/mb/blocks/contents-22.jpg b/docs/static/mb/blocks/contents-22.jpg new file mode 100644 index 00000000..a8d4d3d3 Binary files /dev/null and b/docs/static/mb/blocks/contents-22.jpg differ diff --git a/docs/static/mb/blocks/contents-23.png b/docs/static/mb/blocks/contents-23.png new file mode 100644 index 00000000..f71231b3 Binary files /dev/null and b/docs/static/mb/blocks/contents-23.png differ diff --git a/docs/static/mb/blocks/contents-24.png b/docs/static/mb/blocks/contents-24.png new file mode 100644 index 00000000..5471a904 Binary files /dev/null and b/docs/static/mb/blocks/contents-24.png differ diff --git a/docs/static/mb/blocks/contents-25.png b/docs/static/mb/blocks/contents-25.png new file mode 100644 index 00000000..67647303 Binary files /dev/null and b/docs/static/mb/blocks/contents-25.png differ diff --git a/docs/static/mb/blocks/game-library/pic0.png b/docs/static/mb/blocks/game-library/pic0.png new file mode 100644 index 00000000..de491588 Binary files /dev/null and b/docs/static/mb/blocks/game-library/pic0.png differ diff --git a/docs/static/mb/blocks/image-0.png b/docs/static/mb/blocks/image-0.png new file mode 100644 index 00000000..53fc0fbb Binary files /dev/null and b/docs/static/mb/blocks/image-0.png differ diff --git a/docs/static/mb/blocks/lessons-0.png b/docs/static/mb/blocks/lessons-0.png new file mode 100644 index 00000000..88e5727f Binary files /dev/null and b/docs/static/mb/blocks/lessons-0.png differ diff --git a/docs/static/mb/blocks/lessons-1.png b/docs/static/mb/blocks/lessons-1.png new file mode 100644 index 00000000..6f26c48f Binary files /dev/null and b/docs/static/mb/blocks/lessons-1.png differ diff --git a/docs/static/mb/blocks/lessons-2.png b/docs/static/mb/blocks/lessons-2.png new file mode 100644 index 00000000..8f8dec72 Binary files /dev/null and b/docs/static/mb/blocks/lessons-2.png differ diff --git a/docs/static/mb/blocks/lessons-3.png b/docs/static/mb/blocks/lessons-3.png new file mode 100644 index 00000000..38c46dba Binary files /dev/null and b/docs/static/mb/blocks/lessons-3.png differ diff --git a/docs/static/mb/blocks/lessons-4.png b/docs/static/mb/blocks/lessons-4.png new file mode 100644 index 00000000..38c4dafe Binary files /dev/null and b/docs/static/mb/blocks/lessons-4.png differ diff --git a/docs/static/mb/blocks/lessons-5.png b/docs/static/mb/blocks/lessons-5.png new file mode 100644 index 00000000..3a04b8c5 Binary files /dev/null and b/docs/static/mb/blocks/lessons-5.png differ diff --git a/docs/static/mb/blocks/lessons/answering-machine-3.png b/docs/static/mb/blocks/lessons/answering-machine-3.png new file mode 100644 index 00000000..266036a4 Binary files /dev/null and b/docs/static/mb/blocks/lessons/answering-machine-3.png differ diff --git a/docs/static/mb/blocks/lessons/answering-machine-4.png b/docs/static/mb/blocks/lessons/answering-machine-4.png new file mode 100644 index 00000000..72f94b68 Binary files /dev/null and b/docs/static/mb/blocks/lessons/answering-machine-4.png differ diff --git a/docs/static/mb/blocks/lessons/answering-machine-5.png b/docs/static/mb/blocks/lessons/answering-machine-5.png new file mode 100644 index 00000000..db5b44b0 Binary files /dev/null and b/docs/static/mb/blocks/lessons/answering-machine-5.png differ diff --git a/docs/static/mb/blocks/lessons/blink-6.png b/docs/static/mb/blocks/lessons/blink-6.png new file mode 100644 index 00000000..5b634fd8 Binary files /dev/null and b/docs/static/mb/blocks/lessons/blink-6.png differ diff --git a/docs/static/mb/blocks/lessons/blink-7.png b/docs/static/mb/blocks/lessons/blink-7.png new file mode 100644 index 00000000..39cfbfbc Binary files /dev/null and b/docs/static/mb/blocks/lessons/blink-7.png differ diff --git a/docs/static/mb/blocks/lessons/blink-8.png b/docs/static/mb/blocks/lessons/blink-8.png new file mode 100644 index 00000000..7e9dfc42 Binary files /dev/null and b/docs/static/mb/blocks/lessons/blink-8.png differ diff --git a/docs/static/mb/blocks/lessons/blocks-conditions-0.png b/docs/static/mb/blocks/lessons/blocks-conditions-0.png new file mode 100644 index 00000000..2d033a74 Binary files /dev/null and b/docs/static/mb/blocks/lessons/blocks-conditions-0.png differ diff --git a/docs/static/mb/blocks/lessons/blocks-conditions-1.png b/docs/static/mb/blocks/lessons/blocks-conditions-1.png new file mode 100644 index 00000000..6094da13 Binary files /dev/null and b/docs/static/mb/blocks/lessons/blocks-conditions-1.png differ diff --git a/docs/static/mb/blocks/lessons/blocks-conditions-2.png b/docs/static/mb/blocks/lessons/blocks-conditions-2.png new file mode 100644 index 00000000..9718d82a Binary files /dev/null and b/docs/static/mb/blocks/lessons/blocks-conditions-2.png differ diff --git a/docs/static/mb/blocks/lessons/crocodile-clip-0.jpg b/docs/static/mb/blocks/lessons/crocodile-clip-0.jpg new file mode 100644 index 00000000..73fcaf7f Binary files /dev/null and b/docs/static/mb/blocks/lessons/crocodile-clip-0.jpg differ diff --git a/docs/static/mb/blocks/lessons/digi-yoyo-1.jpg b/docs/static/mb/blocks/lessons/digi-yoyo-1.jpg new file mode 100644 index 00000000..3d10f346 Binary files /dev/null and b/docs/static/mb/blocks/lessons/digi-yoyo-1.jpg differ diff --git a/docs/static/mb/blocks/lessons/flashing-heart-5.jpg b/docs/static/mb/blocks/lessons/flashing-heart-5.jpg new file mode 100644 index 00000000..2e48927f Binary files /dev/null and b/docs/static/mb/blocks/lessons/flashing-heart-5.jpg differ diff --git a/docs/static/mb/blocks/lessons/flashing-heart-6.jpg b/docs/static/mb/blocks/lessons/flashing-heart-6.jpg new file mode 100644 index 00000000..bc778682 Binary files /dev/null and b/docs/static/mb/blocks/lessons/flashing-heart-6.jpg differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-1.png b/docs/static/mb/blocks/lessons/glowing-pendulum-1.png new file mode 100644 index 00000000..11ca9143 Binary files /dev/null and b/docs/static/mb/blocks/lessons/glowing-pendulum-1.png differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-2.png b/docs/static/mb/blocks/lessons/glowing-pendulum-2.png new file mode 100644 index 00000000..8db2a863 Binary files /dev/null and b/docs/static/mb/blocks/lessons/glowing-pendulum-2.png differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-3.png b/docs/static/mb/blocks/lessons/glowing-pendulum-3.png new file mode 100644 index 00000000..d51f2491 Binary files /dev/null and b/docs/static/mb/blocks/lessons/glowing-pendulum-3.png differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-4.png b/docs/static/mb/blocks/lessons/glowing-pendulum-4.png new file mode 100644 index 00000000..32795798 Binary files /dev/null and b/docs/static/mb/blocks/lessons/glowing-pendulum-4.png differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-5.png b/docs/static/mb/blocks/lessons/glowing-pendulum-5.png new file mode 100644 index 00000000..2571a1d1 Binary files /dev/null and b/docs/static/mb/blocks/lessons/glowing-pendulum-5.png differ diff --git a/docs/static/mb/blocks/lessons/graphics-0.png b/docs/static/mb/blocks/lessons/graphics-0.png new file mode 100644 index 00000000..577c6478 Binary files /dev/null and b/docs/static/mb/blocks/lessons/graphics-0.png differ diff --git a/docs/static/mb/blocks/lessons/graphics-1.png b/docs/static/mb/blocks/lessons/graphics-1.png new file mode 100644 index 00000000..ed4f275d Binary files /dev/null and b/docs/static/mb/blocks/lessons/graphics-1.png differ diff --git a/docs/static/mb/blocks/lessons/graphics-2.png b/docs/static/mb/blocks/lessons/graphics-2.png new file mode 100644 index 00000000..d6e5b267 Binary files /dev/null and b/docs/static/mb/blocks/lessons/graphics-2.png differ diff --git a/docs/static/mb/blocks/lessons/graphics-3.png b/docs/static/mb/blocks/lessons/graphics-3.png new file mode 100644 index 00000000..7204187b Binary files /dev/null and b/docs/static/mb/blocks/lessons/graphics-3.png differ diff --git a/docs/static/mb/blocks/lessons/graphics-4.png b/docs/static/mb/blocks/lessons/graphics-4.png new file mode 100644 index 00000000..89175a07 Binary files /dev/null and b/docs/static/mb/blocks/lessons/graphics-4.png differ diff --git a/docs/static/mb/blocks/lessons/hero-0.png b/docs/static/mb/blocks/lessons/hero-0.png new file mode 100644 index 00000000..2d056448 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-0.png differ diff --git a/docs/static/mb/blocks/lessons/hero-1.png b/docs/static/mb/blocks/lessons/hero-1.png new file mode 100644 index 00000000..aae0f632 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-1.png differ diff --git a/docs/static/mb/blocks/lessons/hero-10.jpg b/docs/static/mb/blocks/lessons/hero-10.jpg new file mode 100644 index 00000000..c9337cd5 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-10.jpg differ diff --git a/docs/static/mb/blocks/lessons/hero-11.jpg b/docs/static/mb/blocks/lessons/hero-11.jpg new file mode 100644 index 00000000..5bea27fa Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-11.jpg differ diff --git a/docs/static/mb/blocks/lessons/hero-2.png b/docs/static/mb/blocks/lessons/hero-2.png new file mode 100644 index 00000000..0dc35dd4 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-2.png differ diff --git a/docs/static/mb/blocks/lessons/hero-3.png b/docs/static/mb/blocks/lessons/hero-3.png new file mode 100644 index 00000000..a881e8ec Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-3.png differ diff --git a/docs/static/mb/blocks/lessons/hero-4.png b/docs/static/mb/blocks/lessons/hero-4.png new file mode 100644 index 00000000..f76c0f91 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-4.png differ diff --git a/docs/static/mb/blocks/lessons/hero-5.png b/docs/static/mb/blocks/lessons/hero-5.png new file mode 100644 index 00000000..5eb331e1 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-5.png differ diff --git a/docs/static/mb/blocks/lessons/hero-6.png b/docs/static/mb/blocks/lessons/hero-6.png new file mode 100644 index 00000000..c1ce0646 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-6.png differ diff --git a/docs/static/mb/blocks/lessons/hero-7.png b/docs/static/mb/blocks/lessons/hero-7.png new file mode 100644 index 00000000..4da321d2 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-7.png differ diff --git a/docs/static/mb/blocks/lessons/hero-8.jpg b/docs/static/mb/blocks/lessons/hero-8.jpg new file mode 100644 index 00000000..4560a65c Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-8.jpg differ diff --git a/docs/static/mb/blocks/lessons/hero-9.jpg b/docs/static/mb/blocks/lessons/hero-9.jpg new file mode 100644 index 00000000..b49cb4d7 Binary files /dev/null and b/docs/static/mb/blocks/lessons/hero-9.jpg differ diff --git a/docs/static/mb/blocks/lessons/light-beatbox-0.png b/docs/static/mb/blocks/lessons/light-beatbox-0.png new file mode 100644 index 00000000..fc96ee08 Binary files /dev/null and b/docs/static/mb/blocks/lessons/light-beatbox-0.png differ diff --git a/docs/static/mb/blocks/lessons/light-beatbox-1.png b/docs/static/mb/blocks/lessons/light-beatbox-1.png new file mode 100644 index 00000000..8306ef02 Binary files /dev/null and b/docs/static/mb/blocks/lessons/light-beatbox-1.png differ diff --git a/docs/static/mb/blocks/lessons/light-beatbox-2.png b/docs/static/mb/blocks/lessons/light-beatbox-2.png new file mode 100644 index 00000000..3c4df5b5 Binary files /dev/null and b/docs/static/mb/blocks/lessons/light-beatbox-2.png differ diff --git a/docs/static/mb/blocks/lessons/light-beatbox-3.png b/docs/static/mb/blocks/lessons/light-beatbox-3.png new file mode 100644 index 00000000..3e607468 Binary files /dev/null and b/docs/static/mb/blocks/lessons/light-beatbox-3.png differ diff --git a/docs/static/mb/blocks/lessons/loops-0.png b/docs/static/mb/blocks/lessons/loops-0.png new file mode 100644 index 00000000..f2f02da1 Binary files /dev/null and b/docs/static/mb/blocks/lessons/loops-0.png differ diff --git a/docs/static/mb/blocks/lessons/loops-1.png b/docs/static/mb/blocks/lessons/loops-1.png new file mode 100644 index 00000000..bd455405 Binary files /dev/null and b/docs/static/mb/blocks/lessons/loops-1.png differ diff --git a/docs/static/mb/blocks/lessons/loops-2.png b/docs/static/mb/blocks/lessons/loops-2.png new file mode 100644 index 00000000..8a9fe3ab Binary files /dev/null and b/docs/static/mb/blocks/lessons/loops-2.png differ diff --git a/docs/static/mb/blocks/lessons/loops-3.png b/docs/static/mb/blocks/lessons/loops-3.png new file mode 100644 index 00000000..0fe89bc0 Binary files /dev/null and b/docs/static/mb/blocks/lessons/loops-3.png differ diff --git a/docs/static/mb/blocks/lessons/love-meter-0.jpg b/docs/static/mb/blocks/lessons/love-meter-0.jpg new file mode 100644 index 00000000..c0667d37 Binary files /dev/null and b/docs/static/mb/blocks/lessons/love-meter-0.jpg differ diff --git a/docs/static/mb/blocks/lessons/love-meter-6.png b/docs/static/mb/blocks/lessons/love-meter-6.png new file mode 100644 index 00000000..5605c88f Binary files /dev/null and b/docs/static/mb/blocks/lessons/love-meter-6.png differ diff --git a/docs/static/mb/blocks/lessons/love-meter-7.png b/docs/static/mb/blocks/lessons/love-meter-7.png new file mode 100644 index 00000000..77c89549 Binary files /dev/null and b/docs/static/mb/blocks/lessons/love-meter-7.png differ diff --git a/docs/static/mb/blocks/lessons/lucky-7-3.png b/docs/static/mb/blocks/lessons/lucky-7-3.png new file mode 100644 index 00000000..de52ce07 Binary files /dev/null and b/docs/static/mb/blocks/lessons/lucky-7-3.png differ diff --git a/docs/static/mb/blocks/lessons/lucky-7-4.png b/docs/static/mb/blocks/lessons/lucky-7-4.png new file mode 100644 index 00000000..b83dde21 Binary files /dev/null and b/docs/static/mb/blocks/lessons/lucky-7-4.png differ diff --git a/docs/static/mb/blocks/lessons/lucky-7-5.png b/docs/static/mb/blocks/lessons/lucky-7-5.png new file mode 100644 index 00000000..c9a75c90 Binary files /dev/null and b/docs/static/mb/blocks/lessons/lucky-7-5.png differ diff --git a/docs/static/mb/blocks/lessons/pogo-0.jpg b/docs/static/mb/blocks/lessons/pogo-0.jpg new file mode 100644 index 00000000..cf3d8a7a Binary files /dev/null and b/docs/static/mb/blocks/lessons/pogo-0.jpg differ diff --git a/docs/static/mb/blocks/lessons/pogo-1.jpg b/docs/static/mb/blocks/lessons/pogo-1.jpg new file mode 100644 index 00000000..95ac7dff Binary files /dev/null and b/docs/static/mb/blocks/lessons/pogo-1.jpg differ diff --git a/docs/static/mb/blocks/lessons/pogo-2.jpg b/docs/static/mb/blocks/lessons/pogo-2.jpg new file mode 100644 index 00000000..85788652 Binary files /dev/null and b/docs/static/mb/blocks/lessons/pogo-2.jpg differ diff --git a/docs/static/mb/blocks/lessons/pogo-3.jpg b/docs/static/mb/blocks/lessons/pogo-3.jpg new file mode 100644 index 00000000..f898d276 Binary files /dev/null and b/docs/static/mb/blocks/lessons/pogo-3.jpg differ diff --git a/docs/static/mb/blocks/lessons/screen-wipe-4.png b/docs/static/mb/blocks/lessons/screen-wipe-4.png new file mode 100644 index 00000000..d4602738 Binary files /dev/null and b/docs/static/mb/blocks/lessons/screen-wipe-4.png differ diff --git a/docs/static/mb/blocks/lessons/screen-wipe-5.png b/docs/static/mb/blocks/lessons/screen-wipe-5.png new file mode 100644 index 00000000..f20d2939 Binary files /dev/null and b/docs/static/mb/blocks/lessons/screen-wipe-5.png differ diff --git a/docs/static/mb/blocks/lessons/screen-wipe-6.png b/docs/static/mb/blocks/lessons/screen-wipe-6.png new file mode 100644 index 00000000..833f860b Binary files /dev/null and b/docs/static/mb/blocks/lessons/screen-wipe-6.png differ diff --git a/docs/static/mb/blocks/lessons/screen-wipe-7.png b/docs/static/mb/blocks/lessons/screen-wipe-7.png new file mode 100644 index 00000000..0e80de20 Binary files /dev/null and b/docs/static/mb/blocks/lessons/screen-wipe-7.png differ diff --git a/docs/static/mb/blocks/lessons/smiley-3.png b/docs/static/mb/blocks/lessons/smiley-3.png new file mode 100644 index 00000000..14bf4865 Binary files /dev/null and b/docs/static/mb/blocks/lessons/smiley-3.png differ diff --git a/docs/static/mb/blocks/lessons/smiley-4.png b/docs/static/mb/blocks/lessons/smiley-4.png new file mode 100644 index 00000000..81644a43 Binary files /dev/null and b/docs/static/mb/blocks/lessons/smiley-4.png differ diff --git a/docs/static/mb/blocks/lessons/smiley-5.png b/docs/static/mb/blocks/lessons/smiley-5.png new file mode 100644 index 00000000..fe04634e Binary files /dev/null and b/docs/static/mb/blocks/lessons/smiley-5.png differ diff --git a/docs/static/mb/blocks/lessons/smiley-6.png b/docs/static/mb/blocks/lessons/smiley-6.png new file mode 100644 index 00000000..c773cc86 Binary files /dev/null and b/docs/static/mb/blocks/lessons/smiley-6.png differ diff --git a/docs/static/mb/blocks/lessons/snowflake-fall-1.jpg b/docs/static/mb/blocks/lessons/snowflake-fall-1.jpg new file mode 100644 index 00000000..28895ce5 Binary files /dev/null and b/docs/static/mb/blocks/lessons/snowflake-fall-1.jpg differ diff --git a/docs/static/mb/blocks/lessons/snowflake-fall-2.jpg b/docs/static/mb/blocks/lessons/snowflake-fall-2.jpg new file mode 100644 index 00000000..a72a2902 Binary files /dev/null and b/docs/static/mb/blocks/lessons/snowflake-fall-2.jpg differ diff --git a/docs/static/mb/blocks/lessons/snowflake-fall-3.jpg b/docs/static/mb/blocks/lessons/snowflake-fall-3.jpg new file mode 100644 index 00000000..ba103893 Binary files /dev/null and b/docs/static/mb/blocks/lessons/snowflake-fall-3.jpg differ diff --git a/docs/static/mb/blocks/lessons/snowflake-fall-4.png b/docs/static/mb/blocks/lessons/snowflake-fall-4.png new file mode 100644 index 00000000..78bcff2f Binary files /dev/null and b/docs/static/mb/blocks/lessons/snowflake-fall-4.png differ diff --git a/docs/static/mb/blocks/lessons/snowflake-fall-5.png b/docs/static/mb/blocks/lessons/snowflake-fall-5.png new file mode 100644 index 00000000..731d5f58 Binary files /dev/null and b/docs/static/mb/blocks/lessons/snowflake-fall-5.png differ diff --git a/docs/static/mb/blocks/lessons/snowflake-fall-6.png b/docs/static/mb/blocks/lessons/snowflake-fall-6.png new file mode 100644 index 00000000..cf7191cc Binary files /dev/null and b/docs/static/mb/blocks/lessons/snowflake-fall-6.png differ diff --git a/docs/static/mb/blocks/lessons/spinner-0.jpg b/docs/static/mb/blocks/lessons/spinner-0.jpg new file mode 100644 index 00000000..610c001b Binary files /dev/null and b/docs/static/mb/blocks/lessons/spinner-0.jpg differ diff --git a/docs/static/mb/blocks/lessons/spinner-1.jpg b/docs/static/mb/blocks/lessons/spinner-1.jpg new file mode 100644 index 00000000..dc33f505 Binary files /dev/null and b/docs/static/mb/blocks/lessons/spinner-1.jpg differ diff --git a/docs/static/mb/blocks/lessons/spinner-2.jpg b/docs/static/mb/blocks/lessons/spinner-2.jpg new file mode 100644 index 00000000..d22a04f0 Binary files /dev/null and b/docs/static/mb/blocks/lessons/spinner-2.jpg differ diff --git a/docs/static/mb/blocks/lessons/spinner-3.jpg b/docs/static/mb/blocks/lessons/spinner-3.jpg new file mode 100644 index 00000000..04073ea7 Binary files /dev/null and b/docs/static/mb/blocks/lessons/spinner-3.jpg differ diff --git a/docs/static/mb/blocks/lessons/spinner-4.jpg b/docs/static/mb/blocks/lessons/spinner-4.jpg new file mode 100644 index 00000000..9ef3af15 Binary files /dev/null and b/docs/static/mb/blocks/lessons/spinner-4.jpg differ diff --git a/docs/static/mb/blocks/lessons/spinner-5.jpg b/docs/static/mb/blocks/lessons/spinner-5.jpg new file mode 100644 index 00000000..e143bbdd Binary files /dev/null and b/docs/static/mb/blocks/lessons/spinner-5.jpg differ diff --git a/docs/static/mb/blocks/lessons/strobe-light-3.jpg b/docs/static/mb/blocks/lessons/strobe-light-3.jpg new file mode 100644 index 00000000..bf133694 Binary files /dev/null and b/docs/static/mb/blocks/lessons/strobe-light-3.jpg differ diff --git a/docs/static/mb/blocks/lessons/variables-0.png b/docs/static/mb/blocks/lessons/variables-0.png new file mode 100644 index 00000000..d6c398bf Binary files /dev/null and b/docs/static/mb/blocks/lessons/variables-0.png differ diff --git a/docs/static/mb/blocks/lessons/variables-1.png b/docs/static/mb/blocks/lessons/variables-1.png new file mode 100644 index 00000000..2be74cb7 Binary files /dev/null and b/docs/static/mb/blocks/lessons/variables-1.png differ diff --git a/docs/static/mb/blocks/math-0.png b/docs/static/mb/blocks/math-0.png new file mode 100644 index 00000000..16944807 Binary files /dev/null and b/docs/static/mb/blocks/math-0.png differ diff --git a/docs/static/mb/blocks/math-1.png b/docs/static/mb/blocks/math-1.png new file mode 100644 index 00000000..67ca7db5 Binary files /dev/null and b/docs/static/mb/blocks/math-1.png differ diff --git a/docs/static/mb/blocks/math-2.png b/docs/static/mb/blocks/math-2.png new file mode 100644 index 00000000..f6a11613 Binary files /dev/null and b/docs/static/mb/blocks/math-2.png differ diff --git a/docs/static/mb/blocks/math-3.png b/docs/static/mb/blocks/math-3.png new file mode 100644 index 00000000..227be03a Binary files /dev/null and b/docs/static/mb/blocks/math-3.png differ diff --git a/docs/static/mb/blocks/number-0.png b/docs/static/mb/blocks/number-0.png new file mode 100644 index 00000000..5bc93cf4 Binary files /dev/null and b/docs/static/mb/blocks/number-0.png differ diff --git a/docs/static/mb/blocks/number-1.png b/docs/static/mb/blocks/number-1.png new file mode 100644 index 00000000..7f58f462 Binary files /dev/null and b/docs/static/mb/blocks/number-1.png differ diff --git a/docs/static/mb/blocks/number-2.png b/docs/static/mb/blocks/number-2.png new file mode 100644 index 00000000..fbb99b92 Binary files /dev/null and b/docs/static/mb/blocks/number-2.png differ diff --git a/docs/static/mb/blocks/number-3.png b/docs/static/mb/blocks/number-3.png new file mode 100644 index 00000000..6cac6c4e Binary files /dev/null and b/docs/static/mb/blocks/number-3.png differ diff --git a/docs/static/mb/blocks/string-0.png b/docs/static/mb/blocks/string-0.png new file mode 100644 index 00000000..466c13ea Binary files /dev/null and b/docs/static/mb/blocks/string-0.png differ diff --git a/docs/static/mb/blocks/string-1.png b/docs/static/mb/blocks/string-1.png new file mode 100644 index 00000000..e085cc36 Binary files /dev/null and b/docs/static/mb/blocks/string-1.png differ diff --git a/docs/static/mb/blocks/string-2.png b/docs/static/mb/blocks/string-2.png new file mode 100644 index 00000000..ad2ef979 Binary files /dev/null and b/docs/static/mb/blocks/string-2.png differ diff --git a/docs/static/mb/blocks/to-td-0.png b/docs/static/mb/blocks/to-td-0.png new file mode 100644 index 00000000..6ee02a9d Binary files /dev/null and b/docs/static/mb/blocks/to-td-0.png differ diff --git a/docs/static/mb/blocks/to-td-1.png b/docs/static/mb/blocks/to-td-1.png new file mode 100644 index 00000000..6ed7e37b Binary files /dev/null and b/docs/static/mb/blocks/to-td-1.png differ diff --git a/docs/static/mb/blocks/to-td-2.png b/docs/static/mb/blocks/to-td-2.png new file mode 100644 index 00000000..0a009400 Binary files /dev/null and b/docs/static/mb/blocks/to-td-2.png differ diff --git a/docs/static/mb/blocks/to-td-3.png b/docs/static/mb/blocks/to-td-3.png new file mode 100644 index 00000000..65e511a2 Binary files /dev/null and b/docs/static/mb/blocks/to-td-3.png differ diff --git a/docs/static/mb/blocks/to-td-4.png b/docs/static/mb/blocks/to-td-4.png new file mode 100644 index 00000000..e6a69827 Binary files /dev/null and b/docs/static/mb/blocks/to-td-4.png differ diff --git a/docs/static/mb/blocks/to-td-5.png b/docs/static/mb/blocks/to-td-5.png new file mode 100644 index 00000000..c8ecf130 Binary files /dev/null and b/docs/static/mb/blocks/to-td-5.png differ diff --git a/docs/static/mb/blocks/to-td-6.png b/docs/static/mb/blocks/to-td-6.png new file mode 100644 index 00000000..4147c438 Binary files /dev/null and b/docs/static/mb/blocks/to-td-6.png differ diff --git a/docs/static/mb/blocks/var-0.png b/docs/static/mb/blocks/var-0.png new file mode 100644 index 00000000..917fce60 Binary files /dev/null and b/docs/static/mb/blocks/var-0.png differ diff --git a/docs/static/mb/blocks/var-1.png b/docs/static/mb/blocks/var-1.png new file mode 100644 index 00000000..e0cf928f Binary files /dev/null and b/docs/static/mb/blocks/var-1.png differ diff --git a/docs/static/mb/blocks/var-10.png b/docs/static/mb/blocks/var-10.png new file mode 100644 index 00000000..c25611d9 Binary files /dev/null and b/docs/static/mb/blocks/var-10.png differ diff --git a/docs/static/mb/blocks/var-2.png b/docs/static/mb/blocks/var-2.png new file mode 100644 index 00000000..a0d6ad1d Binary files /dev/null and b/docs/static/mb/blocks/var-2.png differ diff --git a/docs/static/mb/blocks/var-3.png b/docs/static/mb/blocks/var-3.png new file mode 100644 index 00000000..14b9bc23 Binary files /dev/null and b/docs/static/mb/blocks/var-3.png differ diff --git a/docs/static/mb/blocks/var-4.png b/docs/static/mb/blocks/var-4.png new file mode 100644 index 00000000..7a7c16fd Binary files /dev/null and b/docs/static/mb/blocks/var-4.png differ diff --git a/docs/static/mb/blocks/var-5.png b/docs/static/mb/blocks/var-5.png new file mode 100644 index 00000000..29c0c54f Binary files /dev/null and b/docs/static/mb/blocks/var-5.png differ diff --git a/docs/static/mb/blocks/var-6.png b/docs/static/mb/blocks/var-6.png new file mode 100644 index 00000000..787eace4 Binary files /dev/null and b/docs/static/mb/blocks/var-6.png differ diff --git a/docs/static/mb/blocks/var-7.png b/docs/static/mb/blocks/var-7.png new file mode 100644 index 00000000..da6c6cc2 Binary files /dev/null and b/docs/static/mb/blocks/var-7.png differ diff --git a/docs/static/mb/blocks/var-8.png b/docs/static/mb/blocks/var-8.png new file mode 100644 index 00000000..f6ef5515 Binary files /dev/null and b/docs/static/mb/blocks/var-8.png differ diff --git a/docs/static/mb/blocks/var-9.png b/docs/static/mb/blocks/var-9.png new file mode 100644 index 00000000..92cd8c74 Binary files /dev/null and b/docs/static/mb/blocks/var-9.png differ diff --git a/docs/static/mb/boolean-0.png b/docs/static/mb/boolean-0.png new file mode 100644 index 00000000..69283369 Binary files /dev/null and b/docs/static/mb/boolean-0.png differ diff --git a/docs/static/mb/boolean-1.png b/docs/static/mb/boolean-1.png new file mode 100644 index 00000000..4e145faa Binary files /dev/null and b/docs/static/mb/boolean-1.png differ diff --git a/docs/static/mb/boolean-2.png b/docs/static/mb/boolean-2.png new file mode 100644 index 00000000..8f940dd6 Binary files /dev/null and b/docs/static/mb/boolean-2.png differ diff --git a/docs/static/mb/button-is-pressed-0.png b/docs/static/mb/button-is-pressed-0.png new file mode 100644 index 00000000..fe7842ff Binary files /dev/null and b/docs/static/mb/button-is-pressed-0.png differ diff --git a/docs/static/mb/change-0.png b/docs/static/mb/change-0.png new file mode 100644 index 00000000..fb0d1c20 Binary files /dev/null and b/docs/static/mb/change-0.png differ diff --git a/docs/static/mb/change-score-by-0.png b/docs/static/mb/change-score-by-0.png new file mode 100644 index 00000000..69b51e2e Binary files /dev/null and b/docs/static/mb/change-score-by-0.png differ diff --git a/docs/static/mb/change-tempo-0.jpg b/docs/static/mb/change-tempo-0.jpg new file mode 100644 index 00000000..5ec9cef9 Binary files /dev/null and b/docs/static/mb/change-tempo-0.jpg differ diff --git a/docs/static/mb/change-tempo-by-0.jpg b/docs/static/mb/change-tempo-by-0.jpg new file mode 100644 index 00000000..4b807dbe Binary files /dev/null and b/docs/static/mb/change-tempo-by-0.jpg differ diff --git a/docs/static/mb/compass-heading-0.png b/docs/static/mb/compass-heading-0.png new file mode 100644 index 00000000..15801742 Binary files /dev/null and b/docs/static/mb/compass-heading-0.png differ diff --git a/docs/static/mb/create-image-0.png b/docs/static/mb/create-image-0.png new file mode 100644 index 00000000..883979d3 Binary files /dev/null and b/docs/static/mb/create-image-0.png differ diff --git a/docs/static/mb/create-sprite-0.png b/docs/static/mb/create-sprite-0.png new file mode 100644 index 00000000..94ed97b9 Binary files /dev/null and b/docs/static/mb/create-sprite-0.png differ diff --git a/docs/static/mb/crocodile-clips-0.png b/docs/static/mb/crocodile-clips-0.png new file mode 100644 index 00000000..96eb3992 Binary files /dev/null and b/docs/static/mb/crocodile-clips-0.png differ diff --git a/docs/static/mb/crocodile-clips-1.jpg b/docs/static/mb/crocodile-clips-1.jpg new file mode 100644 index 00000000..9bf243be Binary files /dev/null and b/docs/static/mb/crocodile-clips-1.jpg differ diff --git a/docs/static/mb/crocodile-clips-2.jpg b/docs/static/mb/crocodile-clips-2.jpg new file mode 100644 index 00000000..b1c6bf7f Binary files /dev/null and b/docs/static/mb/crocodile-clips-2.jpg differ diff --git a/docs/static/mb/data-0.png b/docs/static/mb/data-0.png new file mode 100644 index 00000000..b47e728c Binary files /dev/null and b/docs/static/mb/data-0.png differ diff --git a/docs/static/mb/data-1.jpg b/docs/static/mb/data-1.jpg new file mode 100644 index 00000000..927bf802 Binary files /dev/null and b/docs/static/mb/data-1.jpg differ diff --git a/docs/static/mb/data-2.jpg b/docs/static/mb/data-2.jpg new file mode 100644 index 00000000..43138405 Binary files /dev/null and b/docs/static/mb/data-2.jpg differ diff --git a/docs/static/mb/data-3.jpg b/docs/static/mb/data-3.jpg new file mode 100644 index 00000000..c207ef55 Binary files /dev/null and b/docs/static/mb/data-3.jpg differ diff --git a/docs/static/mb/data-4.png b/docs/static/mb/data-4.png new file mode 100644 index 00000000..65b07827 Binary files /dev/null and b/docs/static/mb/data-4.png differ diff --git a/docs/static/mb/device-0.png b/docs/static/mb/device-0.png new file mode 100644 index 00000000..b7c7358b Binary files /dev/null and b/docs/static/mb/device-0.png differ diff --git a/docs/static/mb/device-1.jpg b/docs/static/mb/device-1.jpg new file mode 100644 index 00000000..ae9f8ec6 Binary files /dev/null and b/docs/static/mb/device-1.jpg differ diff --git a/docs/static/mb/device/error-codes-0.png b/docs/static/mb/device/error-codes-0.png new file mode 100644 index 00000000..06057a8f Binary files /dev/null and b/docs/static/mb/device/error-codes-0.png differ diff --git a/docs/static/mb/device/pins-0.png b/docs/static/mb/device/pins-0.png new file mode 100644 index 00000000..75f8bbf7 Binary files /dev/null and b/docs/static/mb/device/pins-0.png differ diff --git a/docs/static/mb/device/reactive-0.png b/docs/static/mb/device/reactive-0.png new file mode 100644 index 00000000..ca6fdf5d Binary files /dev/null and b/docs/static/mb/device/reactive-0.png differ diff --git a/docs/static/mb/device/reactive-1.png b/docs/static/mb/device/reactive-1.png new file mode 100644 index 00000000..724cf676 Binary files /dev/null and b/docs/static/mb/device/reactive-1.png differ diff --git a/docs/static/mb/device/reactive-2.png b/docs/static/mb/device/reactive-2.png new file mode 100644 index 00000000..a3214823 Binary files /dev/null and b/docs/static/mb/device/reactive-2.png differ diff --git a/docs/static/mb/device/reactive-3.png b/docs/static/mb/device/reactive-3.png new file mode 100644 index 00000000..163122fb Binary files /dev/null and b/docs/static/mb/device/reactive-3.png differ diff --git a/docs/static/mb/device/screen-0.png b/docs/static/mb/device/screen-0.png new file mode 100644 index 00000000..43cc19bf Binary files /dev/null and b/docs/static/mb/device/screen-0.png differ diff --git a/docs/static/mb/device/usb-0.jpg b/docs/static/mb/device/usb-0.jpg new file mode 100644 index 00000000..ea3c2d68 Binary files /dev/null and b/docs/static/mb/device/usb-0.jpg differ diff --git a/docs/static/mb/device/usb-1.jpg b/docs/static/mb/device/usb-1.jpg new file mode 100644 index 00000000..600f09bf Binary files /dev/null and b/docs/static/mb/device/usb-1.jpg differ diff --git a/docs/static/mb/device/usb-10.png b/docs/static/mb/device/usb-10.png new file mode 100644 index 00000000..8837f635 Binary files /dev/null and b/docs/static/mb/device/usb-10.png differ diff --git a/docs/static/mb/device/usb-2.jpg b/docs/static/mb/device/usb-2.jpg new file mode 100644 index 00000000..b6f07a38 Binary files /dev/null and b/docs/static/mb/device/usb-2.jpg differ diff --git a/docs/static/mb/device/usb-3.jpg b/docs/static/mb/device/usb-3.jpg new file mode 100644 index 00000000..92652d28 Binary files /dev/null and b/docs/static/mb/device/usb-3.jpg differ diff --git a/docs/static/mb/device/usb-4.jpg b/docs/static/mb/device/usb-4.jpg new file mode 100644 index 00000000..865c4247 Binary files /dev/null and b/docs/static/mb/device/usb-4.jpg differ diff --git a/docs/static/mb/device/usb-5.jpg b/docs/static/mb/device/usb-5.jpg new file mode 100644 index 00000000..8f678a89 Binary files /dev/null and b/docs/static/mb/device/usb-5.jpg differ diff --git a/docs/static/mb/device/usb-6.jpg b/docs/static/mb/device/usb-6.jpg new file mode 100644 index 00000000..86a4ac21 Binary files /dev/null and b/docs/static/mb/device/usb-6.jpg differ diff --git a/docs/static/mb/device/usb-7.jpg b/docs/static/mb/device/usb-7.jpg new file mode 100644 index 00000000..1aa68bae Binary files /dev/null and b/docs/static/mb/device/usb-7.jpg differ diff --git a/docs/static/mb/device/usb-8.jpg b/docs/static/mb/device/usb-8.jpg new file mode 100644 index 00000000..a425a73f Binary files /dev/null and b/docs/static/mb/device/usb-8.jpg differ diff --git a/docs/static/mb/device/usb-9.jpg b/docs/static/mb/device/usb-9.jpg new file mode 100644 index 00000000..7d253cde Binary files /dev/null and b/docs/static/mb/device/usb-9.jpg differ diff --git a/docs/static/mb/digital-read-pin-0.png b/docs/static/mb/digital-read-pin-0.png new file mode 100644 index 00000000..ba456a0b Binary files /dev/null and b/docs/static/mb/digital-read-pin-0.png differ diff --git a/docs/static/mb/digital-write-pin-0.png b/docs/static/mb/digital-write-pin-0.png new file mode 100644 index 00000000..9f501a2c Binary files /dev/null and b/docs/static/mb/digital-write-pin-0.png differ diff --git a/docs/static/mb/empty-microbit.png b/docs/static/mb/empty-microbit.png new file mode 100644 index 00000000..18299903 Binary files /dev/null and b/docs/static/mb/empty-microbit.png differ diff --git a/docs/static/mb/events-0.png b/docs/static/mb/events-0.png new file mode 100644 index 00000000..de237200 Binary files /dev/null and b/docs/static/mb/events-0.png differ diff --git a/docs/static/mb/game-library/add-point-to-score-0.png b/docs/static/mb/game-library/add-point-to-score-0.png new file mode 100644 index 00000000..e9ac2973 Binary files /dev/null and b/docs/static/mb/game-library/add-point-to-score-0.png differ diff --git a/docs/static/mb/game-library/game-over-0.png b/docs/static/mb/game-library/game-over-0.png new file mode 100644 index 00000000..d63873bd Binary files /dev/null and b/docs/static/mb/game-library/game-over-0.png differ diff --git a/docs/static/mb/game-library/if-on-edge-bounce-0.png b/docs/static/mb/game-library/if-on-edge-bounce-0.png new file mode 100644 index 00000000..5d3f8139 Binary files /dev/null and b/docs/static/mb/game-library/if-on-edge-bounce-0.png differ diff --git a/docs/static/mb/game-library/move-0.png b/docs/static/mb/game-library/move-0.png new file mode 100644 index 00000000..32c99fd5 Binary files /dev/null and b/docs/static/mb/game-library/move-0.png differ diff --git a/docs/static/mb/game-library/pic0.png b/docs/static/mb/game-library/pic0.png new file mode 100644 index 00000000..849e72a2 Binary files /dev/null and b/docs/static/mb/game-library/pic0.png differ diff --git a/docs/static/mb/game-library/pic1.png b/docs/static/mb/game-library/pic1.png new file mode 100644 index 00000000..034e1d41 Binary files /dev/null and b/docs/static/mb/game-library/pic1.png differ diff --git a/docs/static/mb/game-library/pic2.png b/docs/static/mb/game-library/pic2.png new file mode 100644 index 00000000..3609a339 Binary files /dev/null and b/docs/static/mb/game-library/pic2.png differ diff --git a/docs/static/mb/game-library/pic3.png b/docs/static/mb/game-library/pic3.png new file mode 100644 index 00000000..5d78a089 Binary files /dev/null and b/docs/static/mb/game-library/pic3.png differ diff --git a/docs/static/mb/game-library/position-0.png b/docs/static/mb/game-library/position-0.png new file mode 100644 index 00000000..a60bc387 Binary files /dev/null and b/docs/static/mb/game-library/position-0.png differ diff --git a/docs/static/mb/game-library/reports-0.jpg b/docs/static/mb/game-library/reports-0.jpg new file mode 100644 index 00000000..dbb0f52f Binary files /dev/null and b/docs/static/mb/game-library/reports-0.jpg differ diff --git a/docs/static/mb/game-library/reports-1.jpg b/docs/static/mb/game-library/reports-1.jpg new file mode 100644 index 00000000..74be2848 Binary files /dev/null and b/docs/static/mb/game-library/reports-1.jpg differ diff --git a/docs/static/mb/game-library/reports-2.jpg b/docs/static/mb/game-library/reports-2.jpg new file mode 100644 index 00000000..41b88d1f Binary files /dev/null and b/docs/static/mb/game-library/reports-2.jpg differ diff --git a/docs/static/mb/game-library/start-countdown-0.png b/docs/static/mb/game-library/start-countdown-0.png new file mode 100644 index 00000000..e214070c Binary files /dev/null and b/docs/static/mb/game-library/start-countdown-0.png differ diff --git a/docs/static/mb/game-library/touching-0.png b/docs/static/mb/game-library/touching-0.png new file mode 100644 index 00000000..db48069b Binary files /dev/null and b/docs/static/mb/game-library/touching-0.png differ diff --git a/docs/static/mb/game-library/touching-edge-0.png b/docs/static/mb/game-library/touching-edge-0.png new file mode 100644 index 00000000..69a38091 Binary files /dev/null and b/docs/static/mb/game-library/touching-edge-0.png differ diff --git a/docs/static/mb/game-library/turn-0.png b/docs/static/mb/game-library/turn-0.png new file mode 100644 index 00000000..4ee0c1f0 Binary files /dev/null and b/docs/static/mb/game-library/turn-0.png differ diff --git a/docs/static/mb/hourofcode-0.png b/docs/static/mb/hourofcode-0.png new file mode 100644 index 00000000..da13914c Binary files /dev/null and b/docs/static/mb/hourofcode-0.png differ diff --git a/docs/static/mb/image-0.png b/docs/static/mb/image-0.png new file mode 100644 index 00000000..07759140 Binary files /dev/null and b/docs/static/mb/image-0.png differ diff --git a/docs/static/mb/lessons/answering-machine-0.png b/docs/static/mb/lessons/answering-machine-0.png new file mode 100644 index 00000000..d29260a0 Binary files /dev/null and b/docs/static/mb/lessons/answering-machine-0.png differ diff --git a/docs/static/mb/lessons/answering-machine-1.png b/docs/static/mb/lessons/answering-machine-1.png new file mode 100644 index 00000000..10c8f632 Binary files /dev/null and b/docs/static/mb/lessons/answering-machine-1.png differ diff --git a/docs/static/mb/lessons/answering-machine-2.png b/docs/static/mb/lessons/answering-machine-2.png new file mode 100644 index 00000000..30a82735 Binary files /dev/null and b/docs/static/mb/lessons/answering-machine-2.png differ diff --git a/docs/static/mb/lessons/answering-machine-4.png b/docs/static/mb/lessons/answering-machine-4.png new file mode 100644 index 00000000..15fa4c34 Binary files /dev/null and b/docs/static/mb/lessons/answering-machine-4.png differ diff --git a/docs/static/mb/lessons/answering-machine-5.png b/docs/static/mb/lessons/answering-machine-5.png new file mode 100644 index 00000000..5024e8da Binary files /dev/null and b/docs/static/mb/lessons/answering-machine-5.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-0.png b/docs/static/mb/lessons/banana-keyboard-0.png new file mode 100644 index 00000000..2cfe50af Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-0.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-1.png b/docs/static/mb/lessons/banana-keyboard-1.png new file mode 100644 index 00000000..9ddb8832 Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-1.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-10.png b/docs/static/mb/lessons/banana-keyboard-10.png new file mode 100644 index 00000000..9766040a Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-10.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-11.png b/docs/static/mb/lessons/banana-keyboard-11.png new file mode 100644 index 00000000..bb6ae2cd Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-11.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-12.png b/docs/static/mb/lessons/banana-keyboard-12.png new file mode 100644 index 00000000..05e1e80e Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-12.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-2.png b/docs/static/mb/lessons/banana-keyboard-2.png new file mode 100644 index 00000000..e3983d0b Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-2.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-3.png b/docs/static/mb/lessons/banana-keyboard-3.png new file mode 100644 index 00000000..4c261f3b Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-3.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-4.png b/docs/static/mb/lessons/banana-keyboard-4.png new file mode 100644 index 00000000..c1be8631 Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-4.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-5.png b/docs/static/mb/lessons/banana-keyboard-5.png new file mode 100644 index 00000000..c20ea3b3 Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-5.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-6.png b/docs/static/mb/lessons/banana-keyboard-6.png new file mode 100644 index 00000000..f5edaeed Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-6.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-7.png b/docs/static/mb/lessons/banana-keyboard-7.png new file mode 100644 index 00000000..54793044 Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-7.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-8.png b/docs/static/mb/lessons/banana-keyboard-8.png new file mode 100644 index 00000000..14739ed6 Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-8.png differ diff --git a/docs/static/mb/lessons/banana-keyboard-9.png b/docs/static/mb/lessons/banana-keyboard-9.png new file mode 100644 index 00000000..ba760b3e Binary files /dev/null and b/docs/static/mb/lessons/banana-keyboard-9.png differ diff --git a/docs/static/mb/lessons/blink-0.png b/docs/static/mb/lessons/blink-0.png new file mode 100644 index 00000000..4e1c4aeb Binary files /dev/null and b/docs/static/mb/lessons/blink-0.png differ diff --git a/docs/static/mb/lessons/blink-1.png b/docs/static/mb/lessons/blink-1.png new file mode 100644 index 00000000..1639a3fd Binary files /dev/null and b/docs/static/mb/lessons/blink-1.png differ diff --git a/docs/static/mb/lessons/blink-2.png b/docs/static/mb/lessons/blink-2.png new file mode 100644 index 00000000..b0222961 Binary files /dev/null and b/docs/static/mb/lessons/blink-2.png differ diff --git a/docs/static/mb/lessons/bounce-image-0.png b/docs/static/mb/lessons/bounce-image-0.png new file mode 100644 index 00000000..88589000 Binary files /dev/null and b/docs/static/mb/lessons/bounce-image-0.png differ diff --git a/docs/static/mb/lessons/bounce-image-1.png b/docs/static/mb/lessons/bounce-image-1.png new file mode 100644 index 00000000..5fde403a Binary files /dev/null and b/docs/static/mb/lessons/bounce-image-1.png differ diff --git a/docs/static/mb/lessons/bounce-image-2.png b/docs/static/mb/lessons/bounce-image-2.png new file mode 100644 index 00000000..e9034f0e Binary files /dev/null and b/docs/static/mb/lessons/bounce-image-2.png differ diff --git a/docs/static/mb/lessons/cascade-0.png b/docs/static/mb/lessons/cascade-0.png new file mode 100644 index 00000000..acb60348 Binary files /dev/null and b/docs/static/mb/lessons/cascade-0.png differ diff --git a/docs/static/mb/lessons/cascade-1.png b/docs/static/mb/lessons/cascade-1.png new file mode 100644 index 00000000..0f8fb9e5 Binary files /dev/null and b/docs/static/mb/lessons/cascade-1.png differ diff --git a/docs/static/mb/lessons/cascade-2.png b/docs/static/mb/lessons/cascade-2.png new file mode 100644 index 00000000..ea8f5b14 Binary files /dev/null and b/docs/static/mb/lessons/cascade-2.png differ diff --git a/docs/static/mb/lessons/catch-the-egg-game-0.png b/docs/static/mb/lessons/catch-the-egg-game-0.png new file mode 100644 index 00000000..54129445 Binary files /dev/null and b/docs/static/mb/lessons/catch-the-egg-game-0.png differ diff --git a/docs/static/mb/lessons/column-0.png b/docs/static/mb/lessons/column-0.png new file mode 100644 index 00000000..3730593f Binary files /dev/null and b/docs/static/mb/lessons/column-0.png differ diff --git a/docs/static/mb/lessons/column-1.png b/docs/static/mb/lessons/column-1.png new file mode 100644 index 00000000..027b7d00 Binary files /dev/null and b/docs/static/mb/lessons/column-1.png differ diff --git a/docs/static/mb/lessons/counter-0.png b/docs/static/mb/lessons/counter-0.png new file mode 100644 index 00000000..c2abb0f6 Binary files /dev/null and b/docs/static/mb/lessons/counter-0.png differ diff --git a/docs/static/mb/lessons/counter-1.png b/docs/static/mb/lessons/counter-1.png new file mode 100644 index 00000000..29448958 Binary files /dev/null and b/docs/static/mb/lessons/counter-1.png differ diff --git a/docs/static/mb/lessons/counter-2.png b/docs/static/mb/lessons/counter-2.png new file mode 100644 index 00000000..b924b9fd Binary files /dev/null and b/docs/static/mb/lessons/counter-2.png differ diff --git a/docs/static/mb/lessons/die-roll-0.png b/docs/static/mb/lessons/die-roll-0.png new file mode 100644 index 00000000..472d18bb Binary files /dev/null and b/docs/static/mb/lessons/die-roll-0.png differ diff --git a/docs/static/mb/lessons/die-roll-1.png b/docs/static/mb/lessons/die-roll-1.png new file mode 100644 index 00000000..532bd452 Binary files /dev/null and b/docs/static/mb/lessons/die-roll-1.png differ diff --git a/docs/static/mb/lessons/die-roll-2.png b/docs/static/mb/lessons/die-roll-2.png new file mode 100644 index 00000000..f6594952 Binary files /dev/null and b/docs/static/mb/lessons/die-roll-2.png differ diff --git a/docs/static/mb/lessons/die-roll-3.png b/docs/static/mb/lessons/die-roll-3.png new file mode 100644 index 00000000..1e582cac Binary files /dev/null and b/docs/static/mb/lessons/die-roll-3.png differ diff --git a/docs/static/mb/lessons/digi-yoyo-0.png b/docs/static/mb/lessons/digi-yoyo-0.png new file mode 100644 index 00000000..917ce0e7 Binary files /dev/null and b/docs/static/mb/lessons/digi-yoyo-0.png differ diff --git a/docs/static/mb/lessons/flashing-heart-0.png b/docs/static/mb/lessons/flashing-heart-0.png new file mode 100644 index 00000000..a8e04a87 Binary files /dev/null and b/docs/static/mb/lessons/flashing-heart-0.png differ diff --git a/docs/static/mb/lessons/flipping-bird-0.png b/docs/static/mb/lessons/flipping-bird-0.png new file mode 100644 index 00000000..a28b2ea6 Binary files /dev/null and b/docs/static/mb/lessons/flipping-bird-0.png differ diff --git a/docs/static/mb/lessons/flipping-bird-1.png b/docs/static/mb/lessons/flipping-bird-1.png new file mode 100644 index 00000000..44abf050 Binary files /dev/null and b/docs/static/mb/lessons/flipping-bird-1.png differ diff --git a/docs/static/mb/lessons/glowing-pendulum-0.jpg b/docs/static/mb/lessons/glowing-pendulum-0.jpg new file mode 100644 index 00000000..b5ad4ee4 Binary files /dev/null and b/docs/static/mb/lessons/glowing-pendulum-0.jpg differ diff --git a/docs/static/mb/lessons/glowing-pendulum-1.png b/docs/static/mb/lessons/glowing-pendulum-1.png new file mode 100644 index 00000000..fc30a4df Binary files /dev/null and b/docs/static/mb/lessons/glowing-pendulum-1.png differ diff --git a/docs/static/mb/lessons/guess-the-number-0.png b/docs/static/mb/lessons/guess-the-number-0.png new file mode 100644 index 00000000..af3ff1d0 Binary files /dev/null and b/docs/static/mb/lessons/guess-the-number-0.png differ diff --git a/docs/static/mb/lessons/hack-your-headphones-0.png b/docs/static/mb/lessons/hack-your-headphones-0.png new file mode 100644 index 00000000..ba58df5a Binary files /dev/null and b/docs/static/mb/lessons/hack-your-headphones-0.png differ diff --git a/docs/static/mb/lessons/hack-your-headphones-1.png b/docs/static/mb/lessons/hack-your-headphones-1.png new file mode 100644 index 00000000..42a68449 Binary files /dev/null and b/docs/static/mb/lessons/hack-your-headphones-1.png differ diff --git a/docs/static/mb/lessons/looper-0.png b/docs/static/mb/lessons/looper-0.png new file mode 100644 index 00000000..eaf37d0d Binary files /dev/null and b/docs/static/mb/lessons/looper-0.png differ diff --git a/docs/static/mb/lessons/looper-1.png b/docs/static/mb/lessons/looper-1.png new file mode 100644 index 00000000..4c832c21 Binary files /dev/null and b/docs/static/mb/lessons/looper-1.png differ diff --git a/docs/static/mb/lessons/looper-2.png b/docs/static/mb/lessons/looper-2.png new file mode 100644 index 00000000..3ae90577 Binary files /dev/null and b/docs/static/mb/lessons/looper-2.png differ diff --git a/docs/static/mb/lessons/looper-3.png b/docs/static/mb/lessons/looper-3.png new file mode 100644 index 00000000..701c0d3e Binary files /dev/null and b/docs/static/mb/lessons/looper-3.png differ diff --git a/docs/static/mb/lessons/lucky-7-0.png b/docs/static/mb/lessons/lucky-7-0.png new file mode 100644 index 00000000..e9c20c68 Binary files /dev/null and b/docs/static/mb/lessons/lucky-7-0.png differ diff --git a/docs/static/mb/lessons/lucky-7-1.png b/docs/static/mb/lessons/lucky-7-1.png new file mode 100644 index 00000000..05ed459f Binary files /dev/null and b/docs/static/mb/lessons/lucky-7-1.png differ diff --git a/docs/static/mb/lessons/lucky-7-2.png b/docs/static/mb/lessons/lucky-7-2.png new file mode 100644 index 00000000..51bd9d80 Binary files /dev/null and b/docs/static/mb/lessons/lucky-7-2.png differ diff --git a/docs/static/mb/lessons/lucky-7-3.png b/docs/static/mb/lessons/lucky-7-3.png new file mode 100644 index 00000000..609e1895 Binary files /dev/null and b/docs/static/mb/lessons/lucky-7-3.png differ diff --git a/docs/static/mb/lessons/magic-logo-0.png b/docs/static/mb/lessons/magic-logo-0.png new file mode 100644 index 00000000..67bb4841 Binary files /dev/null and b/docs/static/mb/lessons/magic-logo-0.png differ diff --git a/docs/static/mb/lessons/night-light-0.png b/docs/static/mb/lessons/night-light-0.png new file mode 100644 index 00000000..8803fb65 Binary files /dev/null and b/docs/static/mb/lessons/night-light-0.png differ diff --git a/docs/static/mb/lessons/night-light-1.png b/docs/static/mb/lessons/night-light-1.png new file mode 100644 index 00000000..348e0382 Binary files /dev/null and b/docs/static/mb/lessons/night-light-1.png differ diff --git a/docs/static/mb/lessons/night-light-2.png b/docs/static/mb/lessons/night-light-2.png new file mode 100644 index 00000000..18299903 Binary files /dev/null and b/docs/static/mb/lessons/night-light-2.png differ diff --git a/docs/static/mb/lessons/offset-image-0.png b/docs/static/mb/lessons/offset-image-0.png new file mode 100644 index 00000000..ba2a9afe Binary files /dev/null and b/docs/static/mb/lessons/offset-image-0.png differ diff --git a/docs/static/mb/lessons/offset-image-1.png b/docs/static/mb/lessons/offset-image-1.png new file mode 100644 index 00000000..9c1827b8 Binary files /dev/null and b/docs/static/mb/lessons/offset-image-1.png differ diff --git a/docs/static/mb/lessons/ornament-chain-0.jpg b/docs/static/mb/lessons/ornament-chain-0.jpg new file mode 100644 index 00000000..45b7a1d5 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-0.jpg differ diff --git a/docs/static/mb/lessons/ornament-chain-1.jpg b/docs/static/mb/lessons/ornament-chain-1.jpg new file mode 100644 index 00000000..dd9242cf Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-1.jpg differ diff --git a/docs/static/mb/lessons/ornament-chain-2.png b/docs/static/mb/lessons/ornament-chain-2.png new file mode 100644 index 00000000..07ce9637 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-2.png differ diff --git a/docs/static/mb/lessons/ornament-chain-3.png b/docs/static/mb/lessons/ornament-chain-3.png new file mode 100644 index 00000000..fe2ed067 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-3.png differ diff --git a/docs/static/mb/lessons/ornament-chain-4.png b/docs/static/mb/lessons/ornament-chain-4.png new file mode 100644 index 00000000..fb4d9882 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-4.png differ diff --git a/docs/static/mb/lessons/ornament-chain-5.png b/docs/static/mb/lessons/ornament-chain-5.png new file mode 100644 index 00000000..0c9e6123 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-5.png differ diff --git a/docs/static/mb/lessons/ornament-chain-6.png b/docs/static/mb/lessons/ornament-chain-6.png new file mode 100644 index 00000000..24d1442c Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-6.png differ diff --git a/docs/static/mb/lessons/ornament-chain-7.png b/docs/static/mb/lessons/ornament-chain-7.png new file mode 100644 index 00000000..3fe94170 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-7.png differ diff --git a/docs/static/mb/lessons/ornament-chain-8.png b/docs/static/mb/lessons/ornament-chain-8.png new file mode 100644 index 00000000..b8537355 Binary files /dev/null and b/docs/static/mb/lessons/ornament-chain-8.png differ diff --git a/docs/static/mb/lessons/prank-wifi-0.png b/docs/static/mb/lessons/prank-wifi-0.png new file mode 100644 index 00000000..dbdbe244 Binary files /dev/null and b/docs/static/mb/lessons/prank-wifi-0.png differ diff --git a/docs/static/mb/lessons/rotation-animation-0.png b/docs/static/mb/lessons/rotation-animation-0.png new file mode 100644 index 00000000..96352e44 Binary files /dev/null and b/docs/static/mb/lessons/rotation-animation-0.png differ diff --git a/docs/static/mb/lessons/rotation-animation-1.png b/docs/static/mb/lessons/rotation-animation-1.png new file mode 100644 index 00000000..ba98236a Binary files /dev/null and b/docs/static/mb/lessons/rotation-animation-1.png differ diff --git a/docs/static/mb/lessons/rotation-animation-2.png b/docs/static/mb/lessons/rotation-animation-2.png new file mode 100644 index 00000000..3953500c Binary files /dev/null and b/docs/static/mb/lessons/rotation-animation-2.png differ diff --git a/docs/static/mb/lessons/rotation-animation-3.png b/docs/static/mb/lessons/rotation-animation-3.png new file mode 100644 index 00000000..488b3b02 Binary files /dev/null and b/docs/static/mb/lessons/rotation-animation-3.png differ diff --git a/docs/static/mb/lessons/screen-wipe-0.png b/docs/static/mb/lessons/screen-wipe-0.png new file mode 100644 index 00000000..a1f7855c Binary files /dev/null and b/docs/static/mb/lessons/screen-wipe-0.png differ diff --git a/docs/static/mb/lessons/smiley-0.png b/docs/static/mb/lessons/smiley-0.png new file mode 100644 index 00000000..b2c5452f Binary files /dev/null and b/docs/static/mb/lessons/smiley-0.png differ diff --git a/docs/static/mb/lessons/snowflake-fall-0.png b/docs/static/mb/lessons/snowflake-fall-0.png new file mode 100644 index 00000000..9c295dee Binary files /dev/null and b/docs/static/mb/lessons/snowflake-fall-0.png differ diff --git a/docs/static/mb/lessons/snowflake-fall-1.png b/docs/static/mb/lessons/snowflake-fall-1.png new file mode 100644 index 00000000..92467302 Binary files /dev/null and b/docs/static/mb/lessons/snowflake-fall-1.png differ diff --git a/docs/static/mb/lessons/snowflake-fall-2.png b/docs/static/mb/lessons/snowflake-fall-2.png new file mode 100644 index 00000000..005c2da5 Binary files /dev/null and b/docs/static/mb/lessons/snowflake-fall-2.png differ diff --git a/docs/static/mb/lessons/speed-button-0.png b/docs/static/mb/lessons/speed-button-0.png new file mode 100644 index 00000000..b98310ba Binary files /dev/null and b/docs/static/mb/lessons/speed-button-0.png differ diff --git a/docs/static/mb/lessons/speed-button-1.png b/docs/static/mb/lessons/speed-button-1.png new file mode 100644 index 00000000..44abf050 Binary files /dev/null and b/docs/static/mb/lessons/speed-button-1.png differ diff --git a/docs/static/mb/lessons/speed-button-2.png b/docs/static/mb/lessons/speed-button-2.png new file mode 100644 index 00000000..b00ec1eb Binary files /dev/null and b/docs/static/mb/lessons/speed-button-2.png differ diff --git a/docs/static/mb/lessons/spinner-0.png b/docs/static/mb/lessons/spinner-0.png new file mode 100644 index 00000000..9c0b9390 Binary files /dev/null and b/docs/static/mb/lessons/spinner-0.png differ diff --git a/docs/static/mb/lessons/spinner-1.png b/docs/static/mb/lessons/spinner-1.png new file mode 100644 index 00000000..17c121d3 Binary files /dev/null and b/docs/static/mb/lessons/spinner-1.png differ diff --git a/docs/static/mb/lessons/telegraph-0.png b/docs/static/mb/lessons/telegraph-0.png new file mode 100644 index 00000000..d5ebfdc5 Binary files /dev/null and b/docs/static/mb/lessons/telegraph-0.png differ diff --git a/docs/static/mb/lessons/the-watch-0.png b/docs/static/mb/lessons/the-watch-0.png new file mode 100644 index 00000000..062523d5 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-0.png differ diff --git a/docs/static/mb/lessons/the-watch-1.png b/docs/static/mb/lessons/the-watch-1.png new file mode 100644 index 00000000..d017662f Binary files /dev/null and b/docs/static/mb/lessons/the-watch-1.png differ diff --git a/docs/static/mb/lessons/the-watch-10.png b/docs/static/mb/lessons/the-watch-10.png new file mode 100644 index 00000000..c61ca460 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-10.png differ diff --git a/docs/static/mb/lessons/the-watch-11.png b/docs/static/mb/lessons/the-watch-11.png new file mode 100644 index 00000000..d5abf506 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-11.png differ diff --git a/docs/static/mb/lessons/the-watch-12.png b/docs/static/mb/lessons/the-watch-12.png new file mode 100644 index 00000000..a62b9c95 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-12.png differ diff --git a/docs/static/mb/lessons/the-watch-13.png b/docs/static/mb/lessons/the-watch-13.png new file mode 100644 index 00000000..719a3c65 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-13.png differ diff --git a/docs/static/mb/lessons/the-watch-14.png b/docs/static/mb/lessons/the-watch-14.png new file mode 100644 index 00000000..b8996eae Binary files /dev/null and b/docs/static/mb/lessons/the-watch-14.png differ diff --git a/docs/static/mb/lessons/the-watch-15.png b/docs/static/mb/lessons/the-watch-15.png new file mode 100644 index 00000000..96d036ec Binary files /dev/null and b/docs/static/mb/lessons/the-watch-15.png differ diff --git a/docs/static/mb/lessons/the-watch-16.png b/docs/static/mb/lessons/the-watch-16.png new file mode 100644 index 00000000..2803b3b7 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-16.png differ diff --git a/docs/static/mb/lessons/the-watch-17.png b/docs/static/mb/lessons/the-watch-17.png new file mode 100644 index 00000000..cf8859e3 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-17.png differ diff --git a/docs/static/mb/lessons/the-watch-18.png b/docs/static/mb/lessons/the-watch-18.png new file mode 100644 index 00000000..fe0fd19f Binary files /dev/null and b/docs/static/mb/lessons/the-watch-18.png differ diff --git a/docs/static/mb/lessons/the-watch-19.png b/docs/static/mb/lessons/the-watch-19.png new file mode 100644 index 00000000..7469c484 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-19.png differ diff --git a/docs/static/mb/lessons/the-watch-2.png b/docs/static/mb/lessons/the-watch-2.png new file mode 100644 index 00000000..bcc28694 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-2.png differ diff --git a/docs/static/mb/lessons/the-watch-20.png b/docs/static/mb/lessons/the-watch-20.png new file mode 100644 index 00000000..9d25b72d Binary files /dev/null and b/docs/static/mb/lessons/the-watch-20.png differ diff --git a/docs/static/mb/lessons/the-watch-21.png b/docs/static/mb/lessons/the-watch-21.png new file mode 100644 index 00000000..e241b25f Binary files /dev/null and b/docs/static/mb/lessons/the-watch-21.png differ diff --git a/docs/static/mb/lessons/the-watch-22.png b/docs/static/mb/lessons/the-watch-22.png new file mode 100644 index 00000000..a9e28360 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-22.png differ diff --git a/docs/static/mb/lessons/the-watch-23.png b/docs/static/mb/lessons/the-watch-23.png new file mode 100644 index 00000000..3f216284 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-23.png differ diff --git a/docs/static/mb/lessons/the-watch-3.png b/docs/static/mb/lessons/the-watch-3.png new file mode 100644 index 00000000..f8072ef2 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-3.png differ diff --git a/docs/static/mb/lessons/the-watch-4.png b/docs/static/mb/lessons/the-watch-4.png new file mode 100644 index 00000000..ddbd4ef4 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-4.png differ diff --git a/docs/static/mb/lessons/the-watch-5.png b/docs/static/mb/lessons/the-watch-5.png new file mode 100644 index 00000000..a59970fc Binary files /dev/null and b/docs/static/mb/lessons/the-watch-5.png differ diff --git a/docs/static/mb/lessons/the-watch-6.png b/docs/static/mb/lessons/the-watch-6.png new file mode 100644 index 00000000..dbf98e35 Binary files /dev/null and b/docs/static/mb/lessons/the-watch-6.png differ diff --git a/docs/static/mb/lessons/the-watch-7.png b/docs/static/mb/lessons/the-watch-7.png new file mode 100644 index 00000000..3ef7ec9a Binary files /dev/null and b/docs/static/mb/lessons/the-watch-7.png differ diff --git a/docs/static/mb/lessons/the-watch-8.png b/docs/static/mb/lessons/the-watch-8.png new file mode 100644 index 00000000..cec7104d Binary files /dev/null and b/docs/static/mb/lessons/the-watch-8.png differ diff --git a/docs/static/mb/lessons/the-watch-9.png b/docs/static/mb/lessons/the-watch-9.png new file mode 100644 index 00000000..44aa930e Binary files /dev/null and b/docs/static/mb/lessons/the-watch-9.png differ diff --git a/docs/static/mb/lessons/truth-or-dare-0.png b/docs/static/mb/lessons/truth-or-dare-0.png new file mode 100644 index 00000000..7a01002a Binary files /dev/null and b/docs/static/mb/lessons/truth-or-dare-0.png differ diff --git a/docs/static/mb/magnetic-force-0.png b/docs/static/mb/magnetic-force-0.png new file mode 100644 index 00000000..3da48663 Binary files /dev/null and b/docs/static/mb/magnetic-force-0.png differ diff --git a/docs/static/mb/map-0.png b/docs/static/mb/map-0.png new file mode 100644 index 00000000..cd01ada6 Binary files /dev/null and b/docs/static/mb/map-0.png differ diff --git a/docs/static/mb/object-disclaimer-0.png b/docs/static/mb/object-disclaimer-0.png new file mode 100644 index 00000000..88e79e7f Binary files /dev/null and b/docs/static/mb/object-disclaimer-0.png differ diff --git a/docs/static/mb/object-types-0.png b/docs/static/mb/object-types-0.png new file mode 100644 index 00000000..42f9eceb Binary files /dev/null and b/docs/static/mb/object-types-0.png differ diff --git a/docs/static/mb/object-types-1.png b/docs/static/mb/object-types-1.png new file mode 100644 index 00000000..b740edc2 Binary files /dev/null and b/docs/static/mb/object-types-1.png differ diff --git a/docs/static/mb/offline-0.png b/docs/static/mb/offline-0.png new file mode 100644 index 00000000..47db39d4 Binary files /dev/null and b/docs/static/mb/offline-0.png differ diff --git a/docs/static/mb/offline-1.png b/docs/static/mb/offline-1.png new file mode 100644 index 00000000..e0eb9852 Binary files /dev/null and b/docs/static/mb/offline-1.png differ diff --git a/docs/static/mb/offline-2.png b/docs/static/mb/offline-2.png new file mode 100644 index 00000000..e5a18bda Binary files /dev/null and b/docs/static/mb/offline-2.png differ diff --git a/docs/static/mb/on-gamepad-button-0.png b/docs/static/mb/on-gamepad-button-0.png new file mode 100644 index 00000000..b91e67c1 Binary files /dev/null and b/docs/static/mb/on-gamepad-button-0.png differ diff --git a/docs/static/mb/on-logo-down-0.jpg b/docs/static/mb/on-logo-down-0.jpg new file mode 100644 index 00000000..19ac69cb Binary files /dev/null and b/docs/static/mb/on-logo-down-0.jpg differ diff --git a/docs/static/mb/on-logo-up-0.jpg b/docs/static/mb/on-logo-up-0.jpg new file mode 100644 index 00000000..4835d116 Binary files /dev/null and b/docs/static/mb/on-logo-up-0.jpg differ diff --git a/docs/static/mb/on-notified-0.png b/docs/static/mb/on-notified-0.png new file mode 100644 index 00000000..c2fd701a Binary files /dev/null and b/docs/static/mb/on-notified-0.png differ diff --git a/docs/static/mb/on-screen-down-0.jpg b/docs/static/mb/on-screen-down-0.jpg new file mode 100644 index 00000000..e427aa8f Binary files /dev/null and b/docs/static/mb/on-screen-down-0.jpg differ diff --git a/docs/static/mb/on-screen-up-0.jpg b/docs/static/mb/on-screen-up-0.jpg new file mode 100644 index 00000000..0c4de525 Binary files /dev/null and b/docs/static/mb/on-screen-up-0.jpg differ diff --git a/docs/static/mb/on-signal-strength-changed-0.png b/docs/static/mb/on-signal-strength-changed-0.png new file mode 100644 index 00000000..6f63179b Binary files /dev/null and b/docs/static/mb/on-signal-strength-changed-0.png differ diff --git a/docs/static/mb/play-tone-0.jpg b/docs/static/mb/play-tone-0.jpg new file mode 100644 index 00000000..b7a0ba01 Binary files /dev/null and b/docs/static/mb/play-tone-0.jpg differ diff --git a/docs/static/mb/plot-leds-0.png b/docs/static/mb/plot-leds-0.png new file mode 100644 index 00000000..a46924b1 Binary files /dev/null and b/docs/static/mb/plot-leds-0.png differ diff --git a/docs/static/mb/quick-start-0.png b/docs/static/mb/quick-start-0.png new file mode 100644 index 00000000..223a9cec Binary files /dev/null and b/docs/static/mb/quick-start-0.png differ diff --git a/docs/static/mb/raise-alert-to-0.png b/docs/static/mb/raise-alert-to-0.png new file mode 100644 index 00000000..523238f9 Binary files /dev/null and b/docs/static/mb/raise-alert-to-0.png differ diff --git a/docs/static/mb/receive-number-0.png b/docs/static/mb/receive-number-0.png new file mode 100644 index 00000000..1d93af01 Binary files /dev/null and b/docs/static/mb/receive-number-0.png differ diff --git a/docs/static/mb/rest-0.jpg b/docs/static/mb/rest-0.jpg new file mode 100644 index 00000000..9f5e8be2 Binary files /dev/null and b/docs/static/mb/rest-0.jpg differ diff --git a/docs/static/mb/ring-tone-0.jpg b/docs/static/mb/ring-tone-0.jpg new file mode 100644 index 00000000..0c9d4c31 Binary files /dev/null and b/docs/static/mb/ring-tone-0.jpg differ diff --git a/docs/static/mb/rotation-0.png b/docs/static/mb/rotation-0.png new file mode 100644 index 00000000..c65d8025 Binary files /dev/null and b/docs/static/mb/rotation-0.png differ diff --git a/docs/static/mb/running-time-0.png b/docs/static/mb/running-time-0.png new file mode 100644 index 00000000..19e1ba86 Binary files /dev/null and b/docs/static/mb/running-time-0.png differ diff --git a/docs/static/mb/scroll-image-0.png b/docs/static/mb/scroll-image-0.png new file mode 100644 index 00000000..ae2903b3 Binary files /dev/null and b/docs/static/mb/scroll-image-0.png differ diff --git a/docs/static/mb/serial-library-0.png b/docs/static/mb/serial-library-0.png new file mode 100644 index 00000000..c00882ab Binary files /dev/null and b/docs/static/mb/serial-library-0.png differ diff --git a/docs/static/mb/serial-library-1.png b/docs/static/mb/serial-library-1.png new file mode 100644 index 00000000..86cc6596 Binary files /dev/null and b/docs/static/mb/serial-library-1.png differ diff --git a/docs/static/mb/servo-set-pulse-0.png b/docs/static/mb/servo-set-pulse-0.png new file mode 100644 index 00000000..eb225391 Binary files /dev/null and b/docs/static/mb/servo-set-pulse-0.png differ diff --git a/docs/static/mb/servo-write-pin-0.png b/docs/static/mb/servo-write-pin-0.png new file mode 100644 index 00000000..31eb083a Binary files /dev/null and b/docs/static/mb/servo-write-pin-0.png differ diff --git a/docs/static/mb/show-image-0.png b/docs/static/mb/show-image-0.png new file mode 100644 index 00000000..a13abe9d Binary files /dev/null and b/docs/static/mb/show-image-0.png differ diff --git a/docs/static/mb/show-leds-1.png b/docs/static/mb/show-leds-1.png new file mode 100644 index 00000000..f8ba3c12 Binary files /dev/null and b/docs/static/mb/show-leds-1.png differ diff --git a/docs/static/mb/signal-strength-0.png b/docs/static/mb/signal-strength-0.png new file mode 100644 index 00000000..4c870c32 Binary files /dev/null and b/docs/static/mb/signal-strength-0.png differ diff --git a/docs/static/mb/simulator-0.png b/docs/static/mb/simulator-0.png new file mode 100644 index 00000000..87348b3c Binary files /dev/null and b/docs/static/mb/simulator-0.png differ diff --git a/docs/static/mb/string-0.png b/docs/static/mb/string-0.png new file mode 100644 index 00000000..6efcb95e Binary files /dev/null and b/docs/static/mb/string-0.png differ diff --git a/docs/static/mb/tell-camera-to-0.png b/docs/static/mb/tell-camera-to-0.png new file mode 100644 index 00000000..a66fd0fa Binary files /dev/null and b/docs/static/mb/tell-camera-to-0.png differ diff --git a/docs/static/mb/tell-microphone-to-0.png b/docs/static/mb/tell-microphone-to-0.png new file mode 100644 index 00000000..7222262f Binary files /dev/null and b/docs/static/mb/tell-microphone-to-0.png differ diff --git a/docs/static/mb/tell-remote-control-to-0.png b/docs/static/mb/tell-remote-control-to-0.png new file mode 100644 index 00000000..597bc14e Binary files /dev/null and b/docs/static/mb/tell-remote-control-to-0.png differ diff --git a/docs/static/mb/temperature-0.png b/docs/static/mb/temperature-0.png new file mode 100644 index 00000000..4ea69568 Binary files /dev/null and b/docs/static/mb/temperature-0.png differ diff --git a/docs/static/mb/tempo-0.jpg b/docs/static/mb/tempo-0.jpg new file mode 100644 index 00000000..dc577d54 Binary files /dev/null and b/docs/static/mb/tempo-0.jpg differ diff --git a/docs/static/mb/toggle-all-0.png b/docs/static/mb/toggle-all-0.png new file mode 100644 index 00000000..811a3e95 Binary files /dev/null and b/docs/static/mb/toggle-all-0.png differ