Hello,
I need to react on a signal. I assumed I could just read it via digitalRead() and use this as a boolean.
However when I write something like that:
Low = 1.5V or less (0.2Vcc) High = 3V or more (0.6Vcc)
In-between is undefined and might read high or low.
And in case you don't know this, unconnected input pins are "floating" and they can (theoretically) float to any voltage and they can read high or low. In my limited experiments with analogRead() the voltage tended to float toward the middle and drift somewhere around about 500. But you can't count-on anything with a floating input.
In the analog world comparators do a great job at this. Simply feed a D/A or fix the refereed to voltage to the level you want to test, then a simple digital read give the answer.
How are you powering this audio board? It should be with the same voltage as your Arduino is running at. If it is not then you need a logic level shifter to get your signal high enough to register.
The code in your first post is wrong. While an analogRead will, set up that pin to read the analogue port, it is not the same with a digitalRead. If you want to do is properly you will have to use a pinMode call before each digitalRead to make that pin a digital input. Then you will find you are not reading zero, like you think you are.
If you want to do is properly you will have to use a pinMode call before each digitalRead to make that pin a digital input. Then you will find you are not reading zero, like you think you are.
So this is what I forgot?
What is your arduino board?
It's actually a XIAO nRF52840 but they are compatible with the arduino stuff (mostly). I plugged the chip to the USB power but the other devices are hanging on the 3V output from the nRF52840.
Default analogRead() resolution for your board is 10bit (0-4095 range). So if your code returns 750 from analog reading - it corresponds to LOW level and digitaRead() MUST returns zero!