Skip to content

Commit 0f53bde

Browse files
committed
翻译为中文
其实应该新建中文分支
1 parent 739da92 commit 0f53bde

File tree

2 files changed

+92
-81
lines changed

2 files changed

+92
-81
lines changed

buzzer.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
# Buzzers
1+
# 蜂鸣器
22

3-
There are two main types of buzzer: *active* and *passive*.
3+
蜂鸣器有两种: *有源蜂鸣器* and *无源蜂鸣器*
4+
The *active* buzzers are a lot simpler to use, so these are covered here.
5+
*无源蜂鸣器*输入电压就会发声。需要特定的信号来产生多样的音调。*有源蜂鸣器*更容易使用,介绍如下。
46

5-
A *passive* buzzer emits a tone when a voltage is applied across it. It also requires a specific signal to generate a variety of tones. The *active* buzzers are a lot simpler to use, so these are covered here.
7+
## 连接蜂鸣器
68

7-
## Connecting a buzzer
9+
有源蜂鸣器用起来就像LED一样,但是有源蜂鸣器更加稳健,不需要串联电阻来保护有源蜂鸣器:
810

9-
An *active* buzzer can be connected just like an LED, but as they are a little more robust, you won't be needing a resistor to protect them.
10-
11-
Set up the circuit as shown below:
11+
按照下图连接电路:
1212

1313
![buzzer](images/buzzer-circuit.png)
1414

15-
1. Add `Buzzer` to the `from gpiozero import...` line:
15+
1. 导入 `Buzzer` to the `from gpiozero import...` :
1616

1717
```python
1818
from gpiozero import Buzzer
1919
from time import sleep
2020
```
2121

22-
1. Add a line below your creation of `button` and `lights` to add a `Buzzer` object:
22+
1. 在你创建按钮和灯后面添加`Buzzer`对象。:
2323

2424
```python
2525
buzzer = Buzzer(17)
2626
```
2727

28-
1. In GPIO Zero, a `Buzzer` works exactly like an `LED`, so try adding a `buzzer.on()` and `buzzer.off()` into your loop:
28+
1. GPIO Zero库中,`Buzzer`就像一个`LED`,在循环中试着添加`buzzer.on()` and `buzzer.off()`:
2929

3030
```python
3131
while True:
@@ -36,13 +36,13 @@ Set up the circuit as shown below:
3636

3737
```
3838

39-
1. A `Buzzer` has a `beep()` method which works like an `LED`'s `blink`. Try it out:
39+
1. A `Buzzer` has a `beep()` method which works like an `LED`'s `blink`. `Buzzer`类有一个方法`beep()`类似于`LED`的`blink`。试试看:
4040

4141
```python
4242
while True:
4343
buzzer.beep()
4444
```
4545

46-
## What Next?
46+
## 拓展延伸?
4747

48-
- Continue to the next worksheet on building a [traffic lights](trafficlights.md) system using GPIO Zero.
48+
- 到下一个学习单学习用GPIO Zero打造[交通灯](trafficlights.md) 系统.

worksheet.md

Lines changed: 79 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,94 @@
1-
# Getting started with physical computing
1+
# 物理计算入门
22

3-
## GPIO pins
3+
## GPIO 引脚
44

5-
One powerful feature of the Raspberry Pi is the row of GPIO pins along the top edge of the board. GPIO stands for General-Purpose Input/Output. These pins are a physical interface between the Raspberry Pi and the outside world. At the simplest level, you can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output).
5+
7树莓派强大的特性之一的呢就是板子上面边缘的两行GPIO引脚。GPIO是通用输入输出的缩写。这些针脚是树莓派与外部世界的物理接口。最简单的说就是你可以把这些针脚当做你能够打开或者关闭的用来输入的开关或者Pi本身可以打开关闭的输出开关。
66

7-
The GPIO pins allow the Raspberry Pi to control and monitor the outside world by being connected to electronic circuits. The Pi is able to control LEDs, turning them on or off, run motors, and many other things. It's also able to detect whether a switch has been pressed, the temperature, and light. We refer to this as physical computing.
87

9-
There are 40 pins on the Raspberry Pi (26 pins on early models), and they provide various different functions.
8+
GPIO引脚使得树莓派通过连接电路来控制和检测外部世界。树莓派能够控制多个LED灯,控制lED灯的打开关闭,运行电机,以及其他的事情。还能够检测一个按钮是否被按下,检测温度和光照强度。我们把这些操作称之为物理计算。
9+
10+
11+
树莓派有40个引脚(早期版本有26个引脚),提供了多种多样的功能。
12+
13+
如果你有一个树莓派引脚标签RasPiO,能够帮助你明确每个针脚的用途。确保面对USB接口的时候你的针脚标签的孔是在外侧的。
1014

