DFRobot ROB0117 Manuale di avvio rapido - Pagina 12

Sfoglia online o scarica il pdf Manuale di avvio rapido per Microcontrollori DFRobot ROB0117. DFRobot ROB0117 13. Basic kit for cherokey 4wd

2015/11/4
actualDistance = MeasureDistance();
//
Serial.println(actualDistance);
//
delay(100);
}
if(sweepServo.check() == 1){
servoSweep();
}
if(actualDistance <= 30){
myservo.write(90);
if(pos>=90){
carBack(100,100);
//
Serial.println("carBack");
delay(300);
carTurnRight(250,250);
//
Serial.println("carTurnRight");
delay(500);
}else{
carBack(100,100);
//
Serial.println("carBack");
delay(300);
carTurnLeft(250,250);
//
Serial.println("carTurnLeft");
delay(500);
}
}else{
carAdvance(100,100);
//
Serial.println("carAdvance");
delay(300);
}
}
void SensorSetup(){
pinMode(URTRIG,OUTPUT);
digitalWrite(URTRIG,HIGH);
pinMode(URPWM, INPUT);
for(int i=0;i<4;i++){
Serial.write(EnPwmCmd[i]);
}
}
int MeasureDistance(){ // a low pull on pin COMP/TRIG triggering a sensor reading
digitalWrite(URTRIG, LOW);
digitalWrite(URTRIG, HIGH);
unsigned long distance=pulseIn(URPWM,LOW);
if(distance==50000){
Serial.print("Invalid");
}else{
distance=distance/50;
}
return distance;
}
void carStop(){
digitalWrite(speedPin_M2,0);
digitalWrite(directionPin_M1,LOW);
digitalWrite(speedPin_M1,0);
digitalWrite(directionPin_M2,LOW);
}
void carBack(int leftSpeed,int rightSpeed){
analogWrite (speedPin_M2,leftSpeed);
digitalWrite(directionPin_M1,HIGH);
analogWrite (speedPin_M1,rightSpeed);
digitalWrite(directionPin_M2,HIGH);
}
void carAdvance(int leftSpeed,int rightSpeed){
analogWrite (speedPin_M2,leftSpeed);
digitalWrite(directionPin_M1,LOW);
analogWrite (speedPin_M1,rightSpeed);
digitalWrite(directionPin_M2,LOW);
https://www.dfrobot.com/wiki/index.php?title=Basic_Kit_for_Cherokey_4WD_SKU:ROB0117
Basic Kit for Cherokey 4WD SKU:ROB0117 - Robot Wiki
// A low pull on pin COMP/TRIG
// Set to HIGH
// Sending Enable PWM mode command
// reading Pin PWM will output pulses
// the reading is invalid.
// every 50us low level stands for 1cm
// Motor Stop
//Move forward
//PWM Speed Control
//Move backward
12/13