Introduction
Aims
In this part of the activity we will:
- Write a basic program
- Download it to the micro:bit
- Run the program
Learning outcomes
| Learning outcome | |
|---|---|
| Code | Write a simple program in the browser development environment |
| Physical computing | Download and run the program on a microcontroller |
Preperation
Equipment required
| Equipment item | Quantity |
|---|---|
| Micro:bit | 1 |
Tools required
| Tool | Quantity |
|---|---|
| USB cable | 1 |
Activity instructions
Let’s write our first program
Letās write some code to make the microbit display a smiley face when the program starts When you have finished - download it to you micro:bit (follow the instructions here)
| Blocks | Python |
|---|---|
|
|
Letās make the face change
- Microcontrollers work using a āforever loopā
- Letās write a function to make the face switch between sad and happy in the forever loop
| Blocks | Python |
|---|---|
|
|
Letās program a button input
- We can use buttons as inputs
- Letās use the following to make the face switch between happy and sad:
- Buttons
- An if statement
- A variable called āstateā
| Blocks | Python |
|---|---|
|
|
Extension Questions
- Can you make the faces change to other expressions?
- Can you change how long the faces are displayed for?