if(pos>119) sweepFlag = false; // assign the var
iable again
}else {
if(pos>=60 && pos<=120){
pos=pos-1;
myservo.write(pos);
}
if(pos<61) sweepFlag = true;
}
}
STEP 5: Debugging Robot
#include <Servo.h>
#include <Metro.h>
Metro measureDistance = Metro(50);
Metro sweepServo = Metro(20);
int speedPin_M1 = 5; //M1 Speed Control
int speedPin_M2 = 6; //M2 Speed Control
int directionPin_M1 = 4; //M1 Direction Control
int directionPin_M2 = 7; //M1 Direction Control
unsigned long actualDistance = 0;
Servo myservo; // create servo object to control a servo
int pos = 60;
int sweepFlag = 1;
int URPWM = 3; // PWM Output 0
-
25000US
,
Every 50US represent 1cm
int URTRIG= 10; // PWM trigger pin
uint8_t EnPwmCmd[4]={0x44,0x02,0xbb,0x01}; // distance measure command
void setup(){ // Serial initialization
myservo.attach(9);