Lesson 52: Logic from words
このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
From words to logic
- Exam questions describe a system in words. You write a logic expression, then a truth table.
- Find the inputs, then the words that join them: and, or, not.
- Here three switches are the sensors and an LED is the alarm.
Words for this lesson
| Word | Meaning |
|---|---|
| input | a sensor value, 0 or 1 |
| logic expression | inputs joined with AND, OR, NOT |
| truth table | the output for every row of inputs |
English
Words to logic
| In the question | Logic | C++ |
|---|---|---|
| it is dark (L = 0) | NOT L | !L |
| and | AND | && |
| motion or sound or both | M OR S | M || S |
- Three inputs give 2 × 2 × 2 = 8 rows.
English
In the exam
- 0478/23/M/J/25 Q7(b): the alarm sounds if it is dark and motion or sound or both are detected. (i) Mark scheme: A = NOT L AND (M OR S) (longer correct forms also get the marks). (ii) The truth table: A = 1 only in rows 001, 010 and 011; four marks for eight correct outputs.
難易度 3/5 · 200 コイン + 今日初回達成時の小ボーナス
A security system has three inputs. A switch that is on gives 1. L = 1 means light (0 means dark), M = 1 means motion is detected, S = 1 means sound is detected. The alarm on pin 13 sounds if it is 暗い and motion または sound または both are detected. The program reads L, M and S for you. Write the logic expression in C++ and switch the alarm on or off. Check tries all 8 rows of the truth table.
実行ボタンをクリックして出力を確認してください。
難易度 4/5 · 280 コイン + 今日初回達成時の小ボーナス
Let the Arduino write the truth table. Finish the function alarm(L, M, S) so it returns the alarm output. The loops try every row and print it like 0 1 1 -> 1.
実行ボタンをクリックして出力を確認してください。