 }
 
 /******************************/
+/* section RGB LED functions */
+/******************************/
+#ifdef __SUPPORT_RGBLED__
 void setRGBvalue(byte r, byte g, byte b)
 {
   analogWrite(pinRGBR, r);

  // put your main code here, to run repeatedly:
  int buttonValue;

  onAnimateRGB();
#ifdef __SUPPORT_GSM_MODULE__
  softserialCheck();
#endif // #ifdef __SUPPORT_GSM_MODULE__

  delay(3);
  
}
#endif //#ifdef __SUPPORT_RGBLED__

/**
 *================================================================
 * Section IR remote functions
 * https://github.com/marduino/arduino/wiki
 * 
 * https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/main.cpp
 */

/* a start high pulse of 2400 micro-seconds indicates start transferring a set of bits */
#define IR_REMOTE_START_TIMING    2100 

/* a 'one' timing means to set a bit to 1, indicated by 1200micro-seconds high pulse */
#define IR_REMOTE_ONE_TIMING      900

/* a 'zero' timing means to set a bit to 0, indicated by 600micro-seconds high pulse */
#define IR_REMOTE_ZERO_TIMING     400

unsigned long startTiming;
bool isDataValid;
int irData;
byte irDataIdx;

const int pinIRRemote = 2;


void IRRemoteSetup()
{
  startTiming = 0;
  irDataIdx = 0;
  irData = 0;
  isDataValid = false;
  pinMode(pinIRRemote, INPUT);
}

/*
 * Continua
 */
void IRRemoteMeasure()
{
  int value;
  unsigned long dur;

  value = digitalRead(pinIRRemote);
  if ((startTiming == 0) && (HIGH == value))
  {
    startTiming = micros();
    return;
  }

  /* wait until pin value turn to low, always return when HIGH */
  if (HIGH == value)
  {
    return;
  }

  dur = micros() - startTiming;
  startTiming = 0;
  
  /* read data if is a valid data frame */
  if (isDataValid == true) {
    /* convert data according with timing */
    if (dur >= IR_REMOTE_ONE_TIMING)
    {
       bitSet(irData, irDataIdx);
    }
    else if(dur >= IR_REMOTE_ZERO_TIMING)
    {
      bitClear(irData, irDataIdx);
    }
  }
  /* check duration if it is a new start frame */
  else if (dur >= IR_REMOTE_START_TIMING)
  {
      isDataValid = true;
      irDataIdx = 0;
      irData = 0;
  }

  Serial.println(dur, OCT);

}