11-
If you have a RasPiO pin label, it can help to identify what each pin is used for. Make sure your pin label is placed with the keyring hole facing the USB ports, pointed outwards.
1215

1316
![](images/raspio-ports.jpg)
1417

15-
If you don't have a pin label, then this guide can help you to identify the pin numbers:
18+
如果你没有引脚标签的话,下面的示意图可以帮助你确定引脚编号
1619

1720
![](images/pinout.png)
1821

19-
You'll see pins labelled as 3V3, 5V, GND and GP2, GP3, etc:
22+
你可以看到引脚有3V3,5V,GND,GP2,GP3等标签:
23+
2024

2125
| | | |
2226
|---|---|---|
23-
| 3V3 | 3.3 volts | Anything connected to these pins will always get 3.3V of power |
24-
| 5V | 5 volts | Anything connected to these pins will always get 5V of power |
25-
| GND | ground | Zero volts, used to complete a circuit |
26-
| GP2 | GPIO pin 2 | These pins are for general-purpose use and can be configured as input or output pins |
27-
| ID_SC/ID_SD/DNC | Special purpose pins ||
27+
| 3V3 | 3.3V | 链接到这个引脚可以得到3.3V电压 |
28+
| 5V | 5V | 连接到这个引脚可以得到5V电压 |
29+
| GND | 接地 | 0V接地用来完成电路 |
30+
| GP2 | GPIO 针脚 2 | 这些针脚是通用针脚,可以配置为输入或者输出针脚 |
31+
| ID_SC/ID_SD/DNC | 特殊用途引脚
32+
||
2833

