Skip to main content
WalesElectronicsSyllabus dot point

How is a microcontroller program structured, and how do flowcharts represent decisions, loops and subroutines?

Microcontroller programming: flowcharts, sequence, selection and iteration, input and output instructions, time delays, subroutines, and translating a system specification into a program.

A focused answer to WJEC A-Level Electronics microcontroller programming, covering flowcharts, the program structures of sequence, selection and iteration, input and output instructions, time delays, subroutines, and turning a system specification into a working program.

Generated by Claude Opus 4.812 min answer

Reviewed by: AI editorial process; not yet individually human-reviewed

Have a quick question? Jump to the Q&A page

Jump to a section
  1. What this dot point is asking
  2. The answer
  3. Examples in context
  4. Try this

What this dot point is asking

A microcontroller does nothing without a program, and Component 2 expects you to design and read programs using flowcharts. WJEC expects you to use the three program structures (sequence, selection, iteration), write input and output and delay instructions, use subroutines, and translate a worded system specification into a program. The flowchart design question and the subroutine explanation are reliable, high-mark exam content.

The answer

The three program structures

Flowcharts

Flowcharts are the WJEC-preferred way to plan and present a program, because they make the sequence, decisions and loops visible at a glance.

Inputs, outputs and time delays

A program reads inputs (the state of switches and sensors), drives outputs (turning pins high or low to control LEDs, motors and so on), and uses time delays to control timing, for example to flash a light or debounce a switch.

Subroutines

Examples in context

Example 1. A pedestrian crossing controller
The program is a loop: it waits for the button (selection), then runs a timed sequence of light changes using delays, before returning to wait again. The three structures appear together, and the timed light sequence is a subroutine reused for each cycle.
Example 2. Reading a sensor and reacting
A program reads a temperature through the ADC each loop (input), decides with a selection whether it is above a threshold, and drives a fan output accordingly. The forever loop means the system keeps responding to changing temperature, which a single pass could not.
Example 3. Debouncing a switch
When a switch is pressed, its contacts bounce, giving several quick transitions. A short delay subroutine after detecting a press lets the bounce settle before the program reads again, so one press registers once. This shows a time delay solving a real interfacing problem in software.

Try this

Q1. Name the three basic program structures and say what each does. [3 marks]

  • Cue. Sequence (steps in order), selection (a decision that branches, an if), iteration (a loop that repeats).

Q2. Give one advantage of using a subroutine in a microcontroller program. [1 mark]

  • Cue. It avoids repeating code (write once, call many times), saving program memory; or it makes the program clearer and easier to test.

Exam-style practice questions

Practice questions written in the style of WJEC exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.

WJEC Eduqas 20206 marksA microcontroller must flash an LED on for 1 second and off for 1 second, repeating forever, while also checking a switch each cycle and stopping the flashing if the switch is pressed. Describe, using flowchart structures, how the program would be organised.
Show worked answer →

The program is an iteration (loop) containing output, delay and a selection.

Start: set the LED pin as an output and the switch pin as an input.

Main loop (repeat forever): turn the LED on; wait 1 second (a time delay or delay subroutine); turn the LED off; wait 1 second; then check the switch with a selection (decision): if the switch is pressed, branch out of the loop to a stopped state (LED off); if not, loop back to the start of the main loop.

The structures used are sequence (the ordered steps), iteration (the repeating loop), and selection (the if-switch-pressed decision), with a delay subroutine called twice.

Markers reward the loop structure, the on/delay/off/delay sequence, the switch decision (selection) branching out, and the use of a delay.

WJEC Eduqas 20184 marksExplain what a subroutine is in a microcontroller program and give two advantages of using one.
Show worked answer →

A subroutine is a named, self-contained block of code that performs a specific task and can be called from anywhere in the program; when it finishes it returns to the point it was called from.

Advantages: it avoids repeating the same code (a task such as a time delay is written once and called many times, saving program memory), it makes the program easier to read and structure, and it makes testing and maintenance easier because the block can be checked on its own. Any two of these are acceptable.

Markers reward the definition (reusable called block that returns) and two valid advantages (no repetition/saves memory, readability, easier testing).

Related dot points

Sources & how we know this