KS3 Computing · A program stores information in variables, works on it with operators, and controls the order with sequence, selection and iteration. Examples are in Python, with Scratch alongside for Year 7.
Create the device in stages, testing each stage before adding the next.
Write a test table with normal, boundary and erroneous tests for a device.
Find one fault from testing, fix it, and run all the tests again.
Success criteria
I can show each stage working before I add the next one.
I can run my test table and mark each test pass or fail.
I can explain one fix I made and show the test that now passes.
Key words
Say each word, then read what it means. Every one is in the glossary too.
Variable
A named place in memory that holds a value.
Assignment
Storing a value in a variable. = in Python, ← in pseudocode.
Casting
Changing a value from one data type to another, like int("13").
Concatenation
Joining strings together: "7" + "7" = "77".
Selection
Choosing a path with if / else.
Iteration
Repeating steps: a loop.
Boolean
A value that is only True or False.
Infinite loop
A loop whose condition never becomes false.
The explanation
Read it here, or open the study page below to go one step at a time with things to try.
Build in stages
Build a little, test it, then build a little more. Follow the plan from last lesson.
Wire one LED with its resistor. Test it with Blink.
Add the other two LEDs. Test that setLights(0, 0, 1) shows green only.
Add the button and its pull-down. Print digitalRead(BUTTON) and press it: you should see 0, then 1.
Add the full sequence. Test the whole crossing.
The Serial Monitor is a box under the code. It shows what Serial.println prints. It is your window into the program.
★Remember
If a stage fails, the fault is almost always in the last thing you added.
A test table for a device
Plan the tests before you run them. Write what should happen first.
Test
Type
What to do
Expected
1
Normal
Press the button once while the lights are green
Amber 2 s, red 5 s, red and amber 1 s, then green
2
Boundary
Give the button the quickest tap you can
The sequence still starts
3
Boundary
Press the button again while the lights are red
Nothing extra happens
4
Erroneous
Hold the button down and do not let go
One full sequence, then cars get a green light
For a device, boundary tests try the edges of normal use: the shortest press, or a press at an awkward moment.
Erroneous tests try misuse: holding a button, pressing it again and again, or doing the unexpected.
Fix one thing
Test 4 fails. The lights go green, then loop() starts again at once. The held button is read straight away.
So the sequence starts again. Cars get green for a split second only.
setLights(1, 1, 0); // red and amber together: get ready to go
delay(1000);
setLights(0, 0, 1); // back to green
delay(5000); // NEW: cars always get at least 5 seconds of green
}
}
Change one thing: add delay(5000) after the lights go green.
Run test 4 again. Cars now get 5 seconds of green every time.
Run tests 1 to 3 again. A fix in one place can break another.
★Remember
Record the fail, the fix and the new pass in your test table. That is your evidence.
e.g.Worked example
You press the crossing button and nothing happens. How do you find the fault?
Predict: pressing the button should turn the amber light on.
Check the input first. Add Serial.println(digitalRead(BUTTON)); at the top of loop().
Run it and open the Serial Monitor. Not pressed should show 0. Pressed should show 1.
Always 0? The fault is in the wiring. Check that the button's diagonal leg goes to pin 2.
Jumps between 0 and 1 when nobody presses it? The 10 kΩ pull-down is missing.
Shows 1, but still no amber? The fault is in the code. Check the if uses == and HIGH.