Listing 3. Control Loop with Hardware Interface

int server_room_automated()
{
  float temperature;

  // initialize i/o

  // an infinite loop
  for(;;)
    {
      // retrieve the temperature
      get_temperature(&temperature);

      // decide if this is hot or cold
      if(temperature > 70.0 /* Fahrenheit */)
        {
          // temperature seems warm
          turn_fan_on();
        }
      else if(temperature < 65.0)
        {
          // temperature may be a bit cold
          turn_heater_on();
        }
      else
        {
          // turn off fan and heater
          turn_fan_off();
          turn_fan_on();
        }

      // delay a bit to slow the update rate of this
      // control loop
      usleep(my_delay_interval);
   }
}