Need Help with multiple conditions "If Statement"

Hello everyone and thanks in advance taking the time to help a new b!

I have seen a couple of "if" statements but none of them seem to do the job I need, or maybe am I thinking all this trough wrong!

Here is the thing, I have a servo with the wiper voltage as feedback to lets say A7
a 1 pole 4 positions rotary commutator pined to A5 to A2 with there respective 20k pulldown resistors,
the switching pole to 5 V. And 4 OUTPUTs lets say 1 to 4!

I have also set 4 pre defined angular positions to where I want the servo to go depending on which input is
HIGH! my sketch will follow.

But I want to include some security calibration!

By exemple when calibrating in the "void setup ()", I send the servo to all 4 specific angular positions, read the wiper value and store it in 4 different variables for the loop

Now we are in the loop

I rotate my commutator to position 2 by exemple and in order to turn HIGH the respective OUTPUT some conditions must be achieved!
First I check what position exactly the commutator is in by adding some security check prior to write the value to the servo. Then if all clear the servo goes to the position, I then read the wiper value and compare it to the previous stored value for this specific position (stored in the void setup () variable) then if fine (within a specific range), only now we turn the respective OUTPUT to HIGH!!! if not we light an led by exemple!

So here comes multiple questions if by exemple

// Library, inputs outputs and other stuffs...

// wiper input pin
const int myServoWiper = A7;

// led
const int led = 13;

// pre located positions in degrees
const int angl1 = 20;
const int angl2 = 25;
const int angl3 = 30; 
const int angl4 = 35;
const int safeAngle = 90;

// commutation input pins
const int pos1 = A5;
const int pos2 = A4;
const int pos3 = A3;
const int pos4 = A2;

// output pins
const int out1 = 1;
const int out2 = 2;
const int out3 = 3;
const int out4 = 4; 

