diff --git a/docs/blocks/math.md b/docs/blocks/math.md index ba1610f7..5d519004 100644 --- a/docs/blocks/math.md +++ b/docs/blocks/math.md @@ -1,37 +1,36 @@ # Math -[Numeric](/reference/types/number) values: 0, 1, 2, ... +### [Numeric](/reference/types/number) values: 0, 1, 2, ... -```blocks +```block 0; 1; 2; ``` -Arithmetic binary operation (+, -, *, /) +### Arithmetic binary operation (+, -, *, /) -```blocks +```block 0+1; 0-1; 1*2; 3/4; ``` -Absolute value +### Absolute value -```blocks +```block Math.abs(-5); ``` -Minimum/maximum of two values +### Minimum/maximum of two values -```blocks +```block Math.min(0, 1); -Math.max(0, 1); ``` -Random value +### Random value -```blocks +```block Math.random(5); ``` diff --git a/docs/blocks/math/math.md b/docs/blocks/math/math.md deleted file mode 100644 index c159830b..00000000 --- a/docs/blocks/math/math.md +++ /dev/null @@ -1,42 +0,0 @@ -# Math functions - -### @parent blocks/language - -The math library includes math related functions that you can use with [Numbers](/reference/types/number). - -### abs - -math `->` abs (x : [Number](/reference/types/number)) *returns* [Number](/reference/types/number) - -returns the absolute value of input parameter `x` - -![](/static/mb/blocks/math-0.png) - -### max - -math `->` max (x : [Number](/reference/types/number), y : [Number](/reference/types/number)) *returns* [Number](/reference/types/number) - -returns the larger of two input numbers (`x` and `y`) - -![](/static/mb/blocks/math-1.png) - -### min - -math `->` min (x : [Number](/reference/types/number), y : [Number](/reference/types/number)) *returns* [Number](/reference/types/number) - -returns the smaller of two input numbers (`x` and `y`) - -![](/static/mb/blocks/math-2.png) - -### random - -math `->` random (limit : [Number](/reference/types/number)) *returns* [Number](/reference/types/number) - -returns a random [Number](/reference/types/number) between 0 and the parameter *limit* - -![](/static/mb/blocks/math-3.png) - -### See also - -[Number](/reference/types/number) - diff --git a/docs/device/crocodile-clips.md b/docs/device/crocodile-clips.md index de76b5c1..f9a90413 100644 --- a/docs/device/crocodile-clips.md +++ b/docs/device/crocodile-clips.md @@ -7,10 +7,16 @@ Register an event that will execute whenever the user attaches one side of the c 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) +```blocks +input.onPinPressed(TouchPin.P0, () => { + basic.showNumber(Math.random(10)) +}) +``` ### Connecting Crocodile Clips +![](/static/mb/crocodile-clips-2.jpg) + ### See also [micro:bit pins](/device/pins), [pin is pressed](/reference/input/pin-is-pressed), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin) diff --git a/docs/lessons/blocks-conditions.md b/docs/lessons/blocks-conditions.md index 20e9159a..55286ca0 100644 --- a/docs/lessons/blocks-conditions.md +++ b/docs/lessons/blocks-conditions.md @@ -4,9 +4,11 @@ An introduction to conditions for the Block Editor. ## Introduction to conditions -In the introduction to code, we made the BBC micro:bit automatically shows the message ‘hello, world!’: +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) +```blocks +basic.showString("hello world!") +``` 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: @@ -16,11 +18,13 @@ This statement, or code, will happen as soon as the BBC micro:bit is activated. 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) +```blocks +basic.forever(() => { + if (input.buttonIsPressed(Button.A)) { + basic.showString("hello world!") + } +}) +``` Again, test the code in the simulator. Try clicking **Button A** to display the "hello, world!" message every time the `button is pressed`. @@ -40,7 +44,15 @@ For example, we could make it so our BBC Micro:bit tells us to press the A butto 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) +```blocks +basic.forever(() => { + if (input.buttonIsPressed(Button.A)) { + basic.showString("hello world!") + } else { + basic.showString("PRESS A") + } +}) +``` So, to recap: the `forever` block makes sure our code runs forever. The 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 **Download** to send the code onto the BBC micro:bit. diff --git a/docs/lessons/challenges.md b/docs/lessons/challenges.md deleted file mode 100644 index dc280585..00000000 --- a/docs/lessons/challenges.md +++ /dev/null @@ -1,88 +0,0 @@ -# blocks - challenges - -Extra stuff for the Block Editor - an introduction to GPIO - -## 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](/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/graphics.md b/docs/lessons/graphics.md index 0f9f32b8..3ce1fd05 100644 --- a/docs/lessons/graphics.md +++ b/docs/lessons/graphics.md @@ -6,7 +6,9 @@ An introduction to graphics for the Block Editor. 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) +```blocks +basic.showString("HI!"); +``` The BBC micro:bit has a grid of 25 LEDs, so we can use these to display images. @@ -24,9 +26,16 @@ We can also code our bug to plot a point by giving an x (horizontal) and y (vert 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) +```blocks +basic.forever(() => { + led.plot(2,2) + basic.pause(100) + led.unplot(2,2) + basic.pause(100) +}) +``` -We can also use the `clear screen` block to turn off all LEDs. +We can also use the `basic.clearScreen` block to turn off all LEDs. ## Tip @@ -34,26 +43,35 @@ The pause block is in milliseconds, so setting it to 1000 will have a pause of a ### 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: +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) +```blocks +for(let i = 0; i <=4; i++) { + led.plot(i, 0); + basic.pause(200) +} +``` Our algorithm is: increase **i** by 1 **from 0** to **4**, and **plot** the point **x=i**, **y=0**. The pause block allows this line to be animated (drawn frame by frame). -Try devising an algorithm for a diagonal line using the code above and the variable **i**. 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](/lessons/challenges) section for additional graphical challenges and solutions. +Try devising an algorithm for a diagonal line using the code above and the variable **i**. +```sim +basic.forever(() => { + for(let i = 0; i <=4; i++) { + led.plot(i, i); + basic.pause(200) + } + basic.clearScreen(); +}) +``` ### Animations -Animations are changes happening at a certain rate. For example, we could add the `delay` block from the **Basic** drawer with our square algorithm – this will slowly draw a square (as an animation). +Animations are changes happening at a certain rate. For example, we could add the `pause` block from the **Basic** drawer with our square algorithm – this will slowly draw a square (as an animation). We could create more complex animations, for example we could make our BBC micro:bit display an explosion or fireworks. -See the [challenges](/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: diff --git a/docs/lessons/loops.md b/docs/lessons/loops.md deleted file mode 100644 index 0ed94244..00000000 --- a/docs/lessons/loops.md +++ /dev/null @@ -1,59 +0,0 @@ -# blocks - loops - -An introduction to Loops for the Block Editor. - -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/seismograph/activity.md b/docs/lessons/seismograph/activity.md index d82f268a..5878cab1 100644 --- a/docs/lessons/seismograph/activity.md +++ b/docs/lessons/seismograph/activity.md @@ -94,8 +94,6 @@ Connect a micro:bit to your computer using your USB cable Click or tap the **Download** button for the seismograph program to run the program on the micro:bit. -![](/static/mb/lessons/seismograph22.png) - ## 9. A black line should appear directly beneath the colored line. The black line measures the micro:bit acceleration. And the colored line measures micro:bit simulator acceleration. diff --git a/docs/offline.md b/docs/offline.md new file mode 100644 index 00000000..402fa521 --- /dev/null +++ b/docs/offline.md @@ -0,0 +1,18 @@ +# Offline editing + +## Web application + +**https://codethemicrobit.com is an HTML5 web application** that automatically gets cached locally by your browser. +Once the web app is loaded and you have compiled at least once, you will have all the code needed to work without an internet connection. + +## Command line interface + +For more experience users, you can download the entire toolchain and use the [command line interface](/cli) (CLI) to compile +and deploy your scripts locally. PXT provides a great out-of-the-box experience using [Visual Studio Code](/code), +a lightweight cross-platform code editor. + +![](/static/mb/vscode.png) + +## Native clients + +There are no native clients available yet. \ No newline at end of file diff --git a/docs/reference/String.md b/docs/reference/String.md deleted file mode 100644 index 15e6de5d..00000000 --- a/docs/reference/String.md +++ /dev/null @@ -1,9 +0,0 @@ -# String - -```cards -String.fromCharCode(0); -``` - -### See Also - -[fromCharCode](/reference//math/string-from-char-code) diff --git a/docs/reference/images/image.md b/docs/reference/images/image.md index 580032c5..0c2681b6 100644 --- a/docs/reference/images/image.md +++ b/docs/reference/images/image.md @@ -11,11 +11,16 @@ An *Image* is a matrix of pixels to show on the [LED screen](/device/screen) To display an image: * 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: +```blocks +basic.showLeds(` + . . . . . + . # . # . + . . . . . + # . . . # + . # # # . + `) +``` ### Creating an image diff --git a/docs/reference/led/toggle-all.md b/docs/reference/led/toggle-all.md index 59e58122..00170e99 100644 --- a/docs/reference/led/toggle-all.md +++ b/docs/reference/led/toggle-all.md @@ -20,7 +20,11 @@ led.plot(2, 2) led.toggleAll() ``` -![](/static/mb/toggle-all-0.png) +```sim +basic.clearScreen() +led.plot(2, 2) +led.toggleAll() +``` ### See also diff --git a/docs/reference/offline.md b/docs/reference/offline.md deleted file mode 100644 index 028f3dc8..00000000 --- a/docs/reference/offline.md +++ /dev/null @@ -1,26 +0,0 @@ -# Off-line support - -The micro:bit pins. - -## 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 [https://codethemicrobit.com/](https://codethemicrobit.com/), 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 is 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/static/mb/antenna-0.png b/docs/static/mb/antenna-0.png deleted file mode 100644 index a8852657..00000000 Binary files a/docs/static/mb/antenna-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/comment-0.png b/docs/static/mb/blocks/comment-0.png deleted file mode 100644 index 937f29dc..00000000 Binary files a/docs/static/mb/blocks/comment-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/crocodile-clips-1.jpg b/docs/static/mb/blocks/crocodile-clips-1.jpg deleted file mode 100644 index 9bf243be..00000000 Binary files a/docs/static/mb/blocks/crocodile-clips-1.jpg and /dev/null differ diff --git a/docs/static/mb/blocks/game-library/pic0.png b/docs/static/mb/blocks/game-library/pic0.png deleted file mode 100644 index de491588..00000000 Binary files a/docs/static/mb/blocks/game-library/pic0.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons-0.png b/docs/static/mb/blocks/lessons-0.png deleted file mode 100644 index 88e5727f..00000000 Binary files a/docs/static/mb/blocks/lessons-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons-1.png b/docs/static/mb/blocks/lessons-1.png deleted file mode 100644 index 6f26c48f..00000000 Binary files a/docs/static/mb/blocks/lessons-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons-2.png b/docs/static/mb/blocks/lessons-2.png deleted file mode 100644 index 8f8dec72..00000000 Binary files a/docs/static/mb/blocks/lessons-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons-3.png b/docs/static/mb/blocks/lessons-3.png deleted file mode 100644 index 38c46dba..00000000 Binary files a/docs/static/mb/blocks/lessons-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons-4.png b/docs/static/mb/blocks/lessons-4.png deleted file mode 100644 index 38c4dafe..00000000 Binary files a/docs/static/mb/blocks/lessons-4.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons-5.png b/docs/static/mb/blocks/lessons-5.png deleted file mode 100644 index 3a04b8c5..00000000 Binary files a/docs/static/mb/blocks/lessons-5.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/blocks-conditions-0.png b/docs/static/mb/blocks/lessons/blocks-conditions-0.png deleted file mode 100644 index 2d033a74..00000000 Binary files a/docs/static/mb/blocks/lessons/blocks-conditions-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/blocks-conditions-1.png b/docs/static/mb/blocks/lessons/blocks-conditions-1.png deleted file mode 100644 index 6094da13..00000000 Binary files a/docs/static/mb/blocks/lessons/blocks-conditions-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/blocks-conditions-2.png b/docs/static/mb/blocks/lessons/blocks-conditions-2.png deleted file mode 100644 index 9718d82a..00000000 Binary files a/docs/static/mb/blocks/lessons/blocks-conditions-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/crocodile-clip-0.jpg b/docs/static/mb/blocks/lessons/crocodile-clip-0.jpg deleted file mode 100644 index 73fcaf7f..00000000 Binary files a/docs/static/mb/blocks/lessons/crocodile-clip-0.jpg and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-1.png b/docs/static/mb/blocks/lessons/glowing-pendulum-1.png deleted file mode 100644 index 11ca9143..00000000 Binary files a/docs/static/mb/blocks/lessons/glowing-pendulum-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-2.png b/docs/static/mb/blocks/lessons/glowing-pendulum-2.png deleted file mode 100644 index 8db2a863..00000000 Binary files a/docs/static/mb/blocks/lessons/glowing-pendulum-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-3.png b/docs/static/mb/blocks/lessons/glowing-pendulum-3.png deleted file mode 100644 index d51f2491..00000000 Binary files a/docs/static/mb/blocks/lessons/glowing-pendulum-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-4.png b/docs/static/mb/blocks/lessons/glowing-pendulum-4.png deleted file mode 100644 index 32795798..00000000 Binary files a/docs/static/mb/blocks/lessons/glowing-pendulum-4.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/glowing-pendulum-5.png b/docs/static/mb/blocks/lessons/glowing-pendulum-5.png deleted file mode 100644 index 2571a1d1..00000000 Binary files a/docs/static/mb/blocks/lessons/glowing-pendulum-5.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/graphics-1.png b/docs/static/mb/blocks/lessons/graphics-1.png deleted file mode 100644 index ed4f275d..00000000 Binary files a/docs/static/mb/blocks/lessons/graphics-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/graphics-2.png b/docs/static/mb/blocks/lessons/graphics-2.png deleted file mode 100644 index d6e5b267..00000000 Binary files a/docs/static/mb/blocks/lessons/graphics-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/lessons/graphics-3.png b/docs/static/mb/blocks/lessons/graphics-3.png deleted file mode 100644 index 7204187b..00000000 Binary files a/docs/static/mb/blocks/lessons/graphics-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/math-0.png b/docs/static/mb/blocks/math-0.png deleted file mode 100644 index 16944807..00000000 Binary files a/docs/static/mb/blocks/math-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/math-1.png b/docs/static/mb/blocks/math-1.png deleted file mode 100644 index 67ca7db5..00000000 Binary files a/docs/static/mb/blocks/math-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/math-2.png b/docs/static/mb/blocks/math-2.png deleted file mode 100644 index f6a11613..00000000 Binary files a/docs/static/mb/blocks/math-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/math-3.png b/docs/static/mb/blocks/math-3.png deleted file mode 100644 index 227be03a..00000000 Binary files a/docs/static/mb/blocks/math-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/number-0.png b/docs/static/mb/blocks/number-0.png deleted file mode 100644 index 5bc93cf4..00000000 Binary files a/docs/static/mb/blocks/number-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/number-1.png b/docs/static/mb/blocks/number-1.png deleted file mode 100644 index 7f58f462..00000000 Binary files a/docs/static/mb/blocks/number-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/number-2.png b/docs/static/mb/blocks/number-2.png deleted file mode 100644 index fbb99b92..00000000 Binary files a/docs/static/mb/blocks/number-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/number-3.png b/docs/static/mb/blocks/number-3.png deleted file mode 100644 index 6cac6c4e..00000000 Binary files a/docs/static/mb/blocks/number-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/string-0.png b/docs/static/mb/blocks/string-0.png deleted file mode 100644 index 466c13ea..00000000 Binary files a/docs/static/mb/blocks/string-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/string-1.png b/docs/static/mb/blocks/string-1.png deleted file mode 100644 index e085cc36..00000000 Binary files a/docs/static/mb/blocks/string-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/string-2.png b/docs/static/mb/blocks/string-2.png deleted file mode 100644 index ad2ef979..00000000 Binary files a/docs/static/mb/blocks/string-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-0.png b/docs/static/mb/blocks/to-td-0.png deleted file mode 100644 index 6ee02a9d..00000000 Binary files a/docs/static/mb/blocks/to-td-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-1.png b/docs/static/mb/blocks/to-td-1.png deleted file mode 100644 index 6ed7e37b..00000000 Binary files a/docs/static/mb/blocks/to-td-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-2.png b/docs/static/mb/blocks/to-td-2.png deleted file mode 100644 index 0a009400..00000000 Binary files a/docs/static/mb/blocks/to-td-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-3.png b/docs/static/mb/blocks/to-td-3.png deleted file mode 100644 index 65e511a2..00000000 Binary files a/docs/static/mb/blocks/to-td-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-4.png b/docs/static/mb/blocks/to-td-4.png deleted file mode 100644 index e6a69827..00000000 Binary files a/docs/static/mb/blocks/to-td-4.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-5.png b/docs/static/mb/blocks/to-td-5.png deleted file mode 100644 index c8ecf130..00000000 Binary files a/docs/static/mb/blocks/to-td-5.png and /dev/null differ diff --git a/docs/static/mb/blocks/to-td-6.png b/docs/static/mb/blocks/to-td-6.png deleted file mode 100644 index 4147c438..00000000 Binary files a/docs/static/mb/blocks/to-td-6.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-0.png b/docs/static/mb/blocks/var-0.png deleted file mode 100644 index 917fce60..00000000 Binary files a/docs/static/mb/blocks/var-0.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-1.png b/docs/static/mb/blocks/var-1.png deleted file mode 100644 index e0cf928f..00000000 Binary files a/docs/static/mb/blocks/var-1.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-10.png b/docs/static/mb/blocks/var-10.png deleted file mode 100644 index c25611d9..00000000 Binary files a/docs/static/mb/blocks/var-10.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-2.png b/docs/static/mb/blocks/var-2.png deleted file mode 100644 index a0d6ad1d..00000000 Binary files a/docs/static/mb/blocks/var-2.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-3.png b/docs/static/mb/blocks/var-3.png deleted file mode 100644 index 14b9bc23..00000000 Binary files a/docs/static/mb/blocks/var-3.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-4.png b/docs/static/mb/blocks/var-4.png deleted file mode 100644 index 7a7c16fd..00000000 Binary files a/docs/static/mb/blocks/var-4.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-5.png b/docs/static/mb/blocks/var-5.png deleted file mode 100644 index 29c0c54f..00000000 Binary files a/docs/static/mb/blocks/var-5.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-6.png b/docs/static/mb/blocks/var-6.png deleted file mode 100644 index 787eace4..00000000 Binary files a/docs/static/mb/blocks/var-6.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-7.png b/docs/static/mb/blocks/var-7.png deleted file mode 100644 index da6c6cc2..00000000 Binary files a/docs/static/mb/blocks/var-7.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-8.png b/docs/static/mb/blocks/var-8.png deleted file mode 100644 index f6ef5515..00000000 Binary files a/docs/static/mb/blocks/var-8.png and /dev/null differ diff --git a/docs/static/mb/blocks/var-9.png b/docs/static/mb/blocks/var-9.png deleted file mode 100644 index 92cd8c74..00000000 Binary files a/docs/static/mb/blocks/var-9.png and /dev/null differ diff --git a/docs/static/mb/boolean-0.png b/docs/static/mb/boolean-0.png deleted file mode 100644 index 69283369..00000000 Binary files a/docs/static/mb/boolean-0.png and /dev/null differ diff --git a/docs/static/mb/boolean-1.png b/docs/static/mb/boolean-1.png deleted file mode 100644 index 4e145faa..00000000 Binary files a/docs/static/mb/boolean-1.png and /dev/null differ diff --git a/docs/static/mb/boolean-2.png b/docs/static/mb/boolean-2.png deleted file mode 100644 index 8f940dd6..00000000 Binary files a/docs/static/mb/boolean-2.png and /dev/null differ diff --git a/docs/static/mb/change-0.png b/docs/static/mb/change-0.png deleted file mode 100644 index fb0d1c20..00000000 Binary files a/docs/static/mb/change-0.png and /dev/null differ diff --git a/docs/static/mb/change-score-by-0.png b/docs/static/mb/change-score-by-0.png deleted file mode 100644 index 69b51e2e..00000000 Binary files a/docs/static/mb/change-score-by-0.png and /dev/null differ diff --git a/docs/static/mb/create-sprite-0.png b/docs/static/mb/create-sprite-0.png deleted file mode 100644 index 94ed97b9..00000000 Binary files a/docs/static/mb/create-sprite-0.png and /dev/null differ diff --git a/docs/static/mb/crocodile-clips-0.png b/docs/static/mb/crocodile-clips-0.png deleted file mode 100644 index 96eb3992..00000000 Binary files a/docs/static/mb/crocodile-clips-0.png and /dev/null differ diff --git a/docs/static/mb/crocodile-clips-2.jpg b/docs/static/mb/crocodile-clips-2.jpg index b1c6bf7f..633738dd 100644 Binary files a/docs/static/mb/crocodile-clips-2.jpg and b/docs/static/mb/crocodile-clips-2.jpg differ diff --git a/docs/static/mb/csv.png b/docs/static/mb/csv.png index 382d5136..b54464e4 100644 Binary files a/docs/static/mb/csv.png and b/docs/static/mb/csv.png differ diff --git a/docs/static/mb/data-4.png b/docs/static/mb/data-4.png deleted file mode 100644 index 65b07827..00000000 Binary files a/docs/static/mb/data-4.png and /dev/null differ diff --git a/docs/static/mb/events-0.png b/docs/static/mb/events-0.png deleted file mode 100644 index de237200..00000000 Binary files a/docs/static/mb/events-0.png and /dev/null 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 deleted file mode 100644 index e9ac2973..00000000 Binary files a/docs/static/mb/game-library/add-point-to-score-0.png and /dev/null differ diff --git a/docs/static/mb/game-library/game-over-0.png b/docs/static/mb/game-library/game-over-0.png deleted file mode 100644 index d63873bd..00000000 Binary files a/docs/static/mb/game-library/game-over-0.png and /dev/null 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 deleted file mode 100644 index 5d3f8139..00000000 Binary files a/docs/static/mb/game-library/if-on-edge-bounce-0.png and /dev/null differ diff --git a/docs/static/mb/game-library/move-0.png b/docs/static/mb/game-library/move-0.png deleted file mode 100644 index 32c99fd5..00000000 Binary files a/docs/static/mb/game-library/move-0.png and /dev/null differ diff --git a/docs/static/mb/game-library/pic0.png b/docs/static/mb/game-library/pic0.png deleted file mode 100644 index 849e72a2..00000000 Binary files a/docs/static/mb/game-library/pic0.png and /dev/null differ diff --git a/docs/static/mb/game-library/pic1.png b/docs/static/mb/game-library/pic1.png deleted file mode 100644 index 034e1d41..00000000 Binary files a/docs/static/mb/game-library/pic1.png and /dev/null differ diff --git a/docs/static/mb/game-library/pic2.png b/docs/static/mb/game-library/pic2.png deleted file mode 100644 index 3609a339..00000000 Binary files a/docs/static/mb/game-library/pic2.png and /dev/null differ diff --git a/docs/static/mb/game-library/pic3.png b/docs/static/mb/game-library/pic3.png deleted file mode 100644 index 5d78a089..00000000 Binary files a/docs/static/mb/game-library/pic3.png and /dev/null differ diff --git a/docs/static/mb/game-library/position-0.png b/docs/static/mb/game-library/position-0.png deleted file mode 100644 index a60bc387..00000000 Binary files a/docs/static/mb/game-library/position-0.png and /dev/null differ diff --git a/docs/static/mb/game-library/reports-0.jpg b/docs/static/mb/game-library/reports-0.jpg deleted file mode 100644 index dbb0f52f..00000000 Binary files a/docs/static/mb/game-library/reports-0.jpg and /dev/null differ diff --git a/docs/static/mb/game-library/reports-1.jpg b/docs/static/mb/game-library/reports-1.jpg deleted file mode 100644 index 74be2848..00000000 Binary files a/docs/static/mb/game-library/reports-1.jpg and /dev/null differ diff --git a/docs/static/mb/game-library/reports-2.jpg b/docs/static/mb/game-library/reports-2.jpg deleted file mode 100644 index 41b88d1f..00000000 Binary files a/docs/static/mb/game-library/reports-2.jpg and /dev/null differ diff --git a/docs/static/mb/game-library/start-countdown-0.png b/docs/static/mb/game-library/start-countdown-0.png deleted file mode 100644 index e214070c..00000000 Binary files a/docs/static/mb/game-library/start-countdown-0.png and /dev/null differ diff --git a/docs/static/mb/game-library/touching-0.png b/docs/static/mb/game-library/touching-0.png deleted file mode 100644 index db48069b..00000000 Binary files a/docs/static/mb/game-library/touching-0.png and /dev/null differ diff --git a/docs/static/mb/game-library/turn-0.png b/docs/static/mb/game-library/turn-0.png deleted file mode 100644 index 4ee0c1f0..00000000 Binary files a/docs/static/mb/game-library/turn-0.png and /dev/null differ diff --git a/docs/static/mb/hourofcode-0.png b/docs/static/mb/hourofcode-0.png deleted file mode 100644 index da13914c..00000000 Binary files a/docs/static/mb/hourofcode-0.png and /dev/null differ diff --git a/docs/static/mb/lessons/bounce-image-0.png b/docs/static/mb/lessons/bounce-image-0.png deleted file mode 100644 index 88589000..00000000 Binary files a/docs/static/mb/lessons/bounce-image-0.png and /dev/null differ diff --git a/docs/static/mb/lessons/bounce-image-1.png b/docs/static/mb/lessons/bounce-image-1.png deleted file mode 100644 index 5fde403a..00000000 Binary files a/docs/static/mb/lessons/bounce-image-1.png and /dev/null differ diff --git a/docs/static/mb/lessons/bounce-image-2.png b/docs/static/mb/lessons/bounce-image-2.png deleted file mode 100644 index e9034f0e..00000000 Binary files a/docs/static/mb/lessons/bounce-image-2.png and /dev/null differ diff --git a/docs/static/mb/lessons/seismograph4.png b/docs/static/mb/lessons/seismograph4.png deleted file mode 100644 index 7a5fce3f..00000000 Binary files a/docs/static/mb/lessons/seismograph4.png and /dev/null differ diff --git a/docs/static/mb/object-disclaimer-0.png b/docs/static/mb/object-disclaimer-0.png deleted file mode 100644 index 88e79e7f..00000000 Binary files a/docs/static/mb/object-disclaimer-0.png and /dev/null differ diff --git a/docs/static/mb/object-types-0.png b/docs/static/mb/object-types-0.png deleted file mode 100644 index 42f9eceb..00000000 Binary files a/docs/static/mb/object-types-0.png and /dev/null differ diff --git a/docs/static/mb/object-types-1.png b/docs/static/mb/object-types-1.png deleted file mode 100644 index b740edc2..00000000 Binary files a/docs/static/mb/object-types-1.png and /dev/null differ diff --git a/docs/static/mb/offline-0.png b/docs/static/mb/offline-0.png deleted file mode 100644 index 47db39d4..00000000 Binary files a/docs/static/mb/offline-0.png and /dev/null differ diff --git a/docs/static/mb/offline-1.png b/docs/static/mb/offline-1.png deleted file mode 100644 index e0eb9852..00000000 Binary files a/docs/static/mb/offline-1.png and /dev/null differ diff --git a/docs/static/mb/on-gamepad-button-0.png b/docs/static/mb/on-gamepad-button-0.png deleted file mode 100644 index b91e67c1..00000000 Binary files a/docs/static/mb/on-gamepad-button-0.png and /dev/null differ diff --git a/docs/static/mb/on-signal-strength-changed-0.png b/docs/static/mb/on-signal-strength-changed-0.png deleted file mode 100644 index 6f63179b..00000000 Binary files a/docs/static/mb/on-signal-strength-changed-0.png and /dev/null differ diff --git a/docs/static/mb/plot-leds-0.png b/docs/static/mb/plot-leds-0.png deleted file mode 100644 index a46924b1..00000000 Binary files a/docs/static/mb/plot-leds-0.png and /dev/null differ diff --git a/docs/static/mb/raise-alert-to-0.png b/docs/static/mb/raise-alert-to-0.png deleted file mode 100644 index 523238f9..00000000 Binary files a/docs/static/mb/raise-alert-to-0.png and /dev/null differ diff --git a/docs/static/mb/receive-number-0.png b/docs/static/mb/receive-number-0.png deleted file mode 100644 index 1d93af01..00000000 Binary files a/docs/static/mb/receive-number-0.png and /dev/null differ diff --git a/docs/static/mb/scroll-image-0.png b/docs/static/mb/scroll-image-0.png deleted file mode 100644 index ae2903b3..00000000 Binary files a/docs/static/mb/scroll-image-0.png and /dev/null differ diff --git a/docs/static/mb/show-image-0.png b/docs/static/mb/show-image-0.png deleted file mode 100644 index a13abe9d..00000000 Binary files a/docs/static/mb/show-image-0.png and /dev/null differ diff --git a/docs/static/mb/signal-strength-0.png b/docs/static/mb/signal-strength-0.png deleted file mode 100644 index 4c870c32..00000000 Binary files a/docs/static/mb/signal-strength-0.png and /dev/null differ diff --git a/docs/static/mb/simulator-0.png b/docs/static/mb/simulator-0.png deleted file mode 100644 index 87348b3c..00000000 Binary files a/docs/static/mb/simulator-0.png and /dev/null differ diff --git a/docs/static/mb/string-0.png b/docs/static/mb/string-0.png deleted file mode 100644 index 6efcb95e..00000000 Binary files a/docs/static/mb/string-0.png and /dev/null differ diff --git a/docs/static/mb/tell-camera-to-0.png b/docs/static/mb/tell-camera-to-0.png deleted file mode 100644 index a66fd0fa..00000000 Binary files a/docs/static/mb/tell-camera-to-0.png and /dev/null differ diff --git a/docs/static/mb/tell-microphone-to-0.png b/docs/static/mb/tell-microphone-to-0.png deleted file mode 100644 index 7222262f..00000000 Binary files a/docs/static/mb/tell-microphone-to-0.png and /dev/null differ diff --git a/docs/static/mb/tell-remote-control-to-0.png b/docs/static/mb/tell-remote-control-to-0.png deleted file mode 100644 index 597bc14e..00000000 Binary files a/docs/static/mb/tell-remote-control-to-0.png and /dev/null differ diff --git a/docs/static/mb/toggle-all-0.png b/docs/static/mb/toggle-all-0.png deleted file mode 100644 index 811a3e95..00000000 Binary files a/docs/static/mb/toggle-all-0.png and /dev/null differ diff --git a/libs/microbit/core.cpp b/libs/microbit/core.cpp index 527460a4..c8cd2b24 100644 --- a/libs/microbit/core.cpp +++ b/libs/microbit/core.cpp @@ -183,6 +183,8 @@ namespace pxt { //% RefRecord* mkRecord(int reflen, int totallen); //% + RefRecord* mkClassInstance(int offset); + //% void debugMemLeaks(); //% int incr(uint32_t e); diff --git a/olddocs/blocks-vs-js.md b/olddocs/blocks-vs-js.md deleted file mode 100644 index 96a71996..00000000 --- a/olddocs/blocks-vs-js.md +++ /dev/null @@ -1,141 +0,0 @@ -# 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](/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(Button.A, () => { - for (let i4 = 0; i4 < 5; i4++) { - led.plot(i4, i4) - basic.pause(1000) - } -}) -input.onButtonPressed(Button.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/olddocs/js/assign.md b/olddocs/js/assign.md deleted file mode 100644 index bdb44fcd..00000000 --- a/olddocs/js/assign.md +++ /dev/null @@ -1,50 +0,0 @@ -# Assignment Operator - -Set the value for local and global variables. - -### @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](/blocks/variables/var) or a [global variable](/js/data). - -### Declare a variable - -Declare a new *local* variable using the [var](/blocks/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](/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](/js/types). - -### See also - -[local variables](/reference/variables/var), [global variables](/js/data), [types](/js/types) - diff --git a/olddocs/js/boolean.md b/olddocs/js/boolean.md deleted file mode 100644 index c237308b..00000000 --- a/olddocs/js/boolean.md +++ /dev/null @@ -1,118 +0,0 @@ -# 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](/reference/types/number), [strings](/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](/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](/blocks/logic/if) or [while](/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](/reference/types/number) for more information on comparing two Numbers. You can also [compare strings](/reference/types/string-functions) using the `equals` function. - -### See also - -[if](/reference/logic/if), [while](/js/while), [number](/reference/types/number) - diff --git a/olddocs/js/data.md b/olddocs/js/data.md deleted file mode 100644 index bcfb7c9e..00000000 --- a/olddocs/js/data.md +++ /dev/null @@ -1,112 +0,0 @@ -# Global Variables - -How to define and use global 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](/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](/js/data) or [local](/reference/variables/var). Variables have a name, a [type](/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](/js/data) are variables that are available throughout your script. Unlike [local variables](/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](/js/editor), click `script` (to the right of the search box). - -2. Click `+` **add new**. - -3. Click `data->` **data** and then choose a [type](/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](/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](/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](/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](/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](/lessons/counter), [rotation animation](/lessons/rotation-animation), [digital pet](/lessons/digital-pet), [offset image](/lessons/offset-image) - -### See also - -[local variables](/reference/variables/var), [types](/js/types), [assignment operator](/reference/variables/assign) - diff --git a/olddocs/js/editor.md b/olddocs/js/editor.md deleted file mode 100644 index a7a91e32..00000000 --- a/olddocs/js/editor.md +++ /dev/null @@ -1,112 +0,0 @@ -# Touch Develop Editor - -The Touch Develop editor. - -### @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](/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](/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](/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](/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](/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](/js/statements) that you can insert into your code. These buttons are blue and include things like [var](/reference/variables/var), [if](/reference/logic/if), [for](/reference/loops/for) , and [while](/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](/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](/js/call) for more info) -* `math`: click to see [math functions](/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](/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](/js/publishing) it -* `share`: share a link to a published script (see [publish as script](/js/publishing) for more info) -* `preview`: preview a documentation script -* `+` `add new`: add a new [function](/js/function), [global variable](/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](/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](/js/comment). You can format your comments using [markdown syntax](/js/markdown). - -### Share your scripts - -Share your scripts with other people by publishing them. See [publish a script](/js/publishing) for more info. - -### See also - -[publish a script](/js/publishing), [Touch Develop documentation](/js/contents) - diff --git a/olddocs/js/for.md b/olddocs/js/for.md index eb6a2835..f219c572 100644 --- a/olddocs/js/for.md +++ b/olddocs/js/for.md @@ -9,8 +9,6 @@ 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: ``` diff --git a/olddocs/js/gallery.md b/olddocs/js/gallery.md index 8bd16243..f82a6e55 100644 --- a/olddocs/js/gallery.md +++ b/olddocs/js/gallery.md @@ -34,7 +34,6 @@ Overview of Touch Develop lessons for the BBC micro:bit. ### ~hide -* [Bounce image](/lessons/bounce-image), scroll an image across the screen on shake * [Magic logo](/lessons/magic-logo), show an image on logo up * [Glowing sword](/lessons/glowing-sword), make a glowing sword with fade in and fade out diff --git a/olddocs/js/game-library/add-point-to-score.md b/olddocs/js/game-library/add-point-to-score.md deleted file mode 100644 index fba67cf5..00000000 --- a/olddocs/js/game-library/add-point-to-score.md +++ /dev/null @@ -1,33 +0,0 @@ -# Add Points to Score - -The game library supports simple single-player time-based games. The player will ** add points to score**. - -The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. - -```blocks -input.onButtonPressed(Button.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](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter) - diff --git a/olddocs/js/game-library/change-score-by.md b/olddocs/js/game-library/change-score-by.md deleted file mode 100644 index d5d1b7ac..00000000 --- a/olddocs/js/game-library/change-score-by.md +++ /dev/null @@ -1,31 +0,0 @@ -# Change Score By - -The game library supports simple single-player time-based games. The player will ** add points to score**. - -```blocks -input.onButtonPressed(Button.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](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter) - diff --git a/olddocs/js/game-library/game-over.md b/olddocs/js/game-library/game-over.md deleted file mode 100644 index 63172672..00000000 --- a/olddocs/js/game-library/game-over.md +++ /dev/null @@ -1,12 +0,0 @@ -# Game Over - -You can end the game by calling the `game -> game over` function: - -```blocks -game.gameOver() -``` - -### Lessons - -[game of chance](/lessons/game-of-chance) - diff --git a/olddocs/js/game-library/score.md b/olddocs/js/game-library/score.md deleted file mode 100644 index 274462fd..00000000 --- a/olddocs/js/game-library/score.md +++ /dev/null @@ -1,59 +0,0 @@ -# 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(Button.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](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter) - diff --git a/olddocs/js/game-library/start-countdown.md b/olddocs/js/game-library/start-countdown.md deleted file mode 100644 index 32d8f35d..00000000 --- a/olddocs/js/game-library/start-countdown.md +++ /dev/null @@ -1,57 +0,0 @@ -# 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(Button.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](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter) - diff --git a/olddocs/js/games.md b/olddocs/js/games.md index 5d9b8a43..529bf681 100644 --- a/olddocs/js/games.md +++ b/olddocs/js/games.md @@ -17,7 +17,6 @@ Overview of Games for the BBC micro:bit. * [Lucky 7](/lessons/lucky-7), show a number on the LED screen with show number * [Snowflake fall](/lessons/snowflake-fall), repeat an animation with forever * [Answering machine](/lessons/answering-machine), show a text message with show string -* [Bounce image](/lessons/bounce-image), scroll an image across the screen on shake * [Magic logo](/lessons/magic-logo), show an image on logo up * [Screen wipe](/lessons/screen-wipe), turn off the LEDs with clear screen * [Blink](/lessons/blink), turn an LED on and off with plot diff --git a/olddocs/js/if.md b/olddocs/js/if.md index 78c3978d..2411694d 100644 --- a/olddocs/js/if.md +++ b/olddocs/js/if.md @@ -9,8 +9,6 @@ Conditionally run code depending on whether a [Boolean](/reference/types/boolean ### 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 diff --git a/olddocs/js/image.md b/olddocs/js/image.md index 69b7025b..13d5d2b7 100644 --- a/olddocs/js/image.md +++ b/olddocs/js/image.md @@ -62,7 +62,6 @@ Images that you create in the [Touch Develop editor](/js/editor) are [local vari ### Lessons -* [bounce image ](/lessons/bounce-image) * [offset image](/lessons/offset-image) ### See also diff --git a/olddocs/js/lessons.md b/olddocs/js/lessons.md index 3286bb20..d3e66d1b 100644 --- a/olddocs/js/lessons.md +++ b/olddocs/js/lessons.md @@ -22,12 +22,6 @@ Overview of Touch Develop lessons for the BBC micro:bit. * [Answering Machine](/lessons/answering-machine), show a text message with show string * [Snowflake Fall](/lessons/snowflake-fall), repeat an animation with forever -### ~hide - -* [Bounce Image](/lessons/bounce-image), scroll an image across the screen on shake - -### ~ - * [Magic Logo](/lessons/magic-logo), show an image on logo up * [Screen Wipe](/lessons/screen-wipe), turn off the LEDs with clear screen * [Flashing Heart](/lessons/flashing-heart), display images with a pause diff --git a/olddocs/js/lessons/bounce-image.md b/olddocs/js/lessons/bounce-image.md deleted file mode 100644 index 3a772f2f..00000000 --- a/olddocs/js/lessons/bounce-image.md +++ /dev/null @@ -1,106 +0,0 @@ -# bounce image lesson - -scroll an image across the screen. - -## Topic - -Basic- Show Animation - -## Quick Links - -* [tutorial](/lessons/bounce-image/tutorial) -* [quiz](/lessons/bounce-image/quiz) -* [quiz answers](/lessons/bounce-image/quiz-answers) -* [challenges](/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...](/reference/basic/forever) -* **show animation** : [read more...](/reference/basic/show-animation) -* **on shake** : [read more...](/reference/input/on-gesture) - -## Resources - -* Activity: [tutorial](/lessons/bounce-image/tutorial) -* Activity: [quiz](/lessons/bounce-image/quiz) -* Extended Activity: [challenges](/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](/lessons/bounce-image/tutorial) -* [quiz](/lessons/bounce-image/quiz) - -## Extended Activity - -* time: 20 min. -* [challenges](/lessons/bounce-image/challenges) - -## Homework - -* Extended Activity: [challenges](/lessons/bounce-image/challenges) - -## Intended follow on - -Publish script to the classroom. - diff --git a/olddocs/js/lessons/bounce-image/challenges.md b/olddocs/js/lessons/bounce-image/challenges.md deleted file mode 100644 index 5db6b044..00000000 --- a/olddocs/js/lessons/bounce-image/challenges.md +++ /dev/null @@ -1,86 +0,0 @@ -# bounce image challenges - -Coding challenges for the bounce image tutorial. #docs - -## Before we get started - -Complete the following guided tutorial: - -* [tutorial](/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 - -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 - -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/olddocs/js/lessons/bounce-image/quiz-answers.md b/olddocs/js/lessons/bounce-image/quiz-answers.md deleted file mode 100644 index 123096ba..00000000 --- a/olddocs/js/lessons/bounce-image/quiz-answers.md +++ /dev/null @@ -1,60 +0,0 @@ -# bounce image quiz answers - -scroll an image on the BBC micro:bit. - -This is the answer key for the [bounce image quiz](/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/olddocs/js/lessons/bounce-image/quiz.md b/olddocs/js/lessons/bounce-image/quiz.md deleted file mode 100644 index 9d889c91..00000000 --- a/olddocs/js/lessons/bounce-image/quiz.md +++ /dev/null @@ -1,40 +0,0 @@ -# bounce image quiz - -scroll an image on the BBC micro:bit. - -## Name - -## Directions - -Use this document to guide your work in the [bounce image tutorial](/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/olddocs/js/simulator.md b/olddocs/js/simulator.md index a0531694..d497c595 100644 --- a/olddocs/js/simulator.md +++ b/olddocs/js/simulator.md @@ -8,7 +8,6 @@ While you're writing and testing your scripts, you'll mostly be running scripts 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](/reference/led/plot-image) create a heart image that appears on the BBC micro:bit simulator. diff --git a/olddocs/js/while.md b/olddocs/js/while.md index d84106e8..c50dd1b3 100644 --- a/olddocs/js/while.md +++ b/olddocs/js/while.md @@ -17,7 +17,6 @@ let condition = false ### Block Editor -![](/static/mb/string-0.png) ### Touch Develop diff --git a/package.json b/package.json index 461a7bac..2bd86e84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pxt-microbit", - "version": "0.3.63", + "version": "0.3.67", "description": "micro:bit target for PXT", "keywords": [ "JavaScript", @@ -29,6 +29,6 @@ "typescript": "^1.8.7" }, "dependencies": { - "pxt-core": "0.3.72" + "pxt-core": "0.3.76" } } diff --git a/pxtarget.json b/pxtarget.json index 2b5c0f04..de3d6af8 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -91,7 +91,7 @@ "yottaTarget": "bbc-microbit-classic-gcc", "yottaCorePackage": "pxt-microbit-core", "githubCorePackage": "microsoft/pxt-microbit-core", - "gittag": "v0.4.1", + "gittag": "v0.4.2", "serviceId": "ws" }, "serial": { diff --git a/sim/definitions.ts b/sim/definitions.ts index 2de7ff9b..66f013fd 100644 --- a/sim/definitions.ts +++ b/sim/definitions.ts @@ -191,7 +191,7 @@ namespace pxsim { }, "speaker": { visual: { - image: "/static/hardware/speaker.svg", + image: "/parts/speaker.svg", width: 500, height: 500, firstPin: [180, 135], diff --git a/docs/static/hardware/.gitignore b/sim/public/parts/.gitignore similarity index 88% rename from docs/static/hardware/.gitignore rename to sim/public/parts/.gitignore index a4abe543..74a7a76e 100644 --- a/docs/static/hardware/.gitignore +++ b/sim/public/parts/.gitignore @@ -2,4 +2,4 @@ sparkfun-* raspberrypi-* arduino-* -max6675.svg \ No newline at end of file +max6675* diff --git a/docs/static/hardware/neopixel.svg b/sim/public/parts/neopixel.svg similarity index 100% rename from docs/static/hardware/neopixel.svg rename to sim/public/parts/neopixel.svg diff --git a/docs/static/hardware/speaker.svg b/sim/public/parts/speaker.svg similarity index 100% rename from docs/static/hardware/speaker.svg rename to sim/public/parts/speaker.svg diff --git a/sim/public/instructions.html b/sim/public/siminstructions.html similarity index 100% rename from sim/public/instructions.html rename to sim/public/siminstructions.html diff --git a/sim/state/accelerometer.ts b/sim/state/accelerometer.ts index dc57b1f1..8bc42bd4 100644 --- a/sim/state/accelerometer.ts +++ b/sim/state/accelerometer.ts @@ -7,7 +7,7 @@ namespace pxsim.input { b.useShake = true; runtime.queueDisplayUpdate(); } - pxt.registerWithDal(DAL.MICROBIT_ID_GESTURE, gesture, handler); + pxtcore.registerWithDal(DAL.MICROBIT_ID_GESTURE, gesture, handler); } export function acceleration(dimension: number): number { diff --git a/sim/state/buttonpair.ts b/sim/state/buttonpair.ts index fdad2305..31778c6d 100644 --- a/sim/state/buttonpair.ts +++ b/sim/state/buttonpair.ts @@ -5,7 +5,7 @@ namespace pxsim.input { b.usesButtonAB = true; runtime.queueDisplayUpdate(); } - pxt.registerWithDal(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler); + pxtcore.registerWithDal(button, DAL.MICROBIT_BUTTON_EVT_CLICK, handler); } export function buttonIsPressed(button: number): boolean { diff --git a/sim/state/edgeconnector.ts b/sim/state/edgeconnector.ts index d3278a64..d5e76ad5 100644 --- a/sim/state/edgeconnector.ts +++ b/sim/state/edgeconnector.ts @@ -3,14 +3,14 @@ namespace pxsim.input { let pin = getPin(pinId); if (!pin) return; pin.isTouched(); - pxt.registerWithDal(pin.id, DAL.MICROBIT_BUTTON_EVT_CLICK, handler); + pxtcore.registerWithDal(pin.id, DAL.MICROBIT_BUTTON_EVT_CLICK, handler); } export function onPinReleased(pinId: number, handler: RefAction) { let pin = getPin(pinId); if (!pin) return; pin.isTouched(); - pxt.registerWithDal(pin.id, DAL.MICROBIT_BUTTON_EVT_UP, handler); + pxtcore.registerWithDal(pin.id, DAL.MICROBIT_BUTTON_EVT_UP, handler); } export function pinIsPressed(pinId: number): boolean { diff --git a/sim/state/misc.ts b/sim/state/misc.ts index 2fd7ae95..8e78d540 100644 --- a/sim/state/misc.ts +++ b/sim/state/misc.ts @@ -147,7 +147,7 @@ namespace pxsim.control { } export function onEvent(id: number, evid: number, handler: RefAction) { - pxt.registerWithDal(id, evid, handler) + pxtcore.registerWithDal(id, evid, handler) } export function raiseEvent(id: number, evid: number, mode: number) { @@ -156,7 +156,7 @@ namespace pxsim.control { } } -namespace pxsim.pxt { +namespace pxsim.pxtcore { export function registerWithDal(id: number, evid: number, handler: RefAction) { board().bus.listen(id, evid, handler); } diff --git a/sim/state/radio.ts b/sim/state/radio.ts index 7a48ea3c..fcb5dbb3 100644 --- a/sim/state/radio.ts +++ b/sim/state/radio.ts @@ -94,7 +94,7 @@ namespace pxsim.radio { } export function onBroadcastMessageReceived(msg: number, handler: RefAction): void { - pxt.registerWithDal(DAL.MES_BROADCAST_GENERAL_ID, msg, handler); + pxtcore.registerWithDal(DAL.MES_BROADCAST_GENERAL_ID, msg, handler); } export function setGroup(id: number): void { @@ -152,7 +152,7 @@ namespace pxsim.radio { } export function onDataReceived(handler: RefAction): void { - pxt.registerWithDal(DAL.MICROBIT_ID_RADIO, DAL.MICROBIT_RADIO_EVT_DATAGRAM, handler); + pxtcore.registerWithDal(DAL.MICROBIT_ID_RADIO, DAL.MICROBIT_RADIO_EVT_DATAGRAM, handler); radio.receiveNumber(); } } \ No newline at end of file diff --git a/sim/visuals/neopixel.ts b/sim/visuals/neopixel.ts index 11116166..2cdc73a8 100644 --- a/sim/visuals/neopixel.ts +++ b/sim/visuals/neopixel.ts @@ -67,7 +67,7 @@ namespace pxsim.visuals { let h = NP_PART_HEIGHT; let img = svg.elt("image"); svg.hydrate(img, {class: "sim-neopixel-strip", x: l, y: t, width: w, height: h, - href: `/static/hardware/${NEOPIXEL_PART_IMG}`}); + href: `/parts/${NEOPIXEL_PART_IMG}`}); return {el: img, x: l, y: t, w: w, h: h}; } export class NeoPixel implements SVGAndSize {