114
edits
mNo edit summary |
|||
Line 137: | Line 137: | ||
Below: The Code for controlling the motor's speed and direction, via the ultrasonic sensor. The sensor outputs a range of distance values, and by continuously detecting the distance it can predict the mode of visitor's movement. | Below: The Code for controlling the motor's speed and direction, via the ultrasonic sensor. The sensor outputs a range of distance values, and by continuously detecting the distance it can predict the mode of visitor's movement. | ||
int SNUM[3] ;// | int SNUM[3] ;// | ||
int INA = 4; // | int INA = 4; // | ||
int PWMA = 5; // | int PWMA = 5; // | ||
int INB = 7; // | int INB = 7; // | ||
int PWMB = 6; // | int PWMB = 6; // | ||
void motospd(int sp1,int sp2) //电机速度控制函数。括号内分别为左右电机速度值, | void motospd(int sp1,int sp2) //电机速度控制函数。括号内分别为左右电机速度值, | ||
Line 173: | Line 173: | ||
} | } | ||
Serial.println(SNUM[2]); | Serial.println(SNUM[2]); | ||
if ((SNUM[0]==1)&&(SNUM[1]==1)&&(SNUM[2]==1))// | if ((SNUM[0]==1)&&(SNUM[1]==1)&&(SNUM[2]==1))// | ||
motospd(100,100); // | motospd(100,100); // | ||
if ((SNUM[0]==0)&&(SNUM[1]==1)&&(SNUM[2]==1)) // | if ((SNUM[0]==0)&&(SNUM[1]==1)&&(SNUM[2]==1)) // | ||
motospd(100,50); // | motospd(100,50); // | ||
if ((SNUM[0]==1)&&(SNUM[1]==1)&&(SNUM[2]==0)) // | if ((SNUM[0]==1)&&(SNUM[1]==1)&&(SNUM[2]==0)) // | ||
motospd(50,100); // | motospd(50,100); // | ||
if ((SNUM[0]==1)&&(SNUM[1]==0)&&(SNUM[2]==1)) // | if ((SNUM[0]==1)&&(SNUM[1]==0)&&(SNUM[2]==1)) // | ||
motospd(-100,-100); // | motospd(-100,-100); // | ||
delay(50);} | delay(50);} | ||
Line 206: | Line 206: | ||
long microsecondsToCentimeters(long microseconds) { | long microsecondsToCentimeters(long microseconds) { | ||
return microseconds / 29 / 2; | return microseconds / 29 / 2; | ||
}// | }// | ||
The code part that controls the servo: | The code part that controls the servo: |
edits