Switching active high to active low config.

Herrrro Arduino World,

Have a quick question regarding relay boards, many boards have active low inputs. I have been told This is done to guarantee that no relays will be activated during a power-up sequence. HOW can a user easily invert the relay outputs to work Active Low?? There is a portion of a sketch i use for a hydroponic program that i believe can be changed to accomplish this, if anybody could point me in the right direction that would be helpful.

//initialize all routine called by the IA command
//HHS calls this each time it is started up or shut down
void initializeAll(void)
{
  //set digital enable, usage, pullups and turn all outputs off
  //set analog enable, usage, sensitivity and get current value 
  for (int i=0; i<dp; i++)
  {      
    if (dpu[i] == 1)        //turn off all digital outputs        
    {
      digitalWrite(i,LOW); 
    }
  }
  for (int i=0; i<dp; i++)       //initialize all digital as input
  {
    pinMode(i, INPUT);           //make all ports input to help prevent accidents
    digitalWrite(i,LOW);
    dpu[i]=-1;                   // set type as unknown
    dpv[i]=1;                    // set up first change
    dpDeblast[i]  = 0;           // initialize debounce delay 
    dpvc[i] = false;             // no change in digital
  }
  for (int i=0; i<ap; i++) 
  {
    apu[i]=-1;                  //disabled
    aps[i] = apsensitivity;     //set default sensitivity
    aplv[i]=-1;                 // value of analog port (default to -1 for first trigger) 
  }
  aplasttime=0;                 //turn off both watchdogs
  ahtimeout=0;  
  sensorInit();
}

//command processing routine
void processmessage(void) 
{
  long fields[counter+1];
  //Serial.println(counter);
  for (int i=1; i<counter; i++)
  {     
    fields[i] = atol(parsed[i]);
    //Serial.println(fields[i]);
  }
  switch (getmnemonic(parsed[0])) 
  {
  case 0:                             //DS Digital port enable/disable, type
    if(counter >=3) {
      if (fields[2] = 0) {
        dpu[fields[1]] = -1;         //disable
      }
      else {
        dpu[fields[1]]=fields[3];     //type input=0, output=1, pwm=2
      }

      switch(fields[3])        
      {
      case 0: //input
        pinMode(fields[1], INPUT);
        digitalWrite(fields[1],HIGH);
        break;

      case 1: //output
        pinMode(fields[1], OUTPUT);
        digitalWrite(fields[1],LOW);
        break;

      case 2:  //output pwm
        pinMode(fields[1], OUTPUT);
        analogWrite(fields[1],fields[4]);
        break;

      case 4:   //tied to interrupt pins
        //pinMode(fields[1], OUTPUT); 
        break;
      }
    }
    break;

  case 1:                         //DQ Digital port query/set port,get/set,value
    switch(fields[2])
    {
    case 0:                                        
      dpv[fields[1]] =digitalRead(fields[1]);      //read the port

      Serial.print("{DQ:");
      Serial.print(fields[1]);
      Serial.print(":");
      Serial.print(dpu[fields[1]]);
      Serial.print(":");
      Serial.print("dpv[fields[1]]");
      Serial.print("}");

      //sprintf(sendmsg,"{DQ:%i:%i:%i}",fields[1],dpu[fields[1]],dpv[fields[1]]);
      //sendMessage((char *) sendmsg);  
      break;

    case 1:      //srite to the port
      if (counter==4){
        switch (dpu[fields[1]])
        {
        case 1:
          digitalWrite(fields[1],fields[3]);
          break;
        case 2:
          analogWrite(fields[1],fields[3]);
          break;
        }
      }
    }
    break;

  case 2:                           //AS Analog port enable/disable, type, sensitivity
    if (counter=5) {
      if (fields[2] > 0) {          //enable if non-zero
        apu[fields[1]] = fields[3]; //type of usage
        aps[fields[1]] = fields[4]; //sensitivity
      }
      else {
        apu[fields[1]]= -1; 
      }
    }
    break;

  case 3:                         //AQ Analog port query
    fields[2] =analogRead(fields[1]);      //read the port
    if (fields[1]<2)                       //this assumes that only the temp and humid sensor ports are actual
    {
      type=1;                               //must tell HHS it is actual with 1 in this field
      actual=sensorCompute(fields[1],fields[2]);
    }
    else
    {
      actual=0;                            //tell HHS to use raw data
    }
    Serial.print("{AQ:");
    Serial.print(fields[1]);
    Serial.print(":");
    Serial.print(apu[fields[1]]);
    Serial.print(":");
    Serial.print(fields[2]);
    Serial.print(":");
    Serial.print(actual);
    Serial.print("}");
    break;

  case 4: //QB Query device capabilities  board, digital, analog, channels, timers
    Serial.print("{QB:M:");
    Serial.print(dp);
    Serial.print(":");
    Serial.print(ap);
    Serial.print(":");
    Serial.print(nchan);
    Serial.print(":");
    Serial.print(ntim);
    Serial.print(":");
    Serial.print("1.0.0");
    Serial.print("}");

    //sprintf(sendmsg,"{QB:M:%i:%i:%i:%i:1.0.0}",dp,ap,nchan,ntim);
    //sendMessage(sendmsg);         
    break;

  case 5: //IA initialize all
    initializeAll();
    break;

  case 6: //RL release port processing
    if (fields[1] > 0) {
      released=true;
    }
    else{
      released=false;
    }
    break;

  case 7:  //restart host watchdog when received from host, resets the timeout and set the arduino interval
    hatimeout = 30000;
    ahtimeout=fields[1]*1000;
    previousMillis = millis();
    break;

  case 8:  //digital debounce interval
    dpDebounce = fields[2];
    break;

  case 9: //sensor slope and intercept
    if (counter < 6)
    {
      break;
    }
    if ((fields[3] !=0) & (fields[5] != 0)) 
    {
      slope[fields[1]]=(float)fields[2]/(float)fields[3]; //slope
      intercept[fields[1]]=(float)fields[4]/(float)fields[5]; //slope
      //Serial.println(slope[fields[1]]);
      //Serial.println(intercept[fields[1]]);
    }
    break;

  case 10://DEBUG
    //put debug stuff here

    break;

  }
}

unfortunately, the sketch has very little to do with it.

The active low or active high, or normally closed or normally open, have to do with the relay and the way you activate it.

This is done in case the power goes missing, in which case the Arduino won't be working. See what I mean?