Sunday, December 20, 2009

servo and photocell 003

//hook up a servo to pin2 and a photocell[stabilize it with resistor] to analog pin 0
//load servo library!

Servo myServo;
int photoCellValue;
int mappedValue;

void setup(){
myServo.attach(2);
}

void loop(){

photoCellValue=analogRead(0);//reads value from the photocell
mappedValue=map(photoCellValue,0,1024,1,180);//check in the help, very usefull

myServo.write(mappedValue);
delay(5);

}

No comments:

Post a Comment