当前位置: 首页>>代码示例>>C++>>正文


C++ AFMotorController::latch_tx方法代码示例

本文整理汇总了C++中AFMotorController::latch_tx方法的典型用法代码示例。如果您正苦于以下问题:C++ AFMotorController::latch_tx方法的具体用法?C++ AFMotorController::latch_tx怎么用?C++ AFMotorController::latch_tx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AFMotorController的用法示例。


在下文中一共展示了AFMotorController::latch_tx方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: switch

AF_DCMotor::AF_DCMotor(uint8_t num, uint8_t freq) {
  motornum = num;
  pwmfreq = freq;

  MC.enable();

  switch (num) {
  case 1:
    latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B); // set both motor pins to 0
    MC.latch_tx();
    initPWM1(freq);
    break;
  case 2:
    latch_state &= ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // set both motor pins to 0
    MC.latch_tx();
    initPWM2(freq);
    break;
  case 3:
    latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B); // set both motor pins to 0
    MC.latch_tx();
    initPWM3(freq);
    break;
  case 4:
    latch_state &= ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // set both motor pins to 0
    MC.latch_tx();
    initPWM4(freq);
    break;
  }
}
开发者ID:mikeChastain,项目名称:adafruit-Adafruit-Motor-Shield-library-4bd21ca,代码行数:29,代码来源:AFMotor.cpp

示例2: run

void AF_DCMotor::run(uint8_t cmd) {
  uint8_t a, b;
  switch (motornum) {
  case 1:
    a = MOTOR1_A; b = MOTOR1_B; break;
  case 2:
    a = MOTOR2_A; b = MOTOR2_B; break;
  case 3:
    a = MOTOR3_A; b = MOTOR3_B; break;
  case 4:
    a = MOTOR4_A; b = MOTOR4_B; break;
  default:
    return;
  }

  switch (cmd) {
  case FORWARD:
    latch_state |= _BV(a);
    latch_state &= ~_BV(b);
    MC.latch_tx();
    break;
  case BACKWARD:
    latch_state &= ~_BV(a);
    latch_state |= _BV(b);
    MC.latch_tx();
    break;
  case RELEASE:
    latch_state &= ~_BV(a);     // A and B both low
    latch_state &= ~_BV(b);
    MC.latch_tx();
    break;
  }
}
开发者ID:mikeChastain,项目名称:adafruit-Adafruit-Motor-Shield-library-4bd21ca,代码行数:33,代码来源:AFMotor.cpp

示例3: release

void AF_Stepper::release(void) {
  if (steppernum == 1) {
    latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) &
      ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0
    MC.latch_tx();
  } else if (steppernum == 2) {
    latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B) &
      ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // all motor pins to 0
    MC.latch_tx();
  }
}
开发者ID:mikeChastain,项目名称:adafruit-Adafruit-Motor-Shield-library-4bd21ca,代码行数:11,代码来源:AFMotor.cpp

示例4: onestep

void AF_Stepper::onestep(uint8_t dir) {
  if (dir == FORWARD) {
    currentstep++;
  } else {
    // BACKWARDS
    currentstep--;
  }

  currentstep += MICROSTEPS*4;
  currentstep %= MICROSTEPS*4;

#ifdef MOTORDEBUG
  Serial.print("current step: "); Serial.println(currentstep, DEC);
#endif

  // set all of this motor's pins to 0 (don't smash other motor)
  latch_state &= ~a & ~b & ~c & ~d;

  // No wait!  Keep some energized.
  switch (currentstep/(MICROSTEPS/2)) {
  case 0:  latch_state |= a;      break;  // energize coil 1 only
  case 1:  latch_state |= a | b;  break;  // energize coil 1+2
  case 2:  latch_state |= b;      break;  // energize coil 2 only
  case 3:  latch_state |= b | c;  break;  // energize coil 2+3
  case 4:  latch_state |= c;      break;  // energize coil 3 only
  case 5:  latch_state |= c | d;  break;  // energize coil 3+4
  case 6:  latch_state |= d;      break;  // energize coil 4 only
  case 7:  latch_state |= d | a;  break;  // energize coil 1+4
  }

  // change the energized state now
  MC.latch_tx();
}
开发者ID:LgHS,项目名称:Makelangelo-firmware,代码行数:33,代码来源:AFMotorDrawbot.cpp

示例5: run

