Basically my question is this. I want to analogRead a pin, but if the pushbutton also connected to the analog pin turns LOW (i want to perform a digitalRead to the same pin for this reason) the input to stop reading the analog potentiometer value
Welcome to the forum.
If the analog signal is, for example, between 1V and 5V, then you can detect when it is 0V and stop reading.
For the Arduino Uno, it is possible to do a digitalRead() and a analogRead() on the same pin, but you need the analogRead() to detect 0V.
If a analog input can be anything between 0V and 5V, then it is not possible to detect the button. Unless you use an other pin to put a current in the circuit to detect a zero Ohm to GND.
Can you tell more about your project ? Do you need more pins ? There are many tricks to get more pins or do more with a single pin. The easiest is no trick at all and add a I2C I/O expander.
But why?
Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
If you turn your potentiometer down anywhere in the low 30% of its scale, you will read a digital LOW on that pin.
So it's hard to imagine how you can make this work.
If your pushbutton causes the pin to read LOW by shorting it to Ground (the usual way) then guess what happens when the pot is all the way up, shorting the pin to +5V. It won't be good.
Better to use a separate pin for the button and use software to not read the analog input pin when the button is pressed.
You could add some low value resistor (like 10% of the pot value) between the lower leg of the pot and ground. The switch would go in parallel with the fixed resistor. Then, if the analog reading is between 10% and 100% of the input scale, the switch is known to be open and you have a pot reading. If the analog reading is much less than 10%, then you know that the switch is closed. You can sort out the difference in the code.
Note: The 10% figure is approximate, with a voltage divider that would happen when the pot value is 9 times the fixed value.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.