The problem that I am trying to solve at the moment is ensuring that 3 potentiometers move together. This is done by controlling the movement with an LED, when the LED is on the potentiometer can move, when LED is off, the potentiometer can't move (this simulates a solenoid hydraulic valve controlling a cyclinder).
//pins
int leds[3] = {2, 3, 4};
int potPins[3] = {A0, A3, A5};
//vars
int potVals[3];
void setup() {
for(int i = 0; i < 3; i++) //set led pins
{
pinMode(leds[i], OUTPUT);
}
for(int i = 0; i < 3; i++) //set pot pins
{
pinMode(potPins[i], INPUT);
}
}
void loop() {
for (int i = 0; i < 3; i++) //read pot pins
{
potVals[i] = analogRead(potPins[i]);
}
for (int i = 0; i < 3; i++) //control speed on down stroke
{
if(potVals[i] > 0.9*potVals[!i] && potVals[i] < 1.1*potVals[!i])
{
digitalWrite(leds[i], HIGH);
digitalWrite(leds[!i], HIGH);
}
if(potVals[i] < 0.9*potVals[!i])
{
digitalWrite(leds[i], HIGH);
digitalWrite(leds[!i], LOW);
}
if(potVals[i] > 1.1*potVals[!i])
{
digitalWrite(leds[i], LOW);
digitalWrite(leds[!i], HIGH);
}
}
}
This code does sort of work, but it allows 2 of the potentimeters to run away from the other (even though it can move, if a cyclinder was under a lot more force it wouldn't move with the other), what I need it to do is compare the vals of i vs !notanyi. Because at the moment it compares !i and allows for movement if one of the !i is true.
if(potVals[i] > 1.1*potVals[not any!i])
Is there a way to do this simply?
Many thanks