input select with single active output

Hello there

Im working on a monitor controller that chooses from 3 input sources that can switch to speakers a,b,c.
Each input has a dedicated button to enable it(a relay), but upon activating the chosen input it must disable the other 2 since i only want to hear on input (ditto for the outputrelays).

Can anyone give an example how to write such exclusion ?

Simply turn off the other outputs when you turn the one you've selected on.

thanks... i figured as much, obviously thats not what i was asking :roll_eyes:

I got this far on writing an exclusion, im just wondering if there are better ways to apprach it (there must be).

if (in1Relay == HIGH && in1Led == HIGH) {
    digitalWrite (in2Relay, LOW);
    digitalWrite (in2Led, LOW);
    digitalWrite (in3Relay, LOW);
    digitalWrite (in3Led, LOW);  
  }
  if (in2Relay == HIGH && in2Led == HIGH) {
    digitalWrite (in1Relay, LOW);
    digitalWrite (in1Led, LOW);
    digitalWrite (in3Relay, LOW);
    digitalWrite (in3Led, LOW);
  }
  if (in3Relay == HIGH && in3Led == HIGH) {
    digitalWrite (in1Relay, LOW);
    digitalWrite (in1Led, LOW);
    digitalWrite (in2Relay, LOW);
    digitalWrite (in2Led, LOW);  
  }

Formantix:
thanks... i figured as much, obviously thats not what i was asking :roll_eyes:

Apparently, not that obvious. I'll let someone else deal with the attitude.

Arrch:

Formantix:
thanks... i figured as much, obviously thats not what i was asking :roll_eyes:

Apparently, not that obvious.

...upon activating the chosen input it must disable the other 2...

...Can anyone give an example how to write such exclusion ?...

Dont know what your issue is but it i think i explained it well there.
Regardless, have a nice day

Formantix:
Dont know what your issue is

I think the issue is that Reply #1 addressed your question exactly, so your assertion that this was 'obviously' not your question makes no sense. The question answered was exactly the question you asked. When you start by dismissing people's attempts to help you, it's not exactly encouraging them to bother, is it?

The way I'd address this problem would be to have a function which read the inputs and returned the currently-selected input number (0 .. 2) and another function which output the selected input number (0 .. 2).

I don't know anything about your inputs, but for example if you have a momentary switch per input then you could put the switch input pin numbers in an array and loop through them testing to see whether any of them were active. In this situation I don't think you would need to bother with debouncing.

int getSelectedInput()
{
    static int currentSelection = 0;
    for(int i = 0; i < INPUT_COUNT; i++)
    {
        if(digitalRead(InputPins[i]) == LOW)
        {
            currentSelection = i;
        }
    }
    return currentSelection;
}
void outputCurrentSelection(int selection)
{
    for(int i = 0; i < OUTPUT_COUNT; i++)
    {
        if(i == selection)
        {
           digitalWrite(OutputPins[i], HIGH);
        }
        else
        {
           digitalWrite(OutputPins[i], LOW);
        }
    }
}