void AF_DCMotor::run(uint8_t cmd) {
  uint8_t a, b;
  switch (motornum) {
  case 1:
    a = MOTOR1_A; b = MOTOR1_B; break;
  case 2:
    a = MOTOR2_A; b = MOTOR2_B; break;
  case 3:
    a = MOTOR3_A; b = MOTOR3_B; break;
  case 4:
    a = MOTOR4_A; b = MOTOR4_B; break;
  default:
    return;
  }
  
  if(a != MOTOR2_A) {
    switch (cmd) {
      case FORWARD:
        latch_state |= _BV(a);
        latch_state &= ~_BV(b); 
        MC.latch_tx();
        break;
      case BACKWARD:
        latch_state &= ~_BV(a);
        latch_state |= _BV(b); 
        MC.latch_tx();
        break;
      case RELEASE:
        latch_state &= ~_BV(a);
        latch_state &= ~_BV(b);
        MC.latch_tx();
        break;
      }
  }
  else {
    switch (cmd) {
      case FORWARD:
        //digitalWrite(12, 0x01);
        PORTB |= _BV(4);
        break;
      case BACKWARD:
        //digitalWrite(12, 0x00);
        PORTB &=  ~_BV(4);
        break;         
      }
  }
}
开发者ID:Jeevith78,项目名称:arduinolab,代码行数:47,代码来源:AFMotor.cpp

示例6: pinMode

AF_Stepper::AF_Stepper(uint16_t steps, uint8_t num) {
  MC.enable();

  revsteps = steps;
  steppernum = num;

  if (steppernum == 1) {
    latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) &
      ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0
    MC.latch_tx();
    
    // enable both H bridges
    pinMode(11, OUTPUT);
    pinMode(3, OUTPUT);
    digitalWrite(11, HIGH);
    digitalWrite(3, HIGH);

#ifdef MICROSTEPPING
    // use PWM for microstepping support
    initPWM1(MOTOR12_64KHZ);
    initPWM2(MOTOR12_64KHZ);
    setPWM1(255);
    setPWM2(255);
#endif

  } else if (steppernum == 2) {
    latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B) &
      ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // all motor pins to 0
    MC.latch_tx();

    // enable both H bridges
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);

#ifdef MICROSTEPPING    
    // use PWM for microstepping support
    // use PWM for microstepping support
    initPWM3(1);
    initPWM4(1);
    setPWM3(255);
    setPWM4(255);
#endif
  }
}
开发者ID:Revpatrickchand,项目名称:Arduino-Focuser,代码行数:46,代码来源:AFMotor.cpp

示例7: pinMode

AF_Stepper::AF_Stepper(uint16_t steps, uint8_t num) {
  MC.enable();

  revsteps = steps;
  steppernum = num;
  currentstep = 0;

  if (steppernum == 1) {
    latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) &
      ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0
    MC.latch_tx();

    // enable both H bridges
    pinMode(11, OUTPUT);
    pinMode(3, OUTPUT);
    digitalWrite(11, HIGH);
    digitalWrite(3, HIGH);

    // use PWM for microstepping support
    initPWM1(STEPPER1_PWM_RATE);
    initPWM2(STEPPER1_PWM_RATE);
    setPWM1(255);
    setPWM2(255);

  } else if (steppernum == 2) {
    latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B) &
      ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // all motor pins to 0
    MC.latch_tx();

    // enable both H bridges
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);

    // use PWM for microstepping support
    // use PWM for microstepping support
    initPWM3(STEPPER2_PWM_RATE);
    initPWM4(STEPPER2_PWM_RATE);
    setPWM3(255);
    setPWM4(255);
  }
}
开发者ID:mikeChastain,项目名称:adafruit-Adafruit-Motor-Shield-library-4bd21ca,代码行数:43,代码来源:AFMotor.cpp

示例8: pinMode

/*--    MOTOR SETTINGS      --*/
 AF_Stepper::AF_Stepper(uint16_t steps, uint8_t num) 
 {
  MC.enable();

  revsteps = steps;
  steppernum = num;
  currentstep = 0;

  if (steppernum == 1) {
    latch_state &= ~_BV(MOTOR1_A) & ~_BV(MOTOR1_B) &
      ~_BV(MOTOR2_A) & ~_BV(MOTOR2_B); // all motor pins to 0
    MC.latch_tx();
    
    // enable both H bridges
    pinMode(11, OUTPUT);
    pinMode(3, OUTPUT);
    digitalWrite(11, HIGH);
    digitalWrite(3, HIGH);

    a = _BV(MOTOR1_A);
    b = _BV(MOTOR2_A);
    c = _BV(MOTOR1_B);
    d = _BV(MOTOR2_B);
  } else if (steppernum == 2) {
    latch_state &= ~_BV(MOTOR3_A) & ~_BV(MOTOR3_B) &
      ~_BV(MOTOR4_A) & ~_BV(MOTOR4_B); // all motor pins to 0
    MC.latch_tx();

    // enable both H bridges
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);

    a = _BV(MOTOR3_A);
    b = _BV(MOTOR4_A);
    c = _BV(MOTOR3_B);
    d = _BV(MOTOR4_B);
  }
 }
