Momentary "ON-ON" toggle switch choose between 8 outputs?

I did the change and now no outputs turn on, at all. Here's the current code. I've //'d the line you specified, and put the new one in before it.

const byte noOfInput = 3; // change this into the number of input you need
const byte noOfOutput = 8;       // change this into the number of output you need
const byte inputPin[noOfInput] = {11, 12, 10}; // change according to your input pin
const byte outputPin[noOfOutput] = {2, 3, 4, 5, 6, 7, 8, 9}; // change this according to your output pin
const boolean pullUp = true; //true if you use pull up resistor or internal pull up, false if you dont
const boolean outputLogic = false; // true if High mean On, false if HIGH mean off
const boolean debugMode = false; //true if you want to use Serial Monitor
const boolean outputMode = true;//Set to false if use pin 0 or 1 and debugMode true
const unsigned long debounceDelay = 100;

struct debounce
{
  byte inputPin;
  boolean inputState;
  boolean lastInputState;
  boolean currentInputState;
  unsigned long lastDebounceDelay;
};

struct output
{
  byte outputPin;
  boolean outputState;
};

debounce switchPin[noOfInput];
output pinOutput[noOfOutput];


void setup()
{
  for ( int i = 0; i < noOfInput; i++ )
  {
    switchPin[i].inputPin = inputPin[i];
    switchPin[i].lastInputState = pullUp;
    switchPin[i].lastDebounceDelay = 0;
    pinMode(switchPin[i].inputPin, INPUT);
    digitalWrite(switchPin[i].inputPin, switchPin[i].lastInputState);
  }
  for ( int i = 0; i < noOfOutput; i++)
  {
    pinOutput[i].outputPin = outputPin[i];
    pinOutput[i].outputState = !outputLogic;
    pinMode(pinOutput[i].outputPin, OUTPUT);
    digitalWrite(pinOutput[i].outputPin, pinOutput[i].outputState);
  }
  if (debugMode) Serial.begin(115200);
}

void loop()
{

  unsigned long timeNow = millis();
  static byte counter = noOfOutput;
  for ( int i = 0; i < noOfInput; i++ )


  {
    switchPin[i].currentInputState = digitalRead ( switchPin[i].inputPin );
    if ( switchPin[i].currentInputState != switchPin[i].lastInputState )
    {
      switchPin[i].lastDebounceDelay = timeNow;
      switchPin[i].lastInputState = switchPin[i].currentInputState;
    }
    if ( timeNow - switchPin[i].lastDebounceDelay >= debounceDelay )
    {
      if (switchPin[i].currentInputState != switchPin[i].inputState)
      {
        switchPin[i].inputState = switchPin[i].currentInputState;
        if ( switchPin[0].inputState == !pullUp )
        {
          if (debugMode) Serial.print ("Switch 1 Press\tCounter++\t");
          counter++;
          if ( counter >= noOfOutput ) counter = 7;
        }
        if ( switchPin[1].inputState == !pullUp )
        {
          if (debugMode) Serial.print ("Switch 2 Press\tCounter--\t");
          counter--;
          if ( counter > noOfOutput ) counter = 0;
        }
        if ( switchPin[2].inputState == !pullUp )
        {
          if (debugMode) Serial.print ("Switch 3 Press\tSelect Switch Pressed\t");
          if (counter < noOfOutput) pinOutput[counter].outputState = !outputLogic;
          //if (counter < noOfOutput) pinOutput[counter].outputState = !pinOutput[counter].outputState;
          //else if (counter == noOfOutput);
          //{
          //if (debugMode) Serial.print ("Turning all off\t");
          //  for ( int i = 0 ; i < counter ; i++)
          //  {

          //    pinOutput[i].outputState = !outputLogic;
          //  }
          //  if (debugMode) Serial.print ("All off now\t");
          //}
        }

        if (debugMode)
        {
          if ( switchPin[i].inputState == !pullUp )
          {
            Serial.print ("Switch Press detected\t");
            if (counter < noOfOutput) (pinOutput[counter].outputState) ? Serial.print ("On\t") : Serial.print ("Off\t");
            Serial.println (counter);
          }
        }
      }
    }
  }
  if (outputMode)
  {
    for ( int i = 0; i < noOfOutput; i++)
    {
      digitalWrite(pinOutput[i].outputPin, pinOutput[i].outputState);
    }
  }
}

