Session 6: Operators and decisions
Learning outcomes
- Compare values with ==, !=, <, <=, > and >=
- Combine conditions with &&, || and !
- Write an if / else if / else chain that chooses one action
- Read a button wired to GND as pressed when LOW
Kit and components
- Uno, USB cable and lab PC
- Breadboard, two push buttons and jumper wires
Pre-reading about 25 min
Students read these on their phones before class. They are listed on the student Before class page.
Session plan
- 0:0010 minRecap
Quiz: types and division
- 0:1025 minDemo
Decisions from inputs
Wire two buttons to D2 and D3 with INPUT_PULLUP on the projector. Print both readings, then build the both / either / neither chain step by step and show why the order of the tests matters.
- 0:3530 minBuild
Two-button LED logic
Students build the worked sketch, complete a truth table in the logbook and test every row on the bench.
- 1:0540 min
- 1:4515 minWrap-up
= versus ==
Show if (x = 5) and ask what it prints. Each student explains the difference in one sentence.
Checkpoint: ready to move on?
Each student's two-button sketch matches their truth table for all four combinations, and they can explain why the both-pressed test comes first.
Extension for fast finishers
Give button A priority over B (lesson challenge).
Catch-up path
Write the truth table on paper first, then code one branch at a time.
Homework and practice
Code Along 3.4 and 3.5.
Facilitator notes
- Four-leg buttons turned the wrong way cause most 'always pressed' faults. Show the correct orientation once for everyone.