开发者ID:glennlopez,项目名称:Arc,代码行数:41,代码来源:AFMotor.cpp

示例9: onestep

/*--    MOTOR ONE-STEP CONFIG      --*/
 uint8_t AF_Stepper::onestep(uint8_t dir) 
 {
  if((currentstep/(MICROSTEPS/2)) % 2) 
   { // we're at an odd step, weird
     if(dir == FORWARD) currentstep += MICROSTEPS/2;
     else               currentstep -= MICROSTEPS/2;
   } 
     else 
      {           // go to the next even step
      if(dir == FORWARD) currentstep += MICROSTEPS;
      else               currentstep -= MICROSTEPS;
      }

 currentstep += MICROSTEPS*4;
 currentstep %= MICROSTEPS*4;

 #ifdef MOTORDEBUG
 Serial.print("current step: "); Serial.println(currentstep, DEC);
 #endif

  // preprare to release all coils
  latch_state &= ~a & ~b & ~c & ~d; // all motor pins to 0

  // No wait!  Keep some energized.
  switch (currentstep/(MICROSTEPS/2)) 
  {
    case 0:  latch_state |= a;      break;  // energize coil 1 only
    case 1:  latch_state |= a | b;  break;  // energize coil 1+2
    case 2:  latch_state |= b;      break;  // energize coil 2 only
    case 3:  latch_state |= b | c;  break;  // energize coil 2+3
    case 4:  latch_state |= c;      break;  // energize coil 3 only
    case 5:  latch_state |= c | d;  break;  // energize coil 3+4
    case 6:  latch_state |= d;      break;  // energize coil 4 only
    case 7:  latch_state |= d | a;  break;  // energize coil 1+4
  }

  // change the energized state now
  MC.latch_tx();
  
  return currentstep;
 }
开发者ID:glennlopez,项目名称:Arc,代码行数:42,代码来源:AFMotor.cpp

示例10: release

void AF_Stepper::release() {
  // release all
  latch_state &= ~a & ~b & ~c & ~d; // all motor pins to 0
  MC.latch_tx();
}
开发者ID:LgHS,项目名称:Makelangelo-firmware,代码行数:5,代码来源:AFMotorDrawbot.cpp

示例11: onestep


//.........这里部分代码省略.........
    }
  } else if (style == INTERLEAVE) {
    if (dir == FORWARD) {
       currentstep += MICROSTEPS/2;
    } else {
       currentstep -= MICROSTEPS/2;
    }
  }

  if (style == MICROSTEP) {
    if (dir == FORWARD) {
      currentstep++;
    } else {
      // BACKWARDS
      currentstep--;
    }

    currentstep += MICROSTEPS*4;
    currentstep %= MICROSTEPS*4;

    ocra = ocrb = 0;
    if ( (currentstep >= 0) && (currentstep < MICROSTEPS)) {
      ocra = microstepcurve[MICROSTEPS - currentstep];
      ocrb = microstepcurve[currentstep];
    } else if  ( (currentstep >= MICROSTEPS) && (currentstep < MICROSTEPS*2)) {
      ocra = microstepcurve[currentstep - MICROSTEPS];
      ocrb = microstepcurve[MICROSTEPS*2 - currentstep];
    } else if  ( (currentstep >= MICROSTEPS*2) && (currentstep < MICROSTEPS*3)) {
      ocra = microstepcurve[MICROSTEPS*3 - currentstep];
      ocrb = microstepcurve[currentstep - MICROSTEPS*2];
    } else if  ( (currentstep >= MICROSTEPS*3) && (currentstep < MICROSTEPS*4)) {
      ocra = microstepcurve[currentstep - MICROSTEPS*3];
      ocrb = microstepcurve[MICROSTEPS*4 - currentstep];
    }
  }

  currentstep += MICROSTEPS*4;
  currentstep %= MICROSTEPS*4;

#ifdef MOTORDEBUG
  Serial.print("current step: "); Serial.println(currentstep, DEC);
  Serial.print(" pwmA = "); Serial.print(ocra, DEC);
  Serial.print(" pwmB = "); Serial.println(ocrb, DEC);