Sorry I meant this

if (counter < noOfOutput) pinOutput[counter].outputState = outputLogic;

Negative. That works the same as the original, except now output 8 only is always on, and if I latch any others on, they cannot be turned off....

What do you really want? Please state your thought process.

An up/down toggle switch will "choose" a relay to turn on, from a bank of 8 relays, one at a time. This will be indicated by an LED for each output on the finished project.

A "hold" button can be pressed to "hold" a chosen relay in the on state, and pressed again to return it to the normal state. "held" relays remain active until the operator chooses that relay again and presses hold.

This way the operator can turn on 1 relay, or many relays, in any combination.

Ideally, I'd like to use a rotary encoder I have with a built in push switch to control the whole process with one knob. I just started with the toggle switch idea to keep it simple as a first project.

So your 'toggle' switch is really your up/down selector looping through the 8 relays... yes?

when you use the up/down (toggle) switch.... you do the following:

1.) turn on a matching led that correlates to the relay
2.) the relay turns on.

is this correct so far?

*There is a 3rd (hold) button/switch as well..

if I I use the up/down (toggle) switch.. and I am at,...say relay #8 (pin7):

the #8 led is on.. and the #8 relay is on... (letting whatever is connected to said relay 'run')..

if I use the up/down (toggle) switch to go DOWN.. to relay #7 (pin6).. does relay #8 (pin7) turn off?

(I have not used/touched the 3rd 'hold' button/switch yet)..

is this correct so far?

Assuming that all the above is correct...

if I do the same scenario... but before using the up/down (toggle) switch to move to relay #7 (pin6).. I DO PRESS the 'hold' button...

relay #8 (pin7) stays on/running..

is this correct?

if so.. what you need is to be able to save the state of each relay.. (so you the hold button knows what state to set the relay to)

Yes, this description is exactly what I want.

So basically what you wanted is, a hybrid between the original using the two switch and the last code i gave to you?

well then I guess this gonna be a long edit. haha wait for it i guess.

Ok try the code i gave below, Should work according to plan.

so the idea now is, The 8th relay will turn on first,if i decide to press the up switch nothing happen as the 8th relay is the highest one. if I press the down switch, it will turn off the 8th relay and turn on the 7th relay, so far i hope Im right. and this continue until i reach the 1st relay

now for the latch so to speak switch

if i at any number of relay, I can press select and that relay will latch even if i press up or down, unless i decide to turn it off again by pressing the select switch at the relay number.

const byte noOfInput = 3; // change this into the number of input you need
const byte noOfOutput = 8;       // change this into the number of output you need
const byte inputPin[noOfInput] = {11, 12, 10}; // change according to your input pin
const byte outputPin[noOfOutput] = {0, 1, 2, 3, 4, 5, 6, 7}; // change this according to your output pin
const boolean pullUp = true; //true if you use pull up resistor or internal pull up, false if you dont
const boolean outputLogic = true; // true if High mean On, false if HIGH mean off
const boolean debugMode = true; //true if you want to use Serial Monitor
const boolean outputMode = false;//Set to false if use pin 0 or 1 and debugMode true
const unsigned long debounceDelay = 10;

struct debounce
{
  byte inputPin;
  boolean inputState;
  boolean lastInputState;
  boolean currentInputState;
  unsigned long lastDebounceDelay;
};

struct output
{
  byte outputPin;
  boolean outputState;
  boolean holdState;
};

debounce switchPin[noOfInput];
output pinOutput[noOfOutput];


void setup()
{
  for ( int i = 0; i < noOfInput; i++ )
  {
    switchPin[i].inputPin = inputPin[i];
    switchPin[i].lastInputState = pullUp;
    switchPin[i].lastDebounceDelay = 0;
    pinMode(switchPin[i].inputPin, INPUT);
    digitalWrite(switchPin[i].inputPin, switchPin[i].lastInputState);
  }
  for ( int i = 0; i < noOfOutput; i++)
  {
    pinOutput[i].outputPin = outputPin[i];
    pinOutput[i].outputState = !outputLogic;
    pinOutput[i].holdState = LOW;
    pinMode(pinOutput[i].outputPin, OUTPUT);
    digitalWrite(pinOutput[i].outputPin, pinOutput[i].outputState);
  }
  if (debugMode) Serial.begin(115200);
}

