You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4e29fae
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/reference/creating-your-program.md
+44-42Lines changed: 44 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ When we make our own project, we work through three stages, in this order:
14
14
15
15
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.
16
16
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.
18
18
19
19
## 1. Choose the components
20
20
@@ -23,35 +23,14 @@ Every project takes information in, works out what to do with it, and does somet
23
23
1. Write one sentence that says what the project does.
24
24
2. List the information it needs → these are the **inputs**.
25
25
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.
27
27
28
28
Then put the components in a planning table. The last column tells us which page to read for the code we need.
29
29
30
30
| Component | Input or output | What it does in our project | Page |
31
31
| --- | --- | --- | --- |
32
32
|||||
33
33
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
-
55
34
## 2. Wire them up
56
35
57
36
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
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
-
105
66
## 3. Create the program
106
67
107
68
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
162
123
--8<--"examples/micropython/template/main.py"
163
124
```
164
125
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.
0 commit comments