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
11+ :alt: micro:bit with pins labelled
912
1013Some of the pins are bigger than others so it's possible to attach crocodile
1114clips to them. These are the ones labelled 0, 1, 2, 3V and GND (computers
1215always start counting from zero). If you attach an edge connector board to the
1316device it's possible to plug in wires connected to the other (smaller) pins.
1417
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 ``.
18+ On the latest micro:bit **V2 ** the micro:bit logo can also be used as a touch
19+ input.
1820
19- Simple!
21+ In MicroPython, each pin on the BBC micro:bit is represented by an *object *
22+ called ``pinN ``, where ``N `` is the number pf the pin.
23+
24+ For example, to use the pin labelled 0 (zero), you can use the object called
25+ ``pin0 `` in your script. The logo pin **V2 ** uses ``pin_logo ``.
2026
2127These objects have various *methods * associated with them depending upon what
22- the specific pin is capable of.
28+ the specific pin is capable of eg. read, write or touch .
2329
2430Ticklish Python
2531+++++++++++++++
2632
2733The 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::
34+ touched. So, you can tickle your micro:bit to make it laugh like this::
2935
3036 from microbit import *
3137
@@ -35,26 +41,46 @@ touched. So, you can tickle your device to make it laugh like this::
3541 else:
3642 display.show(Image.SAD)
3743
38- With one hand, hold your device by the GND pin. Then, with your other hand,
44+ With one hand, hold your micro:bit by the GND pin. Then, with your other hand,
3945touch (or tickle) the 0 (zero) pin. You should see the display change from
4046grumpy to happy!
4147
48+ When you use the latest micro:bit **V2 ** you can also change the default
49+ behaviour of the pin, so that you don't have to touch GND at all.::
50+
51+ from microbit import *
52+ pin0.set_touch_mode(pin0.CAPACITIVE)
53+ while True:
54+ if pin0.is_touched():
55+ display.show(Image.HAPPY)
56+ else:
57+ display.show(Image.SAD)
58+
59+ The default for the edge connector pins is `resistive ` and the logo pin
60+ **V2 ** is `capacitive `.
61+
4262This is a form of very basic input measurement. However, the fun really starts
4363when you plug in circuits and other devices via the pins.
4464
4565Bleeps and Bloops
4666+++++++++++++++++
4767
48- The simplest thing we can attach to the device is a Piezo buzzer. We're going
68+ The simplest thing we can attach to the micro:bit is a Piezo buzzer. We're going
4969to use it for output.
5070
5171.. image :: piezo_buzzer.jpg
72+ :width: 250px
73+ :align: center
74+ :alt: piezo buzzer
5275
5376These small devices play a high-pitched bleep when connected to a circuit. To
5477attach one to your BBC micro:bit you should attach crocodile clips to pin 0 and
55- GND (as shown below) .
78+ GND.
5679
5780.. image :: pin0-gnd.png
81+ :width: 250px
82+ :align: center
83+ :alt: piezo connected to pin0 and GND
5884
5985The wire from pin 0 should be attached to the positive connector on the buzzer
6086and the wire from GND to the negative connector.
0 commit comments