# define your states STATE_OFF = 0 STATE_HEATING = 1 STATE_DONE = 2 while True: # Read inputs (buttons, sensors, etc) and save the results in variables # Now do different things based on which state we're in! if state == STATE_OFF: # Do stuff specific to this state outputs.off() # Example to turn the "outputs" off # Decide if we should go to another state if onButton pressed: heater.on() state = STATE_HEATING elif state == STATE_HEATING: # Do stuff specific to this state # Decide if we should go to another state elif state == STATE_DONE: # Do stuff specific to this state # Decide if we should go to another state else: # Where should we go by default?