1- Input/Output
2- ------------
1+ Input/Output Pins
2+ -----------------
33
44There are strips of metal along the bottom edge of the BBC micro:bit that make
55it look as if the device has teeth. These are the input/output pins (or I/O pins
66for short).
77
88.. image :: blue-microbit.png
9+ :width: 300px
10+ :align: center
911
1012Some of the pins are bigger than others so it's possible to attach crocodile
1113clips to them. These are the ones labelled 0, 1, 2, 3V and GND (computers
1214always start counting from zero). If you attach an edge connector board to the
1315device it's possible to plug in wires connected to the other (smaller) pins.
1416
15- Each pin on the BBC micro:bit is represented by an *object * called ``pinN ``
16- where ``N `` is the pin number. So, for example, to do things with the pin
17- labelled with a 0 (zero), use the object called ``pin0 ``.
17+ In MicroPython, each pin on the BBC micro:bit is represented by an *object *
18+ called ``pinN ``, where ``N `` is the number pf the pin.
1819
19- Simple!
20+ For example, to use the pin labelled 0 (zero), you can use the object called
21+ ``pin0 `` in your script.
2022
2123These objects have various *methods * associated with them depending upon what
22- the specific pin is capable of.
24+ the specific pin is capable of eg. read, write or touch .
2325
2426Ticklish Python
2527+++++++++++++++
2628
2729The simplest example of input via the pins is a check to see if they are
28- touched. So, you can tickle your device to make it laugh like this::
30+ touched. So, you can tickle your micro:bit to make it laugh like this::
2931
3032 from microbit import *
3133
@@ -35,7 +37,7 @@ touched. So, you can tickle your device to make it laugh like this::
3537 else:
3638 display.show(Image.SAD)
3739
38- With one hand, hold your device by the GND pin. Then, with your other hand,
40+ With one hand, hold your micro:bit by the GND pin. Then, with your other hand,
3941touch (or tickle) the 0 (zero) pin. You should see the display change from
4042grumpy to happy!
4143
@@ -45,8 +47,8 @@ when you plug in circuits and other devices via the pins.
4547Bleeps and Bloops
4648+++++++++++++++++
4749
48- The simplest thing we can attach to the device is a Piezo buzzer. There are two
49- types of piezo buzzers. The simplest type to use are called active buzzers.
50+ The simplest thing we can attach to the micro:bit is a Piezo buzzer. There are
51+ two types of piezo buzzers. The simplest type to use are called active buzzers.
5052Active buzzers contain an oscillator that produces a tone at a predetermined
5153pitch when a current is passed through them. Passive buzzers require an
5254oscillating current to be passed through them to produce a tone at the frequency
@@ -55,11 +57,17 @@ one tone, while passive buzzers are slightly more complicated to use but can
5557produce a variety of tones.
5658
5759.. image :: piezo_buzzer.jpg
60+ :width: 250px
61+ :align: center
62+ :alt: piezo buzzer
5863
5964We're going to use an active piezo buzzer for output. To attach one to your BBC
6065micro:bit you should attach crocodile clips to pin 0 and GND (as shown below).
6166
6267.. image :: pin0-gnd.png
68+ :width: 250px
69+ :align: center
70+ :alt: piezo connected to pin0 and GND
6371
6472The wire from pin 0 should be attached to the positive connector on the buzzer
6573and the wire from GND to the negative connector.
0 commit comments