Week 2 ยท Decisions & Debugging

Session 6: Operators and decisions

Teach & build120 minLesson 05: Operators & 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.

  1. Lesson 05: Assignment vs comparison
  2. Lesson 05: Boolean operators
  3. Lesson 05: if / else if / else
  4. Theory Reference: Comparison operators

Session plan

  1. 0:0010 min
    Recap

    Quiz: types and division

  2. 0:1025 min
    Demo

    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.

  3. 0:3530 min
    Build

    Two-button LED logic

    Students build the worked sketch, complete a truth table in the logbook and test every row on the bench.

  4. 1:0540 min
  5. 1:4515 min
    Wrap-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.