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
Pic Pic

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
Pic Pic

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
Pic Pic

Extension Questions

  • Can you make the faces change to other expressions?
  • Can you change how long the faces are displayed for?