#endif

  if (steppernum == 1) {
    setPWM1(ocra);
    setPWM2(ocrb);
  } else if (steppernum == 2) {
    setPWM3(ocra);
    setPWM4(ocrb);
  }


  // release all
  latch_state &= ~a & ~b & ~c & ~d; // all motor pins to 0

  //Serial.println(step, DEC);
  if (style == MICROSTEP) {
    if ((currentstep >= 0) && (currentstep < MICROSTEPS))
      latch_state |= a | b;
    if ((currentstep >= MICROSTEPS) && (currentstep < MICROSTEPS*2))
      latch_state |= b | c;
    if ((currentstep >= MICROSTEPS*2) && (currentstep < MICROSTEPS*3))
      latch_state |= c | d;
    if ((currentstep >= MICROSTEPS*3) && (currentstep < MICROSTEPS*4))
      latch_state |= d | a;
  } else {
    switch (currentstep/(MICROSTEPS/2)) {
    case 0:
      latch_state |= a; // energize coil 1 only
      break;
    case 1:
      latch_state |= a | b; // energize coil 1+2
      break;
    case 2:
      latch_state |= b; // energize coil 2 only
      break;
    case 3:
      latch_state |= b | c; // energize coil 2+3
      break;
    case 4:
      latch_state |= c; // energize coil 3 only
      break;
    case 5:
      latch_state |= c | d; // energize coil 3+4
      break;
    case 6:
      latch_state |= d; // energize coil 4 only
      break;
    case 7:
      latch_state |= d | a; // energize coil 1+4
      break;
    }
  }


  MC.latch_tx();
  return currentstep;
}
开发者ID:mikeChastain,项目名称:adafruit-Adafruit-Motor-Shield-library-4bd21ca,代码行数:101,代码来源:AFMotor.cpp

示例12: onestep


//.........这里部分代码省略.........

      // if at even step, make sure its 'odd'
      if (! (step/MICROSTEPS % 2)) {
	step = (step + 7*MICROSTEPS) % (8*MICROSTEPS);
      }
      if ((step == MICROSTEPS) || (step == 5*MICROSTEPS)) {
	// get the current microstep
	if (ocrb == 255)
	  mstep = MICROSTEPS;
	else
	  mstep = ocrb / (256UL / MICROSTEPS);
#ifdef MOTORDEBUG
	Serial.print(" uStep = "); Serial.print(mstep, DEC);
#endif
	// ok now go to next step
	mstep += MICROSTEPS;
	mstep %= (MICROSTEPS+1);
	if (mstep == MICROSTEPS)
	  ocrb = 255;
	else
	  ocrb = mstep * (256UL / MICROSTEPS);
	ocra = 255 - ocrb;
#ifdef MOTORDEBUG
	Serial.print(" !> "); Serial.println(mstep, DEC);
#endif
	if (mstep == 0)
	  step = (step + 6*MICROSTEPS) % (8*MICROSTEPS);
      } else {
	// get the current microstep
	if (ocrb == 255)
	  mstep = MICROSTEPS;
	else
	  mstep = ocrb / (256UL / MICROSTEPS);
#ifdef MOTORDEBUG
	Serial.print("uStep = "); Serial.print(mstep, DEC);
#endif
	// ok now go to next step
	mstep++;
	mstep %= (MICROSTEPS + 1);
	if (mstep == MICROSTEPS)
	  ocrb = 255;
	else 
	  ocrb = mstep * (256UL / MICROSTEPS);
	ocra = 255 - ocrb;
#ifdef MOTORDEBUG
	Serial.print(" *> "); Serial.println(mstep, DEC);
#endif
	if (mstep == MICROSTEPS)
	  step = (step + 6*MICROSTEPS) % (8*MICROSTEPS);
      }
    }
  }


  //Serial.print(" -> step = "); Serial.print(step/MICROSTEPS, DEC); Serial.print("\t");

  if (steppernum == 1) {
    setPWM1(ocra);
     setPWM2(ocrb);
  } else if (steppernum == 2) {
    setPWM3(ocra);
    setPWM4(ocrb);
  }

#endif  // microstepping

  // release all
  latch_state &= ~a & ~b & ~c & ~d; // all motor pins to 0

  //Serial.println(step, DEC);

  switch (step/MICROSTEPS) {
  case 0:
    latch_state |= a; // energize coil 1 only
    break;
  case 1:
    latch_state |= a | b; // energize coil 1+2
    break;
  case 2:
    latch_state |= b; // energize coil 2 only
    break;
  case 3:
    latch_state |= b | c; // energize coil 2+3
    break;
  case 4:
    latch_state |= c; // energize coil 3 only
    break; 
  case 5:
    latch_state |= c | d; // energize coil 3+4
    break;
  case 6:
    latch_state |= d; // energize coil 4 only
    break;
  case 7:
    latch_state |= d | a; // energize coil 1+4
    break;
  }
  MC.latch_tx();
  return mstep;
}
开发者ID:Revpatrickchand,项目名称:Arduino-Focuser,代码行数:101,代码来源:AFMotor.cpp


注:本文中的AFMotorController::latch_tx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。