The assignment spec and design rationale for the automatic classroom heating, cooling and ventilation system. For a summary of the results see the project main page, and for the actual behavior see the simulator.
Assignment spec
The Day 2 team project (challenge level) of "Smart Inventions with Boolean Algebra and Logic Gates". The task is to build a prototype in tkinter that reads virtual sensors and controls devices, and to verify it with a product test table transcribed from the truth table.
There were three implementation constraints.
- Use only the Python standard library and tkinter. No
pip install. - Use only three logic operations:
and,or, andnot. Bitwise operators (&,|,^,~) are not allowed; if XOR is needed, build it yourself by combining the three. - Handle multiple bits as lists of booleans, not as integer bit fields.
Input variables
RIs automatic mode on?PIs someone in the classroom?WIs a window open?T1Is the outdoor temperature above 28 °C?T2Is the outdoor temperature below 18 °C?QIs the carbon dioxide level high?
Output variables
CCoolingHHeatingA1Close-window alarmA2Open-window alarm
Conditions in plain language
- Automatic cooling — Cooling runs when automatic mode is on, someone is in the classroom, the window is closed, the outdoor temperature is above 28 °C, and the carbon dioxide level is not high.
- Automatic heating — Heating runs when automatic mode is on, someone is in the classroom, the window is closed, the outdoor temperature is below 18 °C, and the carbon dioxide level is not high.
- Close-window warning — The close-window alarm sounds when automatic mode is on, someone is in the classroom, the window is open, the outdoor temperature is above 28 °C or below 18 °C, and the carbon dioxide level is not high.
- Open-window warning — The open-window alarm sounds when someone is in the classroom, the window is closed, and the carbon dioxide level is high.
Logic expressions
hot = T1 and (not T2) 더위 신호가 믿을 만한가
cold = T2 and (not T1) 추위 신호가 믿을 만한가
C = R and P and (not W) and hot and (not Q)
H = R and P and (not W) and cold and (not Q)
A1 = R and P and W and (hot or cold) and (not Q)
A2 = P and (not W) and Q
The two alarms have opposite window conditions. The close warning sounds only when the window is open, and the open warning sounds only when it is closed, so A1 and A2 never sound at the same time.
Manual control
When automatic mode (R) is off, a person switches cooling and heating on and off directly. When it is turned back on, the automatic decision takes over again and the manual switches are locked. Manual cooling and manual heating cannot be on at the same time.
C_최종 = (R and C) or ((not R) and 수동냉방)
H_최종 = (R and H) or ((not R) and 수동난방)
A1_최종 = A1 경고음은 자동 판단을 그대로 씁니다
A2_최종 = A2
This is a 2:1 multiplexer with R as the select signal. The alarms are a safety feature, so they keep using the automatic decision even in manual mode. A1 has R in its condition, so it switches itself off in manual mode, while A2 does not depend on R, so it still sounds in manual mode when the air gets bad. The truth table contains only the automatic operation logic; manual control is left out because a person decides it.
Sensor fault handling
The outdoor temperature cannot be above 28 °C and below 18 °C at the same time. If T1 and T2 are both true, the temperature sensor is treated as faulty and all the temperature-driven outputs (C, H, A1) are stopped. The screen also prevents the two checkboxes from being on at the same time.
Design rationale
| Question | Answer |
|---|---|
Why does heating and cooling have not W? |
Heating and cooling are wasted when a window is open |
Why does A1 have W? |
There is no reason to tell someone to close a window that is already closed |
Why does A2 have not W? |
There is no reason to tell someone to open a window that is already open |
Why is A2 the only one without R? |
Air quality is a safety matter, so it must be reported even when automatic mode is off |
Why does heating and cooling have not Q? |
When the air is bad, ventilation comes first, so heating and cooling stop |
Can C and H be on together? |
No. hot and cold cannot both be true |
Can A1 and A2 be on together? |
No. Their W conditions are opposite |
Three fixes made during design
| Problem | Symptom | Fix |
|---|---|---|
A1 had no window condition |
"Please close it" sounded while the window was closed | Added W |
A2 had no window condition |
"Please open it" sounded while the window was open | Added not W |
T1 and T2 could both be true |
Cooling and heating turned on together | Split into hot / cold |
None of the three could be found from the expressions alone; all were found while scanning the 64 truth table rows by eye.
Verification
The program's 전체 테스트 button compares the 64 truth table rows (TEST_CASES) with the actual behavior of decide(). The result is 64 / 64 passed.
Separately from the logic expressions, a reference implementation using conditional branches was written to cross-check all 64 combinations, and it confirmed that the following four things never happen in any combination.
- Cooling and heating running together
- Close-window and open-window alarms running together
- A contradiction between the window state and the alarm content
- Temperature outputs running on the contradictory temperature sensor input
Implementation structure
classroom_hvac.py follows the structure of the class template 05_invention_starter_2out.py (3 inputs / 2 outputs). The file is divided into two areas.
- The part students edit —
TITLE,INPUT_LABELS,OUTPUT_LABELS, the status text,decide(), andTEST_CASES. To this were addedEXCLUSIVE_INPUTS(groups of sensors that cannot be true together),MANUAL_LABELSandEXCLUSIVE_MANUAL(manual switches), andfinal_outputs()(the multiplexer). - The GUI framework — Window creation, checkboxes, buttons, result updates, and test execution follow the template structure. On top of that were added the manual control box, the toggle handling that turns off switches that cannot be on together, the
final_outputs()call, and the mode display in the status line, and the text "two outputs" was changed to "four outputs".
Porting to the web
A tkinter window can be opened only after installing Python and downloading the file. To remove that step, the same program was ported to a single HTML page.
What stayed the same:
- The logic expressions of
decide()andfinal_outputs(), the 64 rows ofTEST_CASES, and the eight output messages were carried over as they were. - The mutually exclusive
T1andT2inputs, the mutually exclusive manual cooling and heating inputs, and the locking of the manual switches when automatic mode is on behave the same. - The three buttons
초기화,전체 테스트, and진리표 보기, and the status line at the bottom (mode, input bits, output bits) are the same.
What changed:
- The truth table is on the same page below rather than in a separate window, and you can filter down to just the 12 rows where something turns on. Clicking a row loads that input into the switches. The combinations where T1 and T2 are both true (2 of the 12 rows) cannot be produced with the switches, so they are only shown dimmed.
- The decision rules are shown on screen, with true and false terms distinguished by color for the current input, so you can see how the expressions are evaluated.
- The full test result appears below the button instead of in a dialog box.
- Only the separator in the title was written as
·(heating·cooling) instead of the original/. The rest of the text is the same as the original.