Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ depending upon the digital reading on pin 0::
display.show(Image.HAPPY)
else:
display.show(Image.SAD)


Pin Functions
=============
Expand Down
Binary file modified docs/tutorials/blue-microbit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/happy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/tutorials/images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
48 changes: 37 additions & 11 deletions docs/tutorials/io.rst
Original file line number Diff line number Diff line change
@@ -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 *

Expand All @@ -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.
Expand Down
16 changes: 10 additions & 6 deletions docs/tutorials/music.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
Binary file modified docs/tutorials/piezo_buzzer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/tutorials/pin0-gnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 11 additions & 18 deletions docs/tutorials/speech.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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::
Expand All @@ -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
Expand Down