void loop()
{
  unsigned long timeNow = millis();
  static byte counter = noOfOutput;
  for ( int i = 0; i < noOfInput; i++ )
  {
    switchPin[i].currentInputState = digitalRead ( switchPin[i].inputPin );
    if ( switchPin[i].currentInputState != switchPin[i].lastInputState )
    {
      switchPin[i].lastDebounceDelay = timeNow;
      switchPin[i].lastInputState = switchPin[i].currentInputState;
    }
    if ( timeNow - switchPin[i].lastDebounceDelay >= debounceDelay )
    {
      if (switchPin[i].currentInputState != switchPin[i].inputState)
      {
        switchPin[i].inputState = switchPin[i].currentInputState;
        if ( switchPin[0].inputState == !pullUp )
        {
          if (debugMode) Serial.print ("Switch 1 Press\tCounter++\t");
          counter++;
          if ( counter == noOfOutput ) counter = noOfOutput - 1;
        }
        if ( switchPin[1].inputState == !pullUp )
        {
          if (debugMode) Serial.print ("Switch 2 Press\tCounter--\t");
          counter--;
          if ( counter > noOfOutput ) counter = 0;
        }
        if ( switchPin[2].inputState == !pullUp )
        {
          if (debugMode) Serial.print ("Switch 3 Press\tSelect Switch Pressed\t");
          if (counter < noOfOutput) pinOutput[counter].holdState = !pinOutput[counter].holdState;
          if (debugMode)
          {
            if ( switchPin[i].inputState == !pullUp )
            {
              Serial.print ("Switch Press detected\t");
              if (counter < noOfOutput) (pinOutput[counter].outputState) ? Serial.print ("On\t") : Serial.print ("Off\t");
              Serial.println (counter);
            }
          }
        }
      }
    }
    if (outputMode)
    {
      for ( int i = 0; i < noOfOutput; i++)
      {
        ( pinOutput[i].holdState == HIGH) ? pinOutput[i].outputState = outputMode : ( counter == i ) ? pinOutput[i].outputState = outputMode:pinOutput[i].outputState = !outputMode;
        digitalWrite(pinOutput[i].outputPin, pinOutput[i].outputState);
      }
    }
  }
}

This probably my last take on your particular problem. Usually i would charge for this kind of service, Ouh well maybe this could be my advertisement of how i do my work.

again This code could easily be simplify by using function and also make a class wrapper. The benefit of code i presented so far is the modularity. I made a very specific code for a specific application, however if someone decide to reuse my code, They do not have to wonder to far to edit, enough to just look at the top most part of the program.

Embedded_automation:

Thanks again for your hard work. This is the closest version to what I am after so far. There is a strange phenomenon with the current sketch version however. I totally understand if this is a lost cause for you. I appreciate all of your help with the project this far, and I get it if you don't want to work on this anymore.

I've got the relays mocked up with LED's switched on ground side via pins 2-9, to show me what is "on" and what is "off". In your sketch the third "latch" button is actually toggling the output mode from "turn on" to "turn off", but can not turn on the current selected output without moving the "cursor" off. IE if all of the outputs are on the current selected output is off. Moving 1 position causes that output to switch back on and the new position to switch off. The program "remembers" which outputs are active, but can not switch an output on/off in a static state.

One other small issue is that all outputs start out active. I would prefer only 1 active on startup. I can probably figure out how to do this on my own.

This is probably too complex a scheme for my first arduino project, I've done some small tutorials, but this is the first custom build I've done. Sorry if this is annoying.

@thelastleroy:

Actually remember that your relay is Active LOW, therefore a LOW will activate your relay, Your LED connection must also reflect this.

if your just using your LED without the relay you could always change this line

 const boolean outputLogic = false; // true if High mean On, false if HIGH mean off

into true.

how to reflect Active LOW?

the pic Show how
Dx is the pin number in question.

Yes, my LEDs are wired this way.