Stap 5:
#include < Servo.h >
Servo myservo;
Servo myservo2;
Const int pingPin = 50;
Const int pingPin2 = 52;
VOID Setup {}
Serial.begin(9600);
myservo.attach(10);
myservo2.attach(11);
}
void loop
{
lange duur, inch, cm;
pinMode (pingPin2, OUTPUT);
digitalWrite (pingPin2, laag);
delayMicroseconds(2);
digitalWrite (pingPin2, hoge);
delayMicroseconds(5);
digitalWrite (pingPin2, laag);
pinMode (pingPin, INPUT);
duur = pulseIn (pingPin, hoge);
duim = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Als (inch < 5) {}
myservo.writeMicroseconds(2000);
myservo2.writeMicroseconds(2000);
}
Als (inch > 5) {}
myservo.writeMicroseconds(1000);
myservo2.writeMicroseconds(1000);
}
Serial.Print(inches);
Serial.Print ("in");
Serial.Print(cm);
Serial.Print("cm");
Serial.println();
delay(100);
}
lange microsecondsToInches(long microseconds)
{
retourneren van microseconden / 74 / 2;
}
lange microsecondsToCentimeters(long microseconds)
{
retourneren van microseconden / 29 / 2;
}