how to use if then condition

#include <Servo.h>

#define threshold 125
#define unpress_angle 90
#define press_angle 0

Servo myservo;
bool trig=true;

void setup() {
Serial.begin(9600);
myservo.attach(9);
myservo.write(unpress_angle);
}

void loop() {

myservo.write(unpress_angle);
delay;

if(analogRead(A0)>= threshold)
{

myservo.write(press_angle);
delay(100);

}
then
{
myservo.write(unpress_angle);
delay(5000);

}

Have a look at the Reference information (top of the page/Resources/Reference) for if. Try using if/else NOT if/then. There's no 'then' in C++.

Steve

sir i want If my If conditon is become true. after that my then conditon become true

(deleted)

yes i know this is not valid text. that why i want to know how i can fix?

i want MY IF condition become true. after that my then condition become true

@vvksh

Other post/duplicate DELETED Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future. Other general help and troubleshooting advice can be found here.

(deleted)

yes, when the analog reading goes over the threshold, I want the servo to move to press_angle, but I want this to happen only once. and after this servo move to unpress angle for 5000ms. and after 5000ms again search for analog reading goes over the threshold and repeat.

vvksh: yes i know this is not valid text. that why i want to know how i can fix?

i want MY IF condition become true. after that my then condition become true

You can't force a computer language to behave more like you think. Your best option is to go look at the documentation for the 'if' statement. There you will find complete explanations and examples of how it should be used.

Your latest reply contains requirements that exceed what can be done with an 'if' statement, although you might need it also.

See the "State change example" that ships with the IDE, to see how an event can trigger an action. I think this must be what you mean by "only once".

If you want to retain some memory of whether an 'if' statement was found to be true in the past, just modify a variable inside the 'if' to reflect that fact.

(deleted)

Good explanation. An example of that logic can be seen in the State Change Example.

sir i don't have much knowledge about coding if possible help me with full coding.

(deleted)

vvksh: sir i don't have much knowledge about coding if possible help me with full coding.

Well, everyone starts with no knowledge of coding. At one time there were not even any computers. How do you think we got to the place where we are now? There were not always forums to go to for help. Have you considered following some kind of learning path?

tove_pedersen:
Compiled but not tested:

#include <Servo.h>

#define threshold 125
#define unpress_angle 90
#define press_angle 0

bool doneTheServoThing = false;

Servo myservo;
bool trig = true;

void setup()
{
 Serial.begin(9600);
 myservo.attach(9);
 myservo.write(unpress_angle);
}//setup

void loop()
{

myservo.write(unpress_angle);
 delay;

if (analogRead(A0) >= threshold && doneTheServoThing == false)
 {
   doneTheServoThing = true;
   myservo.write(press_angle);
   delay(100);
   myservo.write(unpress_angle);
   delay(5000);
 }

if (analogRead(A0) < threshold)
 {
   doneTheServoThing = false;
 }

}//loop

i have tested and thanks this is exactly what i want. thank you soo much.

i have tested and thanks this is exactly what i want.

Do you understand what it does and how it works ? If not than you have learned nothing