Skip to content

Commit 09ce5a3

Browse files
committed
radio updated
1 parent 6f8ee7e commit 09ce5a3

9 files changed

Lines changed: 225 additions & 18 deletions

File tree

‎10_sound.md‎

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@ MicroPython on the BBC micro:bit can play music and sound through the built-in s
2020

2121
### Built-in tunes
2222

23-
Notice that we import the music module. It contains methods used to make and control sound. For example:
23+
Notice that we import the music module. It contains methods used to make and control sound.
24+
25+
1. Stop and close the current **main.py** file.
26+
2. Navigate to the **15_music_builtin** folder in Thonny and open the **main.py** file.
27+
28+
You should see the code below:
2429

2530
```{literalinclude} ./python_files/15_music_builtin/main.py
2631
:linenos:
2732
```
2833

34+
1. **Predict** what you think will happen. Be specific.
35+
2. **Run** the program.
36+
3. Time to **investigate** the code. What does each line do?
37+
2938
```{admonition} Code explanation
3039
:class: notice
3140
- **line 3** → imports the music module
@@ -57,12 +66,21 @@ NOTE[octave][:duration]
5766

5867
For example, `"A1:4"` means note `A`, octave `1`, duration `4`.
5968

60-
Make a list of notes to create a melody. This is similar to creating an animation with a list of images. For example, this code plays the opening of "Frere Jacques":
69+
Make a list of notes to create a melody. This is similar to creating an animation with a list of images. For example, this code plays the opening of "Frere Jacques".
70+
71+
1. Stop and close the current **main.py** file.
72+
2. Navigate to the **15_music_custom** folder in Thonny and open the **main.py** file.
73+
74+
You should see the code below:
6175

6276
```{literalinclude} ./python_files/15_music_custom/main.py
6377
:linenos:
6478
```
6579

80+
1. **Predict** what you think will happen. Be specific.
81+
2. **Run** the program.
82+
3. Time to **investigate** the code. What does each line do?
83+
6684
```{admonition} Code explanation
6785
:class: notice
6886
- **line 3** → imports the music module
@@ -72,14 +90,23 @@ Make a list of notes to create a melody. This is similar to creating an animatio
7290

7391
### Sound Effects
7492

75-
MicroPython lets you make tones that are not musical notes. For example, this code creates a siren sound effect:
93+
MicroPython lets you make tones that are not musical notes.
94+
95+
1. Stop and close the current **main.py** file.
96+
2. Navigate to the **15_music_sound_effects** folder in Thonny and open the **main.py** file.
97+
98+
You should see the code below, which creates a siren sound effect:
7699

77100
```{literalinclude} ./python_files/15_music_sound_effects/main.py
78101
:linenos:
79102
```
80103

81104
This example uses the `music.pitch()` method. It needs a frequency. For example, `440` is the frequency of the note A used by many musicians when tuning instruments.
82105

106+
1. **Predict** what you think will happen. Be specific.
107+
2. **Run** the program.
108+
3. Time to **investigate** the code. What does each line do?
109+
83110
```{admonition} Code explanation
84111
:class: notice
85112
- **line 3** → imports the music module
@@ -101,12 +128,21 @@ Full details can be found at the **[BBC micro:bit MicroPython Speech documentati
101128

102129
### Say
103130

104-
The simplest way to get the micro:bit to speak is to import the speech module and use the `say()` function like this:
131+
The simplest way to get the micro:bit to speak is to import the speech module and use the `say()`.
132+
133+
1. Stop and close the current **main.py** file.
134+
2. Navigate to the **15_speech_say** folder in Thonny and open the **main.py** file.
135+
136+
You should see the code below:
105137

106138
```{literalinclude} ./python_files/15_speech_say/main.py
107139
:linenos:
108140
```
109141

142+
1. **Predict** what you think will happen. Be specific.
143+
2. **Run** the program.
144+
3. Time to **investigate** the code. What does each line do?
145+
110146
```{admonition} Code explanation
111147
:class: notice
112148
- **line 3** → imports the speech module
@@ -124,12 +160,19 @@ Together, these settings control the **timbre** of the voice. Timbre means the s
124160