29-
**WARNING**: If you follow the instructions, then playing about with the GPIO pins is safe and fun. Randomly plugging wires and power sources into your Pi, however, may destroy it, especially if using the 5V pins. Bad things can also happen if you try to connect things to your Pi that use a lot of power; LEDs are fine, motors are not. If you're worried about this, then you might want to consider using an add-on board such as the [Explorer HAT](https://shop.pimoroni.com/products/explorer-hat) until you're confident enough to use the GPIO directly.
34+
**警告**: 如果你严格按照本文教程来,玩耍GPIO引脚将会是一个好玩并且有趣的过程。但是如果你随便连接电线,可能会毁掉树莓派,尤其是你使用5V引脚的时候。当你把大负载的元件连接到树莓派的时候可能会发生不愉快的事情,LED灯是没有问题的,电机可能会有问题。如果你担心损坏树莓派,可以考虑使用诸如[Explorer HAT](https://shop.pimoroni.com/products/explorer-hat)扩展板,直到你能够自信的熟练直接使用GPIO。这个扩展板有电路保护功能防止烧毁树莓派。也可以利用检测开关功能做一个电流急急棒。
3035

31-
## Lighting an LED
36+
## 点亮LED灯
3237

33-
LEDs are delicate little things. If you put too much current through them they will pop (sometimes quite spectacularly). To limit the current going through the LED, you should always use a resistor in series with it.
38+
LED等是很容易被烧坏的小元件。如果电流过大就会炸裂,有时候会让你大吃一惊。为了限制流经LED的电流,你应该在电路里串联一个电阻。突然想到很想买PM2.5传感器和甲醛传感器。
3439

35-
Try connecting the long leg of an LED to the Pi's 3V3 and the short leg to a GND pin. The resistor can be anything over about 50Ω.
40+
把LED灯长的针脚接到3V3这个引脚,然后把短针脚接到GND引脚。电阻可以是大于50Ω的任意电阻。
3641

3742
![](images/led-3v3.png)
3843

39-
The LED should light up. It will always be on, because it's connected to a 3V3 pin, which is itself always on.
44+
这样的话LED就会亮起来,会一直亮,因为LED灯链接的3V3接口会一直是打开的。
4045

41-
Now try moving it from 3V3 to GPIO pin 17:
4246

47+
现在尝试把LED灯长的针脚从3V3接口重新连接到17号GPIO引脚。
4348
![](images/led-gpio17.png)
4449

45-
The LED should now turn off, but now it's on a GPIO pin, and can therefore be controlled by code.
50+
LED灯现在就灭了,因为现在连接到了可以用代码控制通断的GPIO接口
4651

47-
## Switching an LED on and off
52+
## 控制LED亮暗
4853

49-
GPIO Zero is a new Python library which provides a simple interface to everyday GPIO components. It comes installed by default in Raspbian.
54+
>Pi Zero比Arduino便宜,所以以后中学阶段可以用Pi Zero做机器人。
5055
51-
1. Open IDLE from the main menu (`Menu`>`Programming`>`Python 3 (IDLE)`.
56+
GPIO Zero是一个让我们可以用一种简单的方式来控制常见的GPIO元件的新的Python代码库。Raspbian默认安装了GPIO Zero代码库。
5257

53-
1. You can switch an LED on and off by typing commands directly into the Python interpreter window (also known as the Python **shell**). Let's do this by first importing the GPIO Zero library. You also need to tell the Pi which GPIO pin you are using - in this case pin 17. Next to the chevrons `>>>`, type:
58+
1. 从主菜单打开IDLE(`菜单`>`编程`>`Python 3 (IDLE)`.
5459

55-
```python
60+
1.你可以通过直接在Python解释器里输入命令来控制LED的亮暗。(或者说Python **shell**). Let's do this by first importing the GPIO Zero library.在控制LED等之前首先导入GPIO Zero库。你还需要告诉树莓派你正在用哪个针脚-这个例子用的是17号针脚。紧接着大于号 `>>>`, 输入
61+
62+
```python
5663
from gpiozero import LED
5764
led = LED(17)
5865

5966
```
60-
Press **Enter** on the keyboard.
67+
**回车**.
6168

62-
1. To make the LED switch on, type the following and press **Enter**:
69+
1. 为了让LED亮起来,输入下面代码并敲 **Enter**:
6370

6471
```python
6572
led.on()
6673
```
6774

68-
1. To make it switch off you can type:
75+
1. 让LED灭可以输入:
6976

7077
```python
7178
led.off()
7279
```
7380

74-
1. Your LED should switch on and then off again. But that's not all you can do.
81+
1. Your LED should switch on and then off again. But that's not all you can do.LED就会先亮后灭,但是你能做的不止于此。
7582

76-
## Flashing an LED
83+
## 让LED闪烁
7784

78-
With the help of the `time` library and a little loop, you can make the LED flash.
85+
通过使用`time`库,和一个简单的循环,我们可以让LED不断闪烁。
7986

80-
1. Create a new file by clicking **File > New file**.
87+
1. 单击 **文件 > 新建文件**创建新的Python文件.
8188

82-
1. Save the new file by clicking **File > Save**. Save the file as `gpio_led.py`.
89+
1. 单击 **文件 > 保存**保存文件为`gpio_led.py`.
8390

84-
1. Enter the following code to get started:
91+
1. 输入以下代码:
8592

8693
```python
8794
from gpiozero import LED
@@ -96,47 +103,48 @@ With the help of the `time` library and a little loop, you can make the LED flas
96103
sleep(1)
97104
```
98105

99-
1. Save with **Ctrl + S** and run the code with **F5**.
106+
1. **Ctrl + S** 保存文件并按 **F5** 执行代码.
100107

101-
1. The LED should be flashing on and off. To exit the program press **Ctrl + C** on your keyboard.
108+
1. LED灯开始闪烁. 按 **Ctrl + C** 退出程序.
102109

103-
## Using buttons to get input
110+
## 利用按钮获取输入
104111

105-
Now you're able to control an output component (an LED), let's connect and control an input component: a button.
112+
现在你可以控制输出元件(一个LED),现在让我们连接并控制一个输入元件:按钮。
106113

107-
1. Connect a button to another GND pin and GPIO pin 2, like this:
114+
115+
1. 按图把一个按钮连接到另外一个GND引脚和2GPIO引脚:
108116

109117
![](images/button.png)
110118

111-
1. Create a new file by clicking **File > New file**.
119+
1. 点击 **File > New file**新建文件.
112120

113-
1. Save the new file by clicking **File > Save**. Save the file as `gpio_button.py`.
121+
1. 点击 **File > Save**. 把新建文件保存为 `gpio_button.py`.
114122

115-
1. This time you'll need the `Button` class, and to tell it that the button is on pin 2. Write the following code in your new file:
123+
1. 现在你需要使用`Button`类,并且告诉该类按钮连接到了2号引脚。输入以下代码到你新建的文件:
116124

117125
```python
118126
from gpiozero import Button
119127
button = Button(2)
120128
```
121129

122-
1. Now you can get your program to do something when the button is pushed. Add these lines:
130+
1. 现在当按钮按下的时候你的程序就可以做一些事情。添加以下代码:
123131

124132
```python
125133
button.wait_for_press()
126-
print('You pushed me')
134+
print('你按我了')
127135
```
128-
1. Save with **Ctrl + S** and run the code with **F5**.
129-
1. Press the button and your text will appear.
136+
1. **Ctrl + S** 保存代码并按 **F5**执行代码.
137+
1. 单击按钮文本就会出现.
130138

131-
## Manually controlling the LED
139+
## 手动控制LED
132140

133-
You can now combine your two programs written so far to control the LED using the button.
141+
You can now combine your two programs written so far to control the LED using the button.现在可以目前为止写的两个程序结合起来通过按钮来控制LED
134142

135-
1. Create a new file by clicking **File > New file**.
143+
1. 单击 **File > New file**新建文件.
136144

137-
1. Save the new file by clicking **File > Save**. Save the file as `gpio_control.py`.
145+
1. 单击 **File > Save**保存文件为 `gpio_control.py`.
138146

139-
1. Now write the following code:
147+
1. 输入以下代码:
140148

141149
```python
142150
from gpiozero import LED, Button
@@ -151,13 +159,13 @@ You can now combine your two programs written so far to control the LED using th
151159
led.off()
152160
```
153161

154-
1. Save and run your program. When you push the button the LED should come on for three seconds.
162+
1. 保存并运行程序。当你按按钮的时候LED持续亮3秒然后灭掉。
155163

156-
## Making a switch
164+
## 制作一个开关
157165

158-
With a switch, a single press and release on the button would turn the LED on, and another press and release would turn it off again.
166+
通过开关,按下和松开按钮一次就会点亮LED,再次按下和松开就会关掉LED
159167

160-
1. Modify your code so that it looks like this:
168+
1. 修改程序如下:
161169

162170
```python
163171
from gpiozero import LED, Button
@@ -171,11 +179,12 @@ With a switch, a single press and release on the button would turn the LED on, a
171179
led.toggle()
172180
```
173181

174-
`led.toggle()` switches the state of the LED from on to off, or off to on. Since this happens in a loop the LED with turn on and off each time the button is pressed.
182+
`led.toggle()` LED的状态从亮改为灭,从灭改为亮。因为在循环内调用函数,所以每次按按钮的是LED就会点亮或者关闭。
175183

176-
1. It would be great if you could make the LED switch on only when the button is being held down. With GPIO Zero, that's easy. There are two methods of the `Button` class called `when_pressed` and `when_released`. These don't block the flow of the program, so if they are placed in a loop, the program will continue to cycle indefinitely.
184+
1. These don't block the flow of the program, so if they are placed in a loop, the program will continue to cycle indefinitely.
185+
如果只有按钮按下的是LED才会亮是一个很好的注意。因为有了GPIO Zero这个变得很简单。`Button`类有两个方法分别是`when_pressed` and `when_released`。这两个方法不会阻塞程序的流程,所以即便你把这两个函数放到一个循环里,程序仍然会无限循环。
177186

178-
1. Modify your code to look like this:
187+
1. 修改代码如下:
179188

180189
```python
181190
from gpiozero import LED, Button
@@ -190,16 +199,18 @@ With a switch, a single press and release on the button would turn the LED on, a
190199
pause()
191200
```
192201

193-
1. Save and run the program. Now when the button is pressed, the LED will light up. It will turn off again when the button is released.
202+
>这种写法很明显比用Arduino要容易的多,电路也简单的多,充分的体现了Python语言简洁优雅,开发效率高的特点
203+
204+
1. Save and run the program. Now when the button is pressed, the LED will light up. It will turn off again when the button is released.保持并运行程序,现在按下按钮,LED亮;松开按钮,LED灭。
194205

195-
## What next?
206+
## 接下来学习啥?
196207

197-
There are lots of other things you can control or monitor with your Raspberry Pi. Have a look at the worksheets below, to see how easily this can be done.
208+
通过树莓派你可以控制和监测大量其他的元件。看看下面的列表,就会明白这很容易。
198209

199-
- [Using an active buzzer](buzzer.md)
200-
- [Making traffic lights](trafficlights.md)
201-
- [Using a light-dependent resistor](ldr.md)
202-
- [Using a PIR Sensor](pir.md)
203-
- [Using an ultrasonic distance sensor](distance.md)
204-
- [Analogue inputs](analogue.md)
205-
- [Using motors](motors.md)
210+
- [控制蜂鸣器](buzzer.md)
211+
- [制作交通灯](trafficlights.md)
212+
- [光敏电阻的使用](ldr.md)
213+
- [人体红外传感器的使用](pir.md)
214+
- [超声波距离传感器的使用](distance.md)
215+
- [模拟输入](analogue.md)
216+
- [使用电机](motors.md)

0 commit comments

Comments
 (0)