壁掛爐菜單是壁掛爐控制器的顯示面板,它具有顯示溫度、調節溫度、設置定時開關機等功能。下面是一份壁掛爐菜單設置代碼的示例:

```python# 定義菜單頁面menu_pages = { 'main': ['Temp Setting', 'Timer Setting', 'Lock Setting', 'Reset Settings'], 'temp_setting': ['Current Temp: {}℃', 'Set Temp: {}℃', 'Back'], 'timer_setting': ['Set Timer', 'Back'], 'lock_setting': ['Lock', 'Unlock', 'Back'],}
# 定義溫度設定范圍temp_range = (10, 50)
# 定義定時器設定最大時間max_timer = 180
# 定義壁掛爐當前狀態current_temp = 20set_temp = 25timer_remaining = Nonetimer_is_on = Falselock_is_on = False
# 定義菜單控制函數def show_menu(page='main'): while True: print('\n', ' '.join(menu_pages[page])) user_input = input('Select Option: ').strip() if user_input.isdigit() and int(user_input) < len(menu_pages[page]): option = menu_pages[page][int(user_input)] if option == 'Back': return elif option.startswith('Current Temp'): print(option.format(current_temp)) elif option.startswith('Set Temp'): new_temp = int(input('Set Temp: ')) if new_temp < temp_range[0]: new_temp = temp_range[0] elif new_temp> temp_range[1]: new_temp = temp_range[1] set_temp = new_temp print('Set Temp: {}℃'.format(set_temp)) elif option == 'Set Timer': new_timer = int(input('Set Timer (mins): ')) if new_timer < 0: new_timer = 0 elif new_timer> max_timer: new_timer = max_timer timer_remaining = new_timer timer_is_on = True print('Timer Set for {} mins'.format(timer_remaining)) elif option == 'Lock': lock_is_on = True print('Locked') elif option == 'Unlock': lock_is_on = False print('Unlocked') elif option == 'Reset Settings': current_temp = 20 set_temp = 25 timer_remaining = None timer_is_on = False lock_is_on = False print('Settings Reset')```
這個設定代碼定義了菜單頁面、溫度設定范圍、定時器設置最大時間以及壁掛爐的當前狀態。菜單控制函數根據用戶的輸入,選擇對應的操作。其中,設定溫度時需要檢查溫度范圍是否符合要求,設定定時器時需要檢查定時時間是否在允許范圍內。定義了重置設置的函數,將所有設置回歸到默認狀態。這段代碼實現了壁掛爐的基本菜單功能,可以作為壁掛爐控制器的一部分使用。


























