Multi-state input on ATMega328p and ATtiny85

I was pondering ideas on how to condense my system down and to consolidate my inputs. I feel like the ATmega328p can handle a lot more than just having simple HIGH/LOW peripherals attached to its GPIO pins.

I was wondering if it was possible to do a multi-state input on a single GPIO pin. Elaborate: have two sensors, both input into the microcontroller, but one uses 3.3v and the other 5v. It's understood that logic high is 3.3/5v (or above a threshold) and logic low is usually 0v (or below a threshold). Would it be possible to define logic LOW/HIGH to distinguish which peripherals are actively sending a signal?

And would it be possible to do the same on the ATtiny85? I'd imagine they would be similar but I just want to make sure.

Before anyone mentions, I am familiar with shift registers, SPI, and I2C communication and I know it's an alternative but this is just for MSI possibilities.

Thank you for helping me learn more!

Would it be possible to define logic LOW/HIGH to distinguish which peripherals are actively sending a signal?

That's the way they are defined. You can not determine whether or not a pin has anything attached to it. If it does, though, the pin is either HIGH or LOW.

Right but I was wondering if voltage (read: logic) levels could be compartmentalized and read intuitively to determine different states.

Example:
You have a device that runs on 5v connected to a GPIO pin and another device that runs on 3.3v on another GPIO pin. It is understood that their logic HIGH levels would be different (voltage-wise) but the microcontroller doesn't see them that way.

What I was wondering is if there is a way for the uC (in this case, the ATmega328p) to differentiate voltage levels to determine whether it is HIGH or LOW.

Basically, what I am getting to is: could you take two devices and modify their voltage so that one outputs 2v when HIGH and the other outputs 3v when HIGH (together, they put out 5v when both are at logic HIGH) and place them on the same GPIO pin on the microcontroller and write the code so that a certain thing happens according to the voltage level. Is that possible without using shift registers or other serial communication?

Danke.

You have a device that runs on 5v connected to a GPIO pin and another device that runs on 3.3v on another GPIO pin.

Why would you connect a 3.3V device to a 5V pin?

You can't part way turn a pin on. Get over it.

Ah, PaulS, I see what happened.

You didn't quite understand my question. It's alright. Maybe one day, if you try hard enough, you could attempt higher-level systems engineering. That's where you really expand your mind and get to ask pretty cool questions like this.

Not to worry. Thank you for the reply and I'm sorry you didn't know the answer.

Cheers.

I don't know of a way to accomplish this with digitalRead(), but you certainly could use analogRead() and use threshold values in software to distinguish signals. Something like the "analogButtons" technique where a single analog pin is connected to several buttons, each with a different value resistor, and you can tell which button was pressed based on the voltage present on the input pin.

The only disadvantage is, analogRead() is quite slow (in comparison). You can tweak the ADC clock prescaler to increase performance (at the cost of accuracy).

Or add a fast external multichannel ADC, such as MCP3208

Valid inputs read as near 0, near 3.3V (2.3 to 3.3), near 5V (>3.5V).
Have weak resistor divider to hold disconnected voltage in the range of

1.5V and < 2.3V,
so it's above 0.3 x Vcc at 3.3V or 5V (0.99 to 1.5V),
and below 0.7 x Vcc at Vcc = 3.3V or 5V (2.31 to 3.5V).