Help with HVAC controls and correct coding

I've searched for the last 2 days and I can't really find what i am trying to do. Please forgive me if I don't use the correct terminology as I'm learning this myself after my regular day. And i just picked up the Arduino uno about a week ago.

What i am trying to do is Design a stand alone HVAC (Heating Ventilation and Air Conditioning) controls for a custom dash in a streetrod. I plan on using R/C servos to actuate the different doors for air flow control. The dash electrical and mechanics are easy as i've been raised around cars. Anyway here's my issue.

I think what i want to to do is use a subroutine? To help clarify the code for me to read and write i'd like to be able to put the subroutine in a different spot instead of in the middle of the loop code. My plan is to use several momentary pushbuttons to activate different "modes" such as floor, dash and defrost. At this point in time i am NOT concerned about automatically controlling the temperature. I just want the buttons to make the air go where I want.

int (etc etc) servo (etc etc)

void setup (){ pinMode (etc etc) } Make the program remember the last state before the car is turned off.

void loop () { if (defrost button == HIGH) { run the defrost subroutine Stay there until another button is pressed if (floor button == HIGH) run the floor subroutine Stay there until another button is pressed }

Then someplace else specify what the defrost subroutine and the floor subroutine is. Like what angle to turn the servo to, which pin to turn on for the indicator light, relay ect. This would make it a lot easier for me to debug later should there be a problem.

I don't know if what i want makes sense or is even possible. I have ZERO coding experience up until this point. With the exception of the HTML colors above lol.

Thank you so much everyone who takes the time to respond Brian

I think you are better off detecting a state change (was LOW, now HIGH) rather than testing for HIGH.

Also a state machine in general sounds appropriate. Try Googling "Finite state machine".

Before you get to the state machine, you can at least write your floor, dash and defrost subroutines. In C, a subroutine is called a function - loop, setup and pinmode are functions, so you can see from your own example how they are written and the examples with the IDE show how they are called (pinmode is close).

For this example, you can ignore the need to stay in a particular routine until another button is pressed, just call the appropriate function whenever buttons are pressed - if it gets called multiple times to do the same thing, it doesn’t matter here. Later you can build the state machine logic that just calls each once.

Nick, Thank you! that looks like exactly what i need.

Wildbill, thats my problem, i don't know where to put the subroutines once they are written, or how to call them. I'm not asking to be spoonfed, but i'm not sure i'm using the right terminology when i search either.

Here's a snippet taken from your post that illustrates how to declare and call a function:

void loop () 
if (defrost button == HIGH) // won't compile
  defrost(); //Call function

// Do stuff to send air to the windscreen  

Note that it's still got your original pseudo code in it - all I've added is the function example. Note also that floor is an existing function in the c++ libraries- don't try to create one with that name in the same way as defrost - call it footwell or some such.

Return type needed:

void defrost()
// Do stuff to send air to the windscreen  

And that ladies and gentlemen is what you get when you can't be bothered to compile your work. Thank you Nick.

Perfect!! Thank you so much guys!