diff --git a/docs/tutorials/blue-microbit.png b/docs/tutorials/blue-microbit.png index 82368998f..7c806e83f 100644 Binary files a/docs/tutorials/blue-microbit.png and b/docs/tutorials/blue-microbit.png differ diff --git a/docs/tutorials/happy.png b/docs/tutorials/happy.png index d0ebe7b49..2c57292be 100644 Binary files a/docs/tutorials/happy.png and b/docs/tutorials/happy.png differ diff --git a/docs/tutorials/images.rst b/docs/tutorials/images.rst index eb7d29136..1d71bf101 100644 --- a/docs/tutorials/images.rst +++ b/docs/tutorials/images.rst @@ -18,6 +18,8 @@ display is a part of the ``Image`` object and called ``HAPPY``. We tell ``show`` to use it by putting it between the parenthesis (``(`` and ``)``). .. image:: happy.png + :width: 300px + :align: center Here's a list of the built-in images: diff --git a/docs/tutorials/io.rst b/docs/tutorials/io.rst index 3d712b8ef..6a51228e8 100644 --- a/docs/tutorials/io.rst +++ b/docs/tutorials/io.rst @@ -1,31 +1,37 @@ -Input/Output ------------- +Input/Output Pins +----------------- There are strips of metal along the bottom edge of the BBC micro:bit that make it look as if the device has teeth. These are the input/output pins (or I/O pins for short). .. image:: blue-microbit.png + :width: 300px + :align: center + :alt: micro:bit with pins labelled Some of the pins are bigger than others so it's possible to attach crocodile clips to them. These are the ones labelled 0, 1, 2, 3V and GND (computers always start counting from zero). If you attach an edge connector board to the device it's possible to plug in wires connected to the other (smaller) pins. -Each pin on the BBC micro:bit is represented by an *object* called ``pinN`` -where ``N`` is the pin number. So, for example, to do things with the pin -labelled with a 0 (zero), use the object called ``pin0``. +On the latest micro:bit **V2** the micro:bit logo can also be used as a touch +input. -Simple! +In MicroPython, each pin on the BBC micro:bit is represented by an *object* +called ``pinN``, where ``N`` is the number pf the pin. + +For example, to use the pin labelled 0 (zero), you can use the object called +``pin0`` in your script. The logo pin **V2** uses ``pin_logo``. These objects have various *methods* associated with them depending upon what -the specific pin is capable of. +the specific pin is capable of eg. read, write or touch. Ticklish Python +++++++++++++++ The simplest example of input via the pins is a check to see if they are -touched. So, you can tickle your device to make it laugh like this:: +touched. So, you can tickle your micro:bit to make it laugh like this:: from microbit import * @@ -35,26 +41,46 @@ touched. So, you can tickle your device to make it laugh like this:: else: display.show(Image.SAD) -With one hand, hold your device by the GND pin. Then, with your other hand, +With one hand, hold your micro:bit by the GND pin. Then, with your other hand, touch (or tickle) the 0 (zero) pin. You should see the display change from grumpy to happy! +When you use the latest micro:bit **V2** you can also change the default +behaviour of the pin, so that you don't have to touch GND at all.:: + + from microbit import * + pin0.set_touch_mode(pin0.CAPACITIVE) + while True: + if pin0.is_touched(): + display.show(Image.HAPPY) + else: + display.show(Image.SAD) + +The default for the edge connector pins is `resistive` and the logo pin +**V2** is `capacitive`. + This is a form of very basic input measurement. However, the fun really starts when you plug in circuits and other devices via the pins. Bleeps and Bloops +++++++++++++++++ -The simplest thing we can attach to the device is a Piezo buzzer. We're going +The simplest thing we can attach to the micro:bit is a Piezo buzzer. We're going to use it for output. .. image:: piezo_buzzer.jpg + :width: 250px + :align: center + :alt: piezo buzzer These small devices play a high-pitched bleep when connected to a circuit. To attach one to your BBC micro:bit you should attach crocodile clips to pin 0 and -GND (as shown below). +GND. .. image:: pin0-gnd.png + :width: 250px + :align: center + :alt: piezo connected to pin0 and GND The wire from pin 0 should be attached to the positive connector on the buzzer and the wire from GND to the negative connector. diff --git a/docs/tutorials/music.rst b/docs/tutorials/music.rst index e50e9913e..6c789c73d 100644 --- a/docs/tutorials/music.rst +++ b/docs/tutorials/music.rst @@ -2,17 +2,21 @@ Music ----- MicroPython on the BBC micro:bit comes with a powerful music and sound module. -It's very easy to generate bleeps and bloops from the device *if you attach a -speaker*. Use crocodile clips to attach pin 0 and GND to the positive and -negative inputs on the speaker - it doesn't matter which way round they are -connected to the speaker. +It's very easy to generate bleeps and bloops from the device by attaching a +speaker or set of wired headphones, or by using the built-in speaker **V2**. + +If you are attaching a speaker/headphones, you can use crocodile clips to +attach pin 0 and GND to the positive and negative inputs on the speaker. .. image:: pin0-gnd.png + :width: 250px + :align: center + :alt: piezo connected to pin0 and GND .. note:: - Do not attempt this with a Piezo buzzer - such buzzers are only able to - play a single tone. + Do not attempt this with an active Piezo buzzer - such buzzers are only + able to play a single tone. Let's play some music:: diff --git a/docs/tutorials/piezo_buzzer.jpg b/docs/tutorials/piezo_buzzer.jpg index 0b60f80de..00dbfda38 100644 Binary files a/docs/tutorials/piezo_buzzer.jpg and b/docs/tutorials/piezo_buzzer.jpg differ diff --git a/docs/tutorials/pin0-gnd.png b/docs/tutorials/pin0-gnd.png index 056269f01..a0d2b77ca 100644 Binary files a/docs/tutorials/pin0-gnd.png and b/docs/tutorials/pin0-gnd.png differ diff --git a/docs/tutorials/speech.rst b/docs/tutorials/speech.rst index ef46700e8..acb6b459f 100644 --- a/docs/tutorials/speech.rst +++ b/docs/tutorials/speech.rst @@ -1,18 +1,6 @@ Speech ------ -.. warning:: - - WARNING! THIS IS ALPHA CODE. - - We reserve the right to change this API as development continues. - - The quality of the speech is not great, merely "good enough". Given the - constraints of the device you may encounter memory errors and / or - unexpected extra sounds during playback. It's early days and we're - improving the code for the speech synthesiser all the time. Bug reports - and pull requests are most welcome. - Computers and robots that talk feel more "human". So often we learn about what a computer is up to through a graphical user @@ -42,9 +30,14 @@ In any case, we're going to create a DALEK poetry recital on demand. Say Something +++++++++++++ -Before the device can talk you need to plug in a speaker like this: +If you have the latest micro:bit **V2** device, you can use the built-in +speaker as well as or instead of connecting a speaker or set of headphones +like this: -.. image:: ../speech.png +.. image:: pin0-gnd.png + :width: 250px + :align: center + :alt: piezo connected to pin0 and GND The simplest way to get the device to speak is to import the ``speech`` module and use the ``say`` function like this:: @@ -58,10 +51,10 @@ change some of the parameters that the speech synthesiser uses to produce the voice. Our speech synthesiser is quite powerful in this respect because we can change four parameters: -* ``pitch`` - how high or low the voice sounds (0 = high, 255 = Barry White) -* ``speed`` - how quickly the device talks (0 = impossible, 255 = bedtime story) -* ``mouth`` - how tight-lipped or overtly enunciating the voice sounds (0 = ventriloquist's dummy, 255 = Foghorn Leghorn) -* ``throat`` - how relaxed or tense is the tone of voice (0 = falling apart, 255 = totally chilled) +* ``pitch`` - how high or low the voice sounds (0 = high, 255 = low) +* ``speed`` - how quickly the device talks (0 = fast, 255 = slow) +* ``mouth`` - how tight-lipped or overtly enunciating the voice sounds (0 = closed mouth, 255 = open mouth) +* ``throat`` - how relaxed or tense is the tone of voice (0 = tense, 255 = relaxed) Collectively, these parameters control the quality of sound - a.k.a. the timbre. To be honest, the best way to get the tone of voice you want is to