forked from CodeGuild-co/PythonEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.html
387 lines (324 loc) · 17 KB
/
help.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="static/img/favicon.ico">
<title>Python on the BBC micro:bit</title>
<!-- Bootstrap core CSS -->
<link href="static/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="static/css/starter-template.css" rel="stylesheet">
<link href="static/css/highlight.min.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="static/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
:q <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#top">Python on the micro:bit</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="#top">Start Here</a></li>
<li><a href="#hello">Hello, World!</a></li>
<li><a href="#blockly">Blockly</a></li>
<li><a href="#snippets">Snippets</a></li>
<li><a href="#bugs">Bug Fixes</a></li>
<li><a href="#fun">Fun Stuff</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="starter-template">
<div class="row" id="home">
<div class="col-md-8 col-md-offset-2">
<a href="http://microbit.co.uk/"><img src="static/img/microbit.png"/></a>
<a href="http://micropython.org/"><img src="static/img/micropython.jpeg"/></a>
<a href="http://python.org/community/microbit/"><img src="static/img/python.png"/></a><a href="http://microbit.co.uk/"></a>
<br/></br/>
</div>
</div>
</div>
<img src="static/img/comic1.png" class="img-responsive center-block"
alt="http://goo.gl/SrIrIE"/>
<h2 id="start">Start Here</h2>
<p>So you're looking at the Python editor and wondering what to do. That's
easy! Let's learn about the different parts of the editor. First of all,
there are some buttons across the top:</p>
<p><img src="static/img/header.png" class="img-responsive center-block"
alt="A picture of the buttons along the top of the editor."/></p>
<p>Pressing the TAB key will move the focus between the buttons. Pressing
ENTER will activate the highlighted button. If you're in the text window
(see below) you'll need to press the ESCAPE key to re-focus on the buttons.
You can, of course, use your mouse.</p>
<p>What do they do?</p>
<table class="table">
<tr>
<td>
<img src="static/img/download.png" alt="Download button"/>
</td>
<td>
Click on the "Download" button to save a special "hex" file on
your computer. Plug in your BBC micro:bit (it'll show up as USB
storage) and drag the newly saved file onto the device. Your code
will run (or you'll see an error message scroll past on the
device's display). See below for how to extract your code from a
hex file back into the editor.
</td>
</tr>
<tr>
<td>
<img src="static/img/save.png" alt="Save button"/>
</td>
<td>
Click on the "Save" button to save your code onto your computer.
Because you're downloading Python code your computer might check
you want to save the file. It's trying to protect you from
downloading random software from the internet. But since this is
your own code you're safe to proceed. See below for how to load
code back into the editor.
</td>
</tr>
<tr>
<td>
<img src="static/img/load.png" alt="Load button"/>
</td>
<td>
It's very easy to load files from your computer into the editor:
click the load button then drag the file from your computer onto
the grey "drop" area. Alternatively, you could use the file
picker (just click on the link at the bottom to toggle between the
two options). The editor knows how to read Python files (whose name
ends with ".py") and extract Python code from hex files (whose name
ends with ".hex").
</td>
</tr>
<tr>
<td>
<img src="static/img/block_button.png" alt="Blockly button"/>
</td>
<td>
<strong>This is an experimental feature. It may change in future
and could contain bugs.</strong> Clicking the "Blockly" button
displays a set of drag-and-drop
blocks that can be used to quickly create Python code. Move the
blocks, watch Python code appear and change. <strong>Moving such
blocks will re-write your Python code and you may lose work.
Furthermore, the arrangement of blocks is currently not saved,
just the resulting Python code.</strong>
</td>
</tr>
<tr>
<td>
<img src="static/img/snippets.png" alt="Snippets button"/>
</td>
<td>
Clicking on the "Snippets" button brings up a menu of Python
short-cuts (snippets). Code snippets are short blocks of code to
re-use in your own programs. There are snippets for most common
things you'll want to do with Python. Select the one you want and
fill in the gaps in the code editor to make it do what you want.
<strong>Snippets are disabled when blockly is enabled.</strong>
</td>
</tr>
<tr>
<td>
<img src="static/img/help.png" alt="Help button"/>
</td>
<td>
Clicking on the "Help" button gets you here. But you knew that
already, right..? :-) Notice that your editor is still available
but in a separate tab in your browser.
</td>
</tr>
<tr>
<td>
<img src="static/img/share.png" alt="Share button"/>
</td>
<td>
Clicking on the "Share" button creates a unique link that points to
your script. Add this link to your bookmarks to retrieve your code.
If you share this link others will be able to see your code. So
your code remains private you must set a password and an optional
password hint for it. <strong>This button is not available if
you're running the editor from a local file system.</strong>
</td>
</tr>
<tr>
<td>
<img src="static/img/zoom.png" alt="Zoom buttons"/>
</td>
<td>
Everyone likes to show off their awesome Python skills. These
buttons are especially useful to zoom-in and zoom-out when you're
trying to show your code to a large group of people via a
projector.
</td>
</tr>
</table>
<p>The name and description for your script is shown on the top
right hand side. Click them to edit them.</p>
<p>The other part of the editor is the text window:</p>
<p><img src="static/img/editor_text.png"
class="img-responsive center-block img-rounded"
alt="A picture of the text area in the code editor."/></p>
<p>It's very simple to use. Just click and type.</p>
<p>The editor tries to help you out by colouring the text to show what
all the different parts of your program are. For example, Python keywords
(words built into the Python language) are grey. The brighter coloured
words are bits of the program <em>you</em> have created. Brown words
are constant values that never change and purple words represent
strings of characters to display. All the lines are numbered with the
current line highlighted.</p>
<p>Do you want to see how the editor actually works? It's easy, to view
the "source code" press CTRL-U (or CMD-U on a Mac). There's a secret
message for you in the code. Can you find it?</p>
<img src="static/img/comic2.png" class="img-responsive center-block"
alt="http://goo.gl/ArpNbM"/>
<h2 id="hello">Hello, World!</h2>
<p><img src="static/img/comic3.png" class="img-responsive center-block"
alt="http://goo.gl/zpfrsY"/></p>
<p>The version of Python that runs on the BBC micro:bit is called
MicroPython. It's exactly like <em>real</em> Python except it's designed
to run on small devices like the BBC micro:bit. Here's the MicroPython code
you need to make your BBC micro:bit say "Hello, World!". Copy and paste it
into the Python editor, download it and copy it onto your device (just like
Yellow and Blue suggest):</p>
<pre><code class="python">from microbit import *
display.scroll("Hello, World!")</code></pre>
<p>The first line (<code>from microbit import *</code>) tells MicroPython
to get all the bits of Python needed to program the micro:bit.</p>
<p>The second line(<code>display.scroll("Hello, World!")</code>) tells
MicroPython to use one of those bits of Python (the <code>display</code>
module) to scroll the text, <kbd>"Hello, World!"</kbd> across the physical
display on the front of the device. It's all remarkably obvious. If you
followed Yellow and Blue's instructions you should see something like
this:</p>
<p><img src="static/img/scroll-hello.gif" class="img-responsive center-block img-rounded"
alt="An animation of 'hello world' scrolling over the display."/></p>
<p>Can you make it scroll any other messages? Why not try making your
BBC micro:bit scroll your name? Remember, MicroPython will scroll
everything between the <code>"</code>quotation marks<code>"</code>.</p>
<h2 id="blockly">Blockly</h2>
<p>Use blockly to make new Python code from easy to assemble blocks of
code.</p>
<p><img src="static/img/blocks.png"
class="img-responsive center-block img-rounded"
alt="An animation demonstrating how to use snippets."/></p>
<p>Blockly updates Python in the code editor as you move blocks around.
There are lots of different blocks to cover all the features of the
micro:bit. You can make more advanced code by combining blocks together
(such as in the example above).</p>
<p>You should use Blockly to create <em>new code</em> since moving blocks
around will overwrite any existing code you have in the editor (and you may
lose work as a result). The arrangement of blocks isn't (currently)
saved, so Blockly makes a great way to make simple Python code without
lots of typing. In the end, you'll learn that simply typing Python is by
far the quickest and easiest way to write code.</p>
<p>Not all the features of the micro:bit or MicroPython are available via
Blockly. We've done this on purpose. Some of the more advanced and
interesting stuff is only available in pure Python.</p>
<p>However, by using Blockly you'll very quickly get the hang of how Python
code works and fits together.</p>
<h2 id="snippets">Snippets</h2>
<p>Snippets are a cool way to avoid typing. The animation below shows you
how to use them:</p>
<p><img src="static/img/snippet_example.gif"
class="img-responsive center-block img-rounded"
alt="An animation demonstrating how to use snippets."/></p>
<p>You can access snippets from the "Snippets" button (see above), but
it's a lot quicker and easier to learn the <em>triggers</em> for the
different fragments of code, hit the <kbd>TAB</kbd> key to expand the
snippet and then fill in the remaining blocks of code so it does what you
want.</p>
<p>When blockly is enabled the "Snippets" button is disabled. This avoids
snippets from interfering with code that blockly may be generating.</p>
<p><img src="static/img/comic4.png" class="img-responsive center-block"
alt="http://goo.gl/bT8a8M"/></p>
<h2 id="bugs">Bug Fixes</h2>
<p>Things will go wrong!</p>
<p>You have to imagine Python is the most strict English teacher in the
universe... yes, even more strict than that really strict one you have at
your school. Put simply, <strong>you have to type Python without any
mistakes</strong> for it to work.</p>
<p>All programmers make mistakes and create bugs. It's a fact of life.
When you have a bug MicroPython tries to help you out: it will scroll a
message on its display. It may even include a line number. This message is
like the first clue in a treasure hunt, you have to figure out the rest
yourself.</p>
<p>Common bugs include <em>Syntax Errors</em> (which means you've typed it in
wrong) and <em>Name Errors</em> (that mean you've typed in correct Python, but
it can't work out what you're coding about).</p>
<p>If you're unsure what to do
<a href="https://microbit-micropython.readthedocs.io/en/latest/">go read the
MicroPython docs</a>. Alternatively, just ask someone who knows what they're
doing. If no such person is available you could just follow this handy flow
chart:</p>
<p><img src="static/img/tech_support_cheat_sheet.png"
class="img-responsive center-block"
alt="The XKCD tech support cheat sheet."/></p>
<h2 id="fun">Fun Stuff</h2>
<p><img src="static/img/comic5.png" class="img-responsive center-block"
alt="http://goo.gl/q5DAAW"/></p>
<p>Python makes it simple to write powerful programs. Can you work out what
this program does?</p>
<pre><code class="python"># Press button A for a fortune cookie.
from microbit import *
import random
fortunes = [
"Never step off a moving bus",
"This sentence is false",
"The meaning of life is overrated",
"Do not touch!",
"You will receive some advice",
"My hovercraft is full of eels",
]
while True:
if button_a.is_pressed():
cookie = random.choice(fortunes)
display.scroll(cookie)</code></pre>
<p>How could you improve it? What changes could you make?</p>
<p><img src="static/img/comic6.png" class="img-responsive center-block"
alt="http://goo.gl/9lcLAf"/></p>
<p>If you're looking for inspiration (robots, cool light displays and goofy
games) you should check out the
<a href="http://microworldtour.github.io/">World Tour</a>. These projects
were created by volunteers from the global Python community (of which you're
now a member!).</p>
<footer style="text-align: center; margin-top: 64px;">
<p>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons Licence" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/80x15.png" /></a> This work by <a xmlns:cc="http://creativecommons.org/ns#" href="http://python.org/community/microbit/" property="cc:attributionName" rel="cc:attributionURL">The Python Software Foundation</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
</p>
<p>The flowchart comic from XKCD is covered by <a href="https://xkcd.com/license.html">this license</a> and used with thanks to Randall Munroe.</p>
</footer>
</div><!-- /.container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="static/js/jquery-2.1.4.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="static/js/ie10-viewport-bug-workaround.js"></script>
<script src="static/js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>