Esempio n. 1
0
uint8_t Servo::attach(int pin, int minUs, int maxUs)
{
    ServoTimerSequence timerId;

    if (_servoIndex < MAX_SERVOS) {
        if (s_servos[_servoIndex].info.pin == INVALID_PIN) {
            pinMode(pin, OUTPUT);       // set servo pin to output
            digitalWrite(pin, LOW);
            s_servos[_servoIndex].info.pin = pin;
        }

        // keep the min and max within 200-3000 us, these are extreme
        // ranges and should support extreme servos while maintaining
        // reasonable ranges
        _maxUs = max(250, min(3000, maxUs));
        _minUs = max(200, min(_maxUs, minUs));

        // initialize the timerId if it has not already been initialized
        timerId = SERVO_INDEX_TO_TIMER(_servoIndex);
        if (!isTimerActive(timerId)) {
            initISR(timerId);
        }
        s_servos[_servoIndex].info.isDetaching = false;
        s_servos[_servoIndex].info.isActive = true;  // this must be set after the check for isTimerActive
    }
    return _servoIndex;
}
Esempio n. 2
0
void Servo::detach()
{
  servos[this->servoIndex].Pin.isActive = false;
  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
  if(isTimerActive(timer) == false) {
    finISR(timer);
  }
}
Esempio n. 3
0
void Servo::detach()
{
    ServoTimerSequence timerId;

    s_servos[_servoIndex].info.isActive = false;
    timerId = SERVO_INDEX_TO_TIMER(_servoIndex);
    if (!isTimerActive(timerId)) {
        finISR(timerId);
    }
}
Esempio n. 4
0
uint8_t Servo::attach(int pin, int min, int max)
{
  if(this->servoIndex < MAX_SERVOS ) {
    pinMode( pin, OUTPUT) ;                                   // set servo pin to output
    servos[this->servoIndex].Pin.nbr = pin;
    
    // initialize the timer if it has not already been initialized
    timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
    if(isTimerActive(timer) == false)
      initISR(timer);
    servos[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
  }
  return this->servoIndex ;
}
Esempio n. 5
0
uint8_t Servo::attach(int pin, int min, int max)
{
  if(this->servoIndex < MAX_SERVOS ) {
    pinMode( pin, OUTPUT) ;                                   // set servo pin to output
    servos[this->servoIndex].Pin.nbr = pin;
    // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
    this->min  = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS
    this->max  = (MAX_PULSE_WIDTH - max)/4;
    // initialize the timer if it has not already been initialized
    timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
    if(isTimerActive(timer) == false)
      initISR(timer);
    servos[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
  }
  return this->servoIndex ;
}
uint8_t Servo::attach(int pin, int min, int max) {
  if (this->servoIndex < MAX_SERVOS ) {
  #if defined(ENABLE_AUTO_BED_LEVELING) && (PROBE_SERVO_DEACTIVATION_DELAY > 0)
    if (pin > 0) this->pin = pin; else pin = this->pin;
  #endif
    pinMode(pin, OUTPUT);                                   // set servo pin to output
    servos[this->servoIndex].Pin.nbr = pin;
    // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
    this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
    this->max = (MAX_PULSE_WIDTH - max) / 4;
    // initialize the timer if it has not already been initialized
    timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
    if (!isTimerActive(timer)) initISR(timer);
    servos[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive
  }
  return this->servoIndex;
}
Esempio n. 7
0
int8_t Servo::attach(const int pin, const int min, const int max) {

  if (this->servoIndex >= MAX_SERVOS) return -1;

  if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
  pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output

  // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128
  this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
  this->max = (MAX_PULSE_WIDTH - max) / 4;

  // initialize the timer if it has not already been initialized
  timer16_Sequence_t timer = SERVO_INDEX_TO_TIMER(servoIndex);
  if (!isTimerActive(timer)) initISR(timer);
  servo_info[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive

  return this->servoIndex;
}
Esempio n. 8
0
uint8_t Servo::attach(int pin, int min, int max)
{
   if(this->servoIndex < MAX_SERVOS ) {
    if(pin == 0 | pin == 1)
    {
        // disable UART
        U1MODE = 0x0;

    }
   
    pinMode( pin, OUTPUT) ;                                   // set servo pin to output
    servos[this->servoIndex].Pin.nbr = pin;  
    this->min  = (MIN_PULSE_WIDTH - min)/4; //resolution of min/max is 4 uS
    this->max  = (MAX_PULSE_WIDTH - max)/4; 
    // initialize the timer if it has not already been initialized 
    int timer = SERVO_INDEX_TO_TIMER(this->servoIndex);
    if(isTimerActive(timer) == false)
        initISR(timer);    
    servos[this->servoIndex].Pin.isActive = true;  // this must be set after the check for isTimerActive

    return this->servoIndex ;     
   }
}
Esempio n. 9
0
//************************************************************************
uint8_t Servo::attach(int pin, int min, int max)
{
	if (this->servoIndex < ServoCount)
	{
		pinMode(pin, OUTPUT);								// set servo pin to output
		servos[this->servoIndex].Pin.nbr = pin;
		this->min	=	(MIN_PULSE_WIDTH - min)/4;			// resolution of min/max is 4 uS
		this->max	=	(MAX_PULSE_WIDTH - max)/4; 
		// initialize the timer if it has not already been initialized 
		int timer = SERVO_INDEX_TO_TIMER(this->servoIndex);
		if (isTimerActive(timer) == false)
		{
			initISR(timer);	
		}
		servos[this->servoIndex].Pin.isActive = true;		// this must be set after the check for isTimerActive

		return this->servoIndex;
	}
    else
    {
        // return bogus value if this->ServoIndex is invalid
        return(INVALID_SERVO);
    }
}