void setup () {

myservo.attach(9);

// pin modes etc..


// calibration
myservo.write(angl1);
delay(5);
int posVal1 = analogRead(myServoWiper);
delay(10);

// angl2

// angl3

myservo.write(angl4);
delay(5);
int posVal4 = analogRead(myServoWiper);
delay(10);

How to properly store the values without having posVal1 equals to posVal2 etc...?

And most importantly how do I use this "If" statement

void loop() {

digitalRead(pos1)
if ( (pos1 == HIGH) && (pos2 == LOW) && (pos3 == LOW) && (pos4 == LOW)  ){
myservo.write(angl1);
} else if ( (pos1 == LOW) && (pos2 == LOW) && (pos3 == LOW) && (pos4 == LOW)  ){ // if 5v wire brakes
    myservo.write(safeAngle);
}

and now I want to include the comparison of my variables to switch the OUTPUT HIGH
if the difference is within a percentage range

how do I include this in the If statement Please

You have a classic mistake here:

digital.Read(pos1)
if ( (pos1 == HIGH) && (pos2 == LOW) && (pos3 == LOW) && (pos4 == LOW) ){

You're trying to read a digital pin, but you then assume that the pin number contains the value you read. It doesn't. Also, it's digitalRead, not digital.Read.

I'm not sure what your other questions mean.

BenzDuino:
How to properly store the values without having posVal1 equals to posVal2 etc...?

The four values are not going to be equal because you have moved the servo before each read.

Your only real problem is that you have defined posVal1 etc as being local to setup() so you can't use them later in loop(). Make them global i.e. define them at the same level as your constants.

And as wildbill said you want to use the VALUES on your pins in your if statement NOT what you have now the PIN NUMBERS. Read each pin first into variables e.g. pin1Val, pin2Val etc then use those variable in the if.

Steve

wildbill:
You have a classic mistake here:

digital.Read(pos1)

if ( (pos1 == HIGH) && (pos2 == LOW) && (pos3 == LOW) && (pos4 == LOW) ){




You're trying to read a digital pin, but you then assume that the pin number contains the value you read. It doesn't. Also, it's digitalRead, not digital.Read.

I'm not sure what your other questions mean.

Thanks for the point of correction!!!

slipstick:
The four values are not going to be equal because you have moved the servo before each read.

Your only real problem is that you have defined posVal1 etc as being local to setup() so you can't use them later in loop(). Make them global i.e. define them at the same level as your constants.

And as wildbill said you want to use the VALUES on your pins in your if statement NOT what you have now the PIN NUMBERS. Read each pin first into variables e.g. pin1Val, pin2Val etc then use those variable in the if.

Steve

Oh ok, so should i put the the calibration process at the constants level as well!

then regarding the digital pin value I should create a variable to store this value in first?

Thank you guys for helping out with this trying to understand the "basics" of Arduino, then hopefully with people like you everything will be cristal clear!!!

I

wildbill:
You have a classic mistake here:

digital.Read(pos1)

if ( (pos1 == HIGH) && (pos2 == LOW) && (pos3 == LOW) && (pos4 == LOW) ){




You're trying to read a digital pin, but you then assume that the pin number contains the value you read. It doesn't. Also, it's digitalRead, not digital.Read.

I'm not sure what your other questions mean.

If I understood properly

void loop() {

int pos1Val = digitalRead(pos1);
int pos2Val = digitalRead(pos2);
int pos2Val = digitalRead(pos3);
int pos4Val = digitalRead(pos4);


if ( (pos1Val == HIGH) && (pos2Val == LOW) && (pos3Val == LOW) && (pos4Val == LOW) ){
myservo.write(angl1);
} else if ( (pos1Val == LOW) && (pos2Val == LOW) && (pos3Val == LOW) && (pos4Val == LOW)  ){
    myservo.write(safeAngle);
}

slipstick:
The four values are not going to be equal because you have moved the servo before each read.

Your only real problem is that you have defined posVal1 etc as being local to setup() so you can't use them later in loop(). Make them global i.e. define them at the same level as your constants.

And as wildbill said you want to use the VALUES on your pins in your if statement NOT what you have now the PIN NUMBERS. Read each pin first into variables e.g. pin1Val, pin2Val etc then use those variable in the if.

Steve

correction

// Library, inputs outputs and other stuffs...

// wiper input pin
const int myServoWiper = A7;

// led
const int led = 13;

// pre located positions in degrees
const int angl1 = 20;
const int angl2 = 25;
const int angl3 = 30;
const int angl4 = 35;
const int safeAngle = 90;

// calibration variable to store wiper position
int posVal1;
int posVal2;
int posVal3;
int posVal4;

// commutation input pins
const int pos1 = A5;
const int pos2 = A4;
const int pos3 = A3;
const int pos4 = A2;

// output pins
const int out1 = 1;
const int out2 = 2;
const int out3 = 3;
const int out4 = 4;

void setup () {

myservo.attach(9);

// pin modes etc..


// calibration
myservo.write(angl1);
delay(5);
posVal1 = analogRead(myServoWiper);
delay(10);

// angl2

// angl3

myservo.write(angl4);
delay(5);
posVal4 = analogRead(myServoWiper);
delay(10);

That's look better now but you're wasting a lot of time by posting scrappy little code snippets so we can't see everything you're changing.

I've just wasted my time writing something to explain what you needed to do. Then you posted another little snippet showing that you'd worked it out yourself after you'd asked the questions.

I'll give up now.

Steve

slipstick:
That's look better now but you're wasting a lot of time by posting scrappy little code snippets so we can't see everything you're changing.

I've just wasted my time writing something to explain what you needed to do. Then you posted another little snippet showing that you'd worked it out yourself after you'd asked the questions.

I'll give up now.

Steve

Ok then thanks much guys for you patience and tolerance , looks like every one here is a God!
You were born with super powers!

Hey, moderators you can shut this topic down!!!

Obviously patience, tolerance and humility can't be programmed with Arduino!!!