Skip to content

Commit 4e29fae

Browse files
committed
Update creating-your-program.md
1 parent 198d254 commit 4e29fae

1 file changed

Lines changed: 44 additions & 42 deletions

File tree

‎docs/reference/creating-your-program.md‎

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ When we make our own project, we work through three stages, in this order:
1414

1515
Doing it in this order saves us time. If something doesn't work later, we already know each component works on its own, so the problem must be in our code.
1616

17-
We'll follow these stages to build a **Too Hot Alarm**. It shows green lights and a happy face when the room is comfortable, and red lights, a sad face and a beep when it gets too hot.
17+
At the end of this page, we follow all three stages to build a **Too Hot Alarm**. It shows green lights and a happy face when the room is comfortable, and red lights, a sad face and a beep when it gets too hot.
1818

1919
## 1. Choose the components
2020

@@ -23,35 +23,14 @@ Every project takes information in, works out what to do with it, and does somet
2323
1. Write one sentence that says what the project does.
2424
2. List the information it needs → these are the **inputs**.
2525
3. List what it needs to do or show → these are the **outputs**.
26-
4. For each input and output, find a component that can do the job on the [Components](components.md) page.
26+
4. For each input and output, find a component that can do the job on the [Components](components.md) page. When a built-in component can do the job well, we use it, because there is less to wire up.
2727

2828
Then put the components in a planning table. The last column tells us which page to read for the code we need.
2929

3030
| Component | Input or output | What it does in our project | Page |
3131
| --- | --- | --- | --- |
3232
| | | | |
3333

34-
### Too Hot Alarm components
35-
36-
Our sentence: *the alarm shows whether the room is comfortable or too hot*.
37-
38-
- the room's temperature → input
39-
- a colour we can see from across the room → output
40-
- a face on the display → output
41-
- a beep → output
42-
43-
| Component | Input or output | What it does in our project | Page |
44-
| --- | --- | --- | --- |
45-
| Atmospheric Sensor | Input | measures the air temperature | [Atmospheric Sensor](../piicodev-inputs/atmospheric.md) |
46-
| 3x RGB LED | Output | shows green or red | [3x RGB LED](../piicodev-outputs/rgb-led.md) |
47-
| Display | Output | shows a happy or sad face | [Display](../microbit/display.md) |
48-
| Speaker | Output | beeps when it is too hot | [Sound](../microbit/sound.md) |
49-
50-
!!! tip "Built-in or PiicoDev?"
51-
The micro:bit has its own [temperature sensor](../microbit/temperature.md), so why use the Atmospheric Sensor? The built-in sensor is inside the processor, which warms up as it runs. That means it reads a few degrees above the room temperature. The Atmospheric Sensor measures the air, so it gives us a more accurate reading.
52-
53-
When a built-in component can do the job, use it, because there is less to wire up. When it can't do the job well enough, choose a PiicoDev module.
54-
5534
## 2. Wire them up
5635

5736
Now that we know our components, let's connect them. Built-in components, like the display and speaker, don't need connecting.
@@ -84,24 +63,6 @@ Before we combine the components, we run each one's own example from the tutoria
8463
| --- | --- | --- |
8564
| | | |
8665

87-
### Too Hot Alarm wiring
88-
89-
1. Unplug the micro:bit.
90-
2. Plug it into the adapter.
91-
3. Chain the modules: adapter → Atmospheric Sensor → 3x RGB LED.
92-
4. Check that both modules' ASW switches are off.
93-
5. Plug the micro:bit back in.
94-
95-
Our program folder, `too_hot`, needs four files: `main.py`, `PiicoDev_Unified.py`, `PiicoDev_BME280.py` and `PiicoDev_RGB.py`.
96-
97-
Then we test each part:
98-
99-
| Component | Example to run | Expected result |
100-
| --- | --- | --- |
101-
| Atmospheric Sensor | `atmospheric/values` | the Shell shows the temperature, pressure and humidity every second |
102-
| 3x RGB LED | `rgb_led/fill` | all three LEDs turn purple |
103-
| Display | `micropython/first_program` | the display scrolls "Hello world!" and shows a heart |
104-
10566
## 3. Create the program
10667

10768
Now that every component works, we can write the program. Every example in this course uses the same structure. We will use it for our own programs too, because it keeps our code organised and makes problems easier to find and fix.
@@ -162,7 +123,48 @@ Copy this into a new `main.py` to start a program. It is also in the `micropytho
162123
--8<-- "examples/micropython/template/main.py"
163124
```
164125

165-
### Too Hot Alarm program
126+
## Worked example: Too Hot Alarm
127+
128+
Let's put the three stages together to build the Too Hot Alarm.
129+
130+
### 1. Choose the components
131+
132+
Our sentence: *the alarm shows whether the room is comfortable or too hot*.
133+
134+
- the room's temperature → input
135+
- a colour we can see from across the room → output
136+
- a face on the display → output
137+
- a beep → output
138+
139+
| Component | Input or output | What it does in our project | Page |
140+
| --- | --- | --- | --- |
141+
| Atmospheric Sensor | Input | measures the air temperature | [Atmospheric Sensor](../piicodev-inputs/atmospheric.md) |
142+
| 3x RGB LED | Output | shows green or red | [3x RGB LED](../piicodev-outputs/rgb-led.md) |
143+
| Display | Output | shows a happy or sad face | [Display](../microbit/display.md) |
144+
| Speaker | Output | beeps when it is too hot | [Sound](../microbit/sound.md) |
145+
146+
!!! tip "Built-in or PiicoDev?"
147+
The micro:bit has its own [temperature sensor](../microbit/temperature.md), so why use the Atmospheric Sensor? The built-in sensor is inside the processor, which warms up as it runs. That means it reads a few degrees above the room temperature. The Atmospheric Sensor measures the air, so it gives us a more accurate reading.
148+
149+
### 2. Wire them up
150+
151+
1. Unplug the micro:bit.
152+
2. Plug it into the adapter.
153+
3. Chain the modules: adapter → Atmospheric Sensor → 3x RGB LED.
154+
4. Check that both modules' ASW switches are off.
155+
5. Plug the micro:bit back in.
156+
157+
Our program folder, `too_hot`, needs four files: `main.py`, `PiicoDev_Unified.py`, `PiicoDev_BME280.py` and `PiicoDev_RGB.py`.
158+
159+
Then we test each part:
160+
161+
| Component | Example to run | Expected result |
162+
| --- | --- | --- |
163+
| Atmospheric Sensor | `atmospheric/values` | the Shell shows the temperature, pressure and humidity every second |
164+
| 3x RGB LED | `rgb_led/fill` | all three LEDs turn purple |
165+
| Display | `micropython/first_program` | the display scrolls "Hello world!" and shows a heart |
166+
167+
### 3. Create the program
166168

167169
#### Step 1: Plan
168170

0 commit comments

Comments
 (0)