Can an analog sensor be used on a non-PWM digital pin?

Not looking for detailed instructions here. Just trying to figure out if this is possible and deserving of further thought.

Can an analog sensor, like an LDR, be used on a digital pin, PWM or normal? I want to use the digital pin as an input to trigger a Leonardo to press a button on the keyboard. I suspect if this is even possible, I'll probably have to define thresholds so that the output of the LDR can be turned into HIGH or LOW state.

I'm basically going to try to connect LDRs to ALL of the pins, both analog and digital and get the Leonardo pressing specific buttons when the LDR is triggered by the interruption of a laser beam. Yes, you've guessed it. It's a laser harp :wink:

Yes you can, but switch point are of course not as well defined as you can with an analogue input.
Datasheet states <= 0.3VCC for a LOW, and >=0.6VCC for a HIGH.

Try with the LDR between pin and ground, and pull up enabled on the pin in setup.
pinMode(ldrPin, INPUT_PULLUP);

Laser harp projects have been done before.
Use the search field on top of this page.
Leo..

Actually all digital input pins on an Atmega has Schmitt trigger with hysteresis of 0.05 VCC
So at 5V Vcc input voltage above 2.625V will be considered as a HIGH and as a LOW blow 2.375V

2.625 - 2/375 = 0.25volt, not 0.05volt.

Are these your own findings?
Because I can only find 0.3VCC and 0.6VCC in the datasheet.
Leo..

Wawa:
2.625 - 2/375 = 0.25volt, not 0.05volt.

Are these your own findings?
Because I can only find 0.3VCC and 0.6VCC in the datasheet.
Leo..

0.05 Vcc = 0.05 * 5V = 0.25V
I can't find this formula in latest datasheet. May be I mixed up with something. However you can check figures in Pin Threshold and Hysteresis section of Atmega datasheet. And numbers are pretty close to that formula.
PS Found some related article - Arduino Uno Schmitt Trigger Voltage Logic Levels - Radish Logic