#define pingTrig 6
#define pingEcho 7
#include
Servo myservo;
void setup()
{
pinMode(pingTrig, OUTPUT);
pinMode(pingEcho, INPUT);
myservo.attach(9);
}
void loop()
{
long duration, inches, cm;
digitalWrite(pingTrig, LOW);
digitalWrite(pingTrig, HIGH);
delayMicroseconds(10);
digitalWrite(pingTrig, LOW);
duration = pulseIn(pingEcho, HIGH);
cm = duration / 29 / 2;
if(cm < 10 ){
myservo.write(90);
delay(100);
}else{
myservo.write(0);
}
delay(2000);
}
Stavro IshoStavro Isho
asked Nov 27, 2014 at 23:02
1 Answer 1
Your include statement seems to be incomplete; add "Servo.h" to your include to make it look like this:
#include "Servo.h"
Without including "Servo.h", the compiler doesn't know what a servo is, and thus "Servo does not name a type".
answered Nov 28, 2014 at 1:11