sorry if i was not to specific and i hope you can understand it now.
I just don't understand what you want to do. "Changes to below"? Below what? "or a higher number"? Higher than what?
my ir sensor reads values from 0 to 1023(like any analogpin input) and when this value is lower than 600, the servo starts rotating and while it is rotating, if the ir sensor dectecs something the sensorValue(0 to 1023) should change and if it changes to an number higher than 600 I wanted to stop the servo until it changes again to a number lower than 600
instead of freezing it for 3 seconds.
#include <Servo.h>
const int irsensor = A0; //ir sensor pin
int sensorValue = 0; //ir sensor reading values
int servoPin = 9; //pin where servo is attached to
int i = 0; //servo degrees
Servo servo; //my Servo is called servo
void setup() {
servo.attach(servoPin); //attach servo to servo pin
}
void loop() {
sensorValue = analogRead(irsensor); //ir sensor reading values
if(sensorValue < 600) //if sensorValue is lower than 600
{
for (int i = 0; i<=180; i++) //servo degrees increses from 0 to 180
{
servo.write(i); //servo goes to (i) position
delay(15); //delay of 15 so it as time to change the position gently
if(analogRead(irsensor) > 600) //if it detecs something at that position
{
servo.write(i); //stay in that position
delay(3000); //and here instead of waiting 3 seconds, can it only continue whith the code if sensorValue gets lower than 600
}
}
//the same just from 180 to 0 (in the opposite direction)
for (int i = 180; i>=0; i--)
{
servo.write(i);
delay(15);
if(analogRead(irsensor) > 600)
{
servo.write(i);
delay(3000);
}
}
}
}
thans and i hope you get the idea now but my english isnt the best.