I wrote some code that makes my Servo motor rotate whenever the photoresistor gets dark. I held my photoresistor up to a white computer screen and periodically made the screen black. When it sensed black, the servo would move, but when I flash the black color very quickly, (for less than a second) The servo would rotate, but just barely. How do I make it so that the servo rotates completely to how much it should and then go back when it sees white? I am including my current code below.
[code]
#include <Servo.h>
Servo myservo;
int sensorPin = A0;
int sensorValue = 0;
int val;
void setup() {
// put your setup code here, to run once:
myservo.attach(2);
Serial.begin(9600);
myservo.write(80);
}
void loop() {
// put your main code here, to run repeatedly:
sensorValue = (analogRead(sensorPin));
if (sensorValue < 650) {
// cactus
val = 130;
}
else {
//no cactus
val = 80;
myservo.write(val);
delay(0);
}
Serial.println(sensorValue); //debug
myservo.write(val);
delay(15);
}
[/code]