125161
To adjust the settings, pass them into the `say()` function. **[More details can be found in the speech module API documentation](https://microbit-micropython.readthedocs.io/en/latest/speech.html#timbre)**.
126162

163+
1. Stop and close the current **main.py** file.
164+
2. Navigate to the **15_speech_say_2** folder in Thonny and open the **main.py** file.
165+
127166
This example changes the voice settings:
128167

129168
```{literalinclude} ./python_files/15_speech_say_2/main.py
130169
:linenos:
131170
```
132171

172+
1. **Predict** what you think will happen. Be specific.
173+
2. **Run** the program.
174+
3. Time to **investigate** the code. What does each line do?
175+
133176
```{admonition} Code explanation
134177
:class: notice
135178
- **line 3** → imports the speech module
@@ -145,12 +188,19 @@ When you use phonemes, you write the word the way it sounds, not the way it is n
145188

146189
A **[full list of phonemes](https://microbit-micropython.readthedocs.io/en/latest/speech.html#phonemes)** is available in the speech documentation. You can also pass English words into the **[translate function](https://microbit-micropython.readthedocs.io/en/latest/speech.html#speech.translate)**. It returns a first version of the phonemes that the speech synthesiser would use. You can then edit the result to improve how it sounds.
147190

191+
1. Stop and close the current **main.py** file.
192+
2. Navigate to the **15_speech_pronounce** folder in Thonny and open the **main.py** file.
193+
148194
The `pronounce()` function is used for phoneme output like this:
149195

150196
```{literalinclude} ./python_files/15_speech_say_3/main.py
151197
:linenos:
152198
```
153199

200+
1. **Predict** what you think will happen. Be specific.
201+
2. **Run** the program.
202+
3. Time to **investigate** the code. What does each line do?
203+
154204
```{admonition} Code explanation
155205
:class: notice
156206
- **line 3** → imports the speech module
@@ -165,12 +215,21 @@ The mapping from pitch numbers to musical notes is shown below:
165215

166216
![speech-pitch](assets/speech-pitch.jpg)
167217

168-
Annotations work by adding a hash sign (`#`) and a pitch number before the phoneme. The pitch stays the same until a new annotation is given. For example, this code makes MicroPython sing a scale:
218+
Annotations work by adding a hash sign (`#`) and a pitch number before the phoneme. The pitch stays the same until a new annotation is given.
219+
220+
1. Stop and close the current **main.py** file.
221+
2. Navigate to the **15_sing** folder in Thonny and open the **main.py** file.
222+
223+
In this example, the code makes MicroPython sing a scale:
169224

170225
```{literalinclude} ./python_files/15_sing/main.py
171226
:linenos:
172227
```
173228

229+
1. **Predict** what you think will happen. Be specific.
230+
2. **Run** the program.
231+
3. Time to **investigate** the code. What does each line do?
232+
174233
```{admonition} Code explanation
175234
:class: notice
176235
- **lines 5 - 14** → creates a list of sung sounds, for example:
@@ -204,7 +263,10 @@ The microphone can respond to built-in sound events based on how loud the sound
204263
- `microbit.SoundEvent.QUIET` → sound changes from loud to quiet
205264
- `microbit.SoundEvent.LOUD` → sound changes from quiet to loud
206265

207-
For example:
266+
1. Stop and close the current **main.py** file.
267+
2. Navigate to the **15_microphone_1** folder in Thonny and open the **main.py** file.
268+
269+
You should see the code below:
208270

209271
```{literalinclude} ./python_files/15_microphone_1/main.py
210272
:linenos:
@@ -214,14 +276,26 @@ For example:
214276

215277
The microphone can also give a sound level reading from `0` to `255`.
216278

217-
For example:
279+
1. Stop and close the current **main.py** file.
280+
2. Navigate to the **15_microphone_2** folder in Thonny and open the **main.py** file.
281+
282+
You should see the code below:
218283

219284
```{literalinclude} ./python_files/15_microphone_2/main.py
220285
:linenos:
221286
```
222287

223-
## Sound exercises
288+
## Sound exercise 1
289+
1. Stop and close the current **main.py** file.
290+
2. Navigate to the **15_sound_ex1** folder in Thonny and open the **main.py** file.
291+
3. Create a program that plays your own tune
292+
293+
## Sound exercise 2
294+
1. Stop and close the current **main.py** file.
295+
2. Navigate to the **15_sound_ex2** folder in Thonny and open the **main.py** file.
296+
3. Create a program that sings the College Song
224297

225-
1. Create a program that plays your own tune
226-
2. Create a program that sings the College Song
298+
## Sound exercise 3
299+
1. Stop and close the current **main.py** file.
300+
2. Navigate to the **15_sound_ex3** folder in Thonny and open the **main.py** file.
227301
3. Create a program that lights up the display based on how loud the sound is

‎11_radio.md‎

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,45 @@ When a micro:bit receives a message, it is placed in a message **queue**. A comp
2323

2424
## Example
2525

26-
The example below shows how radio messages work. One micro:bit sends a message, and the other micro:bit displays an image. Run the same code on two micro:bits.
26+
The example below shows how radio messages work. One micro:bit sends a message, and the other micro:bit displays an image.
27+
28+
On two seprate micro:bits:
29+
1. Stop and close the current **main.py** file.
30+
2. open the **main.py** file in the **16_radio** folder in Thonny.
31+
32+
You should see the code below:
2733

2834
```{literalinclude} ./python_files/16_radio/main.py
2935
:linenos:
3036
```
3137

32-
## Radio Exercises
38+
## Radio Exercise 1
39+
40+
On two separate micro:bits:
41+
1. Stop and close the current **main.py** file.
42+
2. Open the **main.py** file in the **16_radio_exercise_1** folder in Thonny.
43+
3. Write code to move an image between two micro:bits when one micro:bit is shaken.
3344

34-
1. Move an image between two micro:bits when one micro:bit is shaken.
35-
2. Use the micro:bit radio feature to send a private yes or no answer.
45+
## Radio Exercise 2
46+
47+
On two separate micro:bits:
48+
1. Stop and close the current **main.py** file.
49+
2. Open the **main.py** file in the **16_radio_exercise_2** folder in Thonny.
50+
3. Write code to use the micro:bit radio feature to send a private yes or no answer.
3651
- Choose either **yes** or **no** and send it to another micro:bit.
3752
- Display the answer on the other micro:bit for half a second.
3853
- Use **[`radio.config`](https://microbit-micropython.readthedocs.io/en/v2-docs/radio.html#radio.config)** to choose a group so other nearby micro:bits do not receive your message.
39-
3. Use two micro:bits to display the outdoor and indoor temperatures.
40-
- The **outdoor micro:bit** should take a temperature reading and transmit it every 5 seconds.
41-
- The **indoor micro:bit** should display the indoor temperature when button **A** is pressed, or the outdoor temperature when button **B** is pressed.
54+
55+
## Radio Exercise 3
56+
57+
On one micro:bit:
58+
1. Stop and close the current **main.py** file.
59+
2. Open the **main.py** file in the **16_radio_exercise_3/inside** folder in Thonny.
60+
3. Write code to display the indoor temperature when button **A** is pressed.
61+
62+
On a differnt micro:bit:
63+
1. Stop and close the current **main.py** file.
64+
2. Open the **main.py** file in the **16_radio_exercise_3/outside** folder in Thonny.
65+
3. Write code to take a temperature reading and transmit it every 5 seconds.
66+
67+
Place the outside micro:bit outside and the inside micro:bit inside. When you press button **A** on the inside micro:bit, it should display the temperature reading from the inside micro:bit. When you press button **B**, it should display the outdoor temperature.
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# sound exrercise
2-
# 1
2+
3+
from microbit import *
4+
5+
# --- SETUP
6+
# start sensors
7+
8+
# store variables
9+
10+
# --- RUNNING
11+
while True:
12+
# read sensor data
13+
14+
# process data
15+
16+
# output data
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
# sound exercise 2
22

3+
4+
from microbit import *
5+
6+
# --- SETUP
7+
# start sensors
8+
9+
# store variables
10+
11+
# --- RUNNING
12+
while True:
13+
# read sensor data
14+
15+
# process data
16+
17+
# output data
18+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
# sound exercise 3
2+
3+
from microbit import *
4+
5+
# --- SETUP
6+
# start sensors
7+
8+
# store variables
9+
10+
# --- RUNNING
11+
while True:
12+
# read sensor data
13+
14+
# process data
15+
16+
# output data
17+

‎python_files/16_radio_ex1/main.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
# radio exercise 1
2+
3+
from microbit import *
4+
5+
# --- SETUP
6+
# start sensors
7+
8+
# store variables
9+
10+
# --- RUNNING
11+
while True:
12+
# read sensor data
13+
14+
# process data
15+
16+
# output data

‎python_files/16_radio_ex2/main.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
# radio exercise 2
2+
3+
from microbit import *
4+
5+
# --- SETUP
6+
# start sensors
7+
8+
# store variables
9+
10+
# --- RUNNING
11+
while True:
12+
# read sensor data
13+
14+
# process data
15+
16+
# output data
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
# radio exercise 3 indside
2+
3+
from microbit import *
4+
5+
# --- SETUP
6+
# start sensors
7+
8+
# store variables
9+
10+
# --- RUNNING
11+
while True:
12+
# read sensor data
13+
14+
# process data
15+
16+
# output data
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
11
# radio exercise 3 outside
2+
3+
from microbit import *
4+
5+
# --- SETUP
6+
# start sensors
7+
8+
# store variables
9+
10+
# --- RUNNING
11+
while True:
12+
# read sensor data
13+
14+
# process data
15+
16+
# output data

0 commit comments

Comments
 (0)