[Video Teaching]
[Graphic Tutorial]
Lesson 8 Button Control Light
1. Course Introduction
Program branching can enhance interaction in programs. In the last lesson, we used a doorbell as a case study to explain the interaction design under a single boolean condition. In this lesson, we introduce boolean operations, achieving more complex program logic by creating a button-controlled light.
Components needed for this lesson: Arduino UNO, LED light, button.
2. Key Points of This Lesson
Program branching, boolean operations
3. Explanation of Required Modules
Boolean Operations:
Location: Operators.
Module function: Perform “AND” operation on the boolean values to the left and right of the module.
4. Program and Flowchart
Program Diagram:
5. Related Knowledge Explanation
State Variables:
In this example, the variable is a state variable that records the light’s on/off state, which, together with the button state (high/low level state of port 5), determines the specific program branch statement executed.
Boolean Operations:
“AND” Operation:
When all boolean values involved in the operation are true, the result is true;
If any boolean value involved in the operation is false, the result is false;
“OR” Operation:
If at least one boolean value involved in the operation is true, the result is true;
If all boolean values involved in the operation are false, the result is false;
“NOT” Operation:
Not “true” is “false”, not “false” is “true”.