<\/p>\nServo myservo;<\/p>\n
#define echoPin 2
\n#define trigPin 3 <\/p>\n
long duration;
\nint distance;
\nint count = 0;
\nint pos=120;<\/p>\n
void setup() {
\n pinMode(trigPin, OUTPUT);
\n pinMode(echoPin, INPUT);
\n Serial.begin(9600);
\n Serial.println(\u00abHC-SR04 Test\u00bb);
\n Serial.println(\u00abServo\u00bb); <\/p>\n
myservo.attach(9);
\n myservo.write(pos);
\n}
\nvoid loop() {
\n digitalWrite(trigPin, LOW);
\n delayMicroseconds(2);
\n digitalWrite(trigPin, HIGH);
\n delayMicroseconds(10);
\n digitalWrite(trigPin, LOW);
\n duration = pulseIn(echoPin, HIGH);
\n distance = duration * 0.034 \/ 2;
\n Serial.print(\u00abDistancia: \u00ab);
\n Serial.print(distance);
\n Serial.println(\u00bb cm\u00bb);
\n delay(500);<\/p>\n
if (distance <= 20)
\n {
\n Serial.println(\u00abGato detectado \u00ab);
\n if (pos > 20) {
\n for (pos = 120; pos >= 20; pos-=5)
\n {
\n delay(100);
\n myservo.write(pos);
\n }
\n }
\n delay(1000);
\n } else
\n {
\n Serial.println(\u00abGato NO detectado \u00ab);
\n delay(500);
\n Serial.println(pos);
\n if (pos <= 20) {
\n for (pos = 20; pos <= 120; pos+=5)
\n {
\n delay(100);
\n myservo.write(pos);
\n }
\n }
\n pos = 120;
\n } <\/p>\n
}<\/servo.h><\/p>\n","protected":false},"excerpt":{"rendered":"
Tengo problemas de hormigas en casa, y cada vez que dejo la comida del gato abierta, me la encuentro llena de hormigas. Con este invento…<\/p>\n","protected":false},"author":2,"featured_media":849,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[60,82,80,81,24,79],"_links":{"self":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/823"}],"collection":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=823"}],"version-history":[{"count":3,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/823\/revisions"}],"predecessor-version":[{"id":850,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/823\/revisions\/850"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/media\/849"}],"wp:attachment":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}