Robot Logic Truth Table
Run the Robot Logic Truth Table MicroSim Fullscreen
About This MicroSim
Robots make decisions by combining conditions. This MicroSim uses two conditions from a real robot:
- A is
obstacle_close. It isTruewhen the distance sensor reads under 20 cm. - B is
robot_moving. It isTruewhen the motors are running.
You pick a rule that combines them with and, or, or not. When the
rule is True, the Emergency stop? lamp turns red.
A truth table lists every possible combination of True and False
for A and B, and the answer the rule gives for each one. The row that
matches your switches is highlighted yellow. The other answers stay hidden
as ? until you predict them.
How to Use
- Flip the switches. Use the A and B checkboxes, or click a switch in the picture. You can also click a row of the table to jump to it.
- Pick a rule such as
A and Bornot A and B. The code line shows the rule as a MicroPythonifstatement, with the live values worked out step by step underneath. - Tick "Show parentheses order" to see which part Python works out
first:
notis 1,andis 2, andoris 3. - Press Test my prediction. Click a
?in the Result column, then press True or False. Can you fill the whole table without mistakes? - Press Show all rows to check the full table.
Challenge: With A or B, find the one row where the lamp stays dark.
Then choose the rule that stops the robot only when it is moving and not
close to an obstacle. The operators are introduced in
Chapter 3: Logical Operators.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Learning Objective
Students will apply the rules for and, or, and not, including
MicroPython's operator precedence, to evaluate compound robot conditions and
predict when an emergency-stop rule fires (Bloom's Taxonomy: Apply).
Grade Level
Grades 8–12.
Duration
15–20 minutes.
Prerequisites
- The "Booleans", "Comparison Operators", and "Logical Operators" sections of Chapter 3.
- Reading a simple
ifstatement.
Background
Truth tables externalize the full input space of a Boolean expression, which
lets students verify a rule exhaustively instead of by a single example. The
two compound rules are chosen to surface precedence: because not binds more
tightly than and, not A and B means (not A) and B, not not (A and B).
The optional order circles and the step-by-step value line make that
evaluation order visible. Hiding the non-current rows until students commit
to a prediction turns the table from a reference into a practice task.
Activities
- Warm-up (3 min). With
A and B, students flip the switches through all four combinations and say the robot behavior aloud for each. - Predict the table (5 min). For
A or B, students use Test my prediction to fill every?before pressing Show all rows. - Challenge (4 min). The dark row for
A or Bis AFalse, BFalse. The rule that stops only when moving and not close isnot A and B, whose results for rows FF, FT, TF, TT areFalse,True,False,False. - Precedence (4 min). Students compare
not A and Bwith(not A) or Busing the order circles, then writenot (A and B)on paper and build its truth table by hand. Ask how it differs fromnot A and B. - Connect to code (2 min). Students rewrite the emergency-stop rule
with comparisons from the chapter:
if distance_cm < 20 and motor_speed > 0:.
Assessment
- Formative: Watch the number of "Not yet" responses during Activity 2;
students with more than two should re-state the
orrule before continuing. - Exit ticket: "Write the full truth table for
not A or B, and say in plain words when the lamp is dark." (Dark only when A isTrueand B isFalse.) - Rubric (4-point): Exemplary — correct tables for all five rules,
including precedence, and a correct hand-built table for
not (A and B); Proficient — correct tables forand,or, andnot, with one precedence error; Developing — confusesandwithor; Beginning — evaluates only the highlighted row.
References
- Chapter 3: MicroPython and Development Environment Setup — booleans, comparison operators, and logical operators.
- Truth table — Wikipedia — how truth tables list every input combination.
- Python Language Reference: Boolean operations — official rules for
and,or, andnot. - Python Language Reference: Operator precedence — why
notis evaluated beforeand, andandbeforeor. - Python Operator Playground (Moving Rainbow) — the logic evaluation this MicroSim builds on.