Go Down

Topic: 8 input. 8 Ouput Switch (Read 744 times) previous topic - next topic

1955_2018

Hi, can anyone help please. Wondering if any code is about that could be modified to my requirements or would a Pic be a better solution?

Anyway…

8 switch Inputs *(could be low or high as I can use a hex inverter to get want I want).
8 outputs *(could be low or high as I can use a hex inverter to get want I want).
*If any input goes low the corresponding output goes high for a pre-set period disabling inputs.
If 2 or more inputs go low at the same time only one input is selected. I assume this conflict would not be an issue if the input ports were scanned.

Any help much appreciated.

Paul

PaulRB

#1
Mar 03, 2017, 08:13 am Last Edit: Mar 03, 2017, 08:17 am by PaulRB
Hi Paul.

From your description, the code should be very simple to write. You won't need any inverters. A PIC would be no more or less suitable than any other type of mcu for this. But people on this forum know about Arduino and less or nothing about PIC.

Are you willing to learn, or would you prefer someone to create the code for you?

1955_2018

Hi, thanks for your response at this time I would prefer if someone could create the code for me that I could tinker with or adapt!

I just mentioned a pic because that would be a one chip solution but as you clearly state we are talking Arduino here.

Regards

Paul

PaulRB

#3
Mar 03, 2017, 08:13 pm Last Edit: Mar 03, 2017, 11:28 pm by PaulRB
Well, as you sound like you are willing to learn to understand the code given to you, and it's only a few lines anyway, I'll get you started.

Code: [Select]
const byte inPins[8] = {2, 3, 4, 5, 6, 7, 8, 9};
const byte outPins[8] = {10, 11, 12, 13, 14, 15, 16, 17};

void setup() {
  for (int i = 0; i < 8; i++) {
    pinMode(inPins[i], INPUT_PULLUP);
    pinMode(outPins[i], OUTPUT);
  }
}

void loop() {
  for (int i = 0; i < 8; i++) {
    if (digitalRead(inPins[i]) == LOW) {
      digitalWrite(outPins[i], HIGH);
      delay(500);
      digitalWrite(outPins[i], LOW);
    }
  }
}

Go Up