DigitalIn with custom voltages

16 Jan 2011 . Edited: 16 Jan 2011

Currently digitalin evaluates any voltage under 0.8 volts to logical 0, and anything over 2.0 volts to logical 1.

I would like to be able to change these voltages.  Does anyone know if this would be possible?

Looking at the digitalin() source code would be helpful, but I can only find the header file?

16 Jan 2011

Hi Gary,

The voltages that the microcontroller interprets as logical 0 or 1 actually has nothing to do with the software; this is a function of the microcontroller GPIO hardware/pins. The software is just reading a 0 or 1 from a register. You can actually see the code here:

If you do need to respond to pin voltages in a different way, you could potentially use an AnalogIn (where you can read the actual voltage presented on a pin), or add some external circuitry to convert your signal to 0 or 1 based on your requirements.

Hope that helps, Simon