Got the basic code started and tested.
Can anyone suggest an easy way to have the servo move more slowly?
#include <Servo.h>
const int THRESHOLD = 680; // an arbitrary threshold level that's in the range of the analog input
Servo myservo; // create servo object to control a servo
int LDRpin = 0; // analog pin used to connect the potentiometer
int LDRval; // variable to read the value from the analog pin
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the LDR:
int analogValue = analogRead(LDRpin);
// if the analog value is high enough, turn on the Servo:
if (analogValue > THRESHOLD) {
myservo.write(180);
}
else {
myservo.write(0); //Reset the Servo if the value is too low
}
// print the analog value:
Serial.println(analogValue);
delay(150); // delay in between reads for stability
}