// Here we control the Angle of Servo motor using brightness
// Relationship betweeen Angle and Brightness using line equation y-y1=m(x-x1) // find m=(y2-y1)/(x2-x1)//
#include<Servo.h>
int servopin = 9;
int lightpin = A0;
int lightval;
int servopos;
int dt = 100;
Servo myServo;
void setup() {
// put your setup code here, to run once:
// Here we will use Servo motor in a Simple Project
Serial.begin(9600);
pinMode(lightpin,INPUT);
pinMode(servopin,OUTPUT);
myServo.attach(servopin);
}
void loop() {
// put your main code here, to run repeatedly:
lightval=analogRead(lightpin);
Serial.println(lightval);
servopos=(-16./63.)*lightval+(16.*780./63.);
myServo.write(servopos);
}