Determine WHICH pin is high

TomGeorge:
Hi,
As I understand it , each 8266 has one button, only one button, you want to know at a central WiFi point which button is pressed.
Why poll, just wait for the button with its address to send a packet out over the WiFi when it is pressed.

You do not need customised code for each 2866, each 2866 can have a set of dip switches on its PCB.
They are used to set the ID of each 2866.

When the 2866 boots, it reads the dip switches with it unique ID.

Or am I missing something?

Can you post a simple block diagram explaining your system?

Tom..... :slight_smile:

The dip switches are a great idea. I'll have a thought about that.

Robin2:
Jeez, you would have written the 4 or 5 lines of code to iterate over the pins 100 times since you started this Thread - what's the big aversion to a simple reliable and portable solution.

What I suggested using jumpers is just a less elegant version of @TomGeorge's proposal to use a DIP switch.

...R

Yes I know that I would have written these few lines in the time of discussion over here. But I prefer to learn instead of being the fastest code writer in the world :wink:

I wanted to thank you all for you're effort. I'm now going to think a bit about the suggested solutions.

Even if you were to use direct port IO to read 8bits at a time, you'd still need to iterate over the bits that you read...

You COULD use pin change interrupts and queue up a list of which interrupts occurred, and then dequeue individual "events." I guess that wouldn't be iteration (excepting the the pin change interrupt vector needs to iterate over the bits in the port to figure out which one interrupted.) It's just be more complicated.

I've often thought it might be neat to have a "read all digital pins" function that filled in a 16bit/32bit/Array with ALL the pin info, in some convenient but efficient order. Then you could do stuff like:

    a = digitalReadAllPins();   // get all the pin values
    if (a & (AllPins4|AllPins5|AllPins6|AllPins7)) {  // check for any of 4 buttons pressed
      // iterate over the individual buttons.
    }

Potentially much quicker than doing 4 digitalRead() calls.
But you'd have to have separate constants that would be confusing, and while it'd be great for the 13 digital pins of an Uno, it starts to get more complicated if you include the analog pins, or have something like a Mega...