Analog inputs are supposed to be driven by voltage sources of lowish impedance (10k or lower for
full accuracy on Uno and other ATmega based Arduinos).
If you have high impedance (basically floating) analog inputs, they will pick up interference
readily.
This is intrinsic to the thing you are measuring. I think you need some way to ground the inputs
you are not measuring, perhaps by setting all the pins but the one you are currently measuring to
pinMode (A0, OUTPUT)
To measure one of the pins, set its pinMode to INPUT, then do the analogRead(), then set it to OUTPUT
again.
MarkT:
Analog inputs are supposed to be driven by voltage sources of lowish impedance (10k or lower for
full accuracy on Uno and other ATmega based Arduinos).
If you have high impedance (basically floating) analog inputs, they will pick up interference
readily.
This is intrinsic to the thing you are measuring. I think you need some way to ground the inputs
you are not measuring, perhaps by setting all the pins but the one you are currently measuring to
pinMode (A0, OUTPUT)
To measure one of the pins, set its pinMode to INPUT, then do the analogRead(), then set it to OUTPUT
again.
So to understand you correctly, I could do something like this:
So that at any time only the pin you are about to read is set to INPUT and the others are all OUTPUT. Once you've read them all you can do all your tests as normal.
And then something similiar for val2 and so on. And that would let me read them independently?
No, not at all. What is pinVal1, pinVal2 ? The pin you are reading is analogPin.
Make sure to use the generic names for analog pins, ie A0, A1, not 0, 1 (pinMode requires this).
Can you confirm which Arduino board you are using?
MarkT:
No, not at all. What is pinVal1, pinVal2 ? The pin you are reading is analogPin.
Make sure to use the generic names for analog pins, ie A0, A1, not 0, 1 (pinMode requires this).
Can you confirm which Arduino board you are using?
I think I managed to write that in a very confusing manner, sorry about that. This is what I came up with:
Wait I think I understand what you mean, I am supposed to use A1 and so on instead of the int values i created. I assume my variables as such wont work?
int analogTouch1 = A1;
int analogTouch2 = A2;
int analogTouch3 = A3;
int analogTouch4 = A4;
MarkT:
You need to learn about arrays - when you have a bunch of identical things, use an array of them.
const byte analogTouch[4] = { A1, A2, A3, A4 };
void setup()
{
for (byte i = 0 ; i < 4 ; i++)
pinMode (analogTouch[i], OUTPUT) ;
...
}
A byte is plenty to represent a pin number.
I wrote it up in here, and not in the arduino project. But you're correct an arraylist would be a better choice. I am really only somewhat confident in Java, and trying by learning in different languages.