servo position indicate problem

i write code for servo run 0 -180 degree using for loop and i want to indicate led when the servo came 100 degree
for(pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
if(pos=100){
state =HIGH}}
its not working properly

can you help me

Program never reaches your if statement until it goes through all numbers. It only leaves the for loop once pos fails the <=180 condition check.
Try putting it inside the for loop.

INTP is right!
Quick explenation:
The for loop is a loop as the name says, which means during one void loop interval it goes through all the for loop statement and is “stuck” there until it done all of them. So what you want to do is to make the “if-question” after every position change.

for(pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);

if(pos=100)
{
state =HIGH;
}

delay(15);
}

Try this code.

I hope i could help :slight_smile: