/* Function   : programConfig(int config)
 * Description: 
 * Parameter  :  
 * Return     : duration of button press down (Ms)
 */
uint16_t Grove_Joint::checkButtonDown()
{  
  uint16_t ret = 0;
  uint16_t blockCountermillis = 0;
  uint16_t time_duration = 0;
  
  if((HIGH==digitalRead(KEY)))
  {
    delay(5);
    if((HIGH==digitalRead(KEY)))
    {      
      while((HIGH==digitalRead(KEY)))
      {
        delayMicroseconds(998);
        blockCountermillis++;        
      }
      time_duration = blockCountermillis;
      ret = time_duration;
      
      #if DEBUG        
        LOG_VALUE("time_duration: ", time_duration);
      #endif      
    }
  }
  
  return ret;
}
Exemple #2
0
/**********************************************************************
 * Compute a logarithm.
 **********************************************************************/
PROB_T my_log
  (PROB_T x)
{
  if (x > 0.0) {
    return(LOG_VALUE(log(x)));
  } else if (x < 0.0) {
    die("Tried to take the log of a negative value (%g).", x);
  } /* else if (x == 0.0) */
  return(LOG_ZERO);
}
/* Function   : int initLightSensor(void)
 * Description: 
 * Parameter  : 
 * Return     : Ambient light value
 */
int Grove_Joint::initLightSensor(void)
{
  long tmp = 0;
  for(int i=0;i<100;i++){
    tmp += analogRead(LIGHT_SENSOR);
  } 
  tmp /= 100;
  #if DEBUG
  LOG_VALUE(" Read Light Sensor: ", tmp);  
  #endif
  
  return tmp;
}