示例#1
0
/*
 * move the motor to the given location
 */
void move(int location) {
    int posn = 0;
    ADCON0bits.GO = 1; //ConvertADC();
    while (0 == ADCON0bits.GO); // spin while busy
    posn = ((((unsigned int)ADRESH)<<8)|(ADRESL) - location) / ADC_PRECISION;
    while (0 != posn) { // move forward or back depending on the location
        if (posn < 0) {
            adjustMotor(1);
        } else {
            adjustMotor(0);
        }
        Delay100TCYx(1);
        ADCON0bits.GO = 1; //ConvertADC(); // determine new location and if any change is needed
        while (0 == ADCON0bits.GO); // spin while busy
        posn = ((((unsigned int)ADRESH)<<8)|(ADRESL) - location) / ADC_PRECISION;
    }
    PORTDbits.RD6 = 1; // lock the reader
    PORTDbits.RD7 = 1;
}
示例#2
0
void loop(){

 
  if(move){
    detectLine();
    keepDistance();
    adjustMotor(min(motorLine_l,motorDist_l),min(motorLine_r,motorDist_r));
  }
  else
  {
      hearClap();
  }
}
void loop(){

 
  if(move){
    detectLine();
    keepDistance();
    adjustMotor(min(motorLine_l,motorDist_l),min(motorLine_r,motorDist_r));
    measureDistance();
  }
  else
  {
      detectAlone();
  }
}