Page 139 - 최강 아두이노 스마트 자동차 로봇 키트
P. 139
#define SERVO_DEGREE_RIGHT
//
#define DIR_DISC_CENTER 1
#define DIR_DISC_LEFT 2
#define DIR_DISC_RIGHT 3
// global instance ultrasonic sensor.
NewPing sonar_distance(TRIGGER_PIN, ECHO_PIN,
MAX_DISTANCE);
// global instance servo motor.
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be
created
void setup() {
Serial.begin(9600);
initSystem();
}
//
// get value current distance from HC-SR04 ( ultrasonic )
//
int getCurrDistance()
{
delay(60);
int uS = sonar_distance.ping();
return uS / US_ROUNDTRIP_CM;
}
//
138