Kerias
January 18, 2018, 7:32pm
#1
I don’t know how to research whether I can do this or not, so any help (an answer or a site that would help) would be appreciated!
Basically, I want to do this:
Int thing1
Int thing2
int thing3
For (i=1, i++, i<3) {analogRead (Pin(i))=thing(i)}
Would this result in reading pin 1, 2 and 3, and then storing their respective values to the ints thing1, thing 2, and thing 3?
LarryD
January 18, 2018, 7:38pm
#2
Kerias:
Would this result in reading pin 1, 2 and 3, and then storing their respective values to the ints thing1, thing 2, and thing 3?
No, what you need here is an array
int thing[3];
Kerias:
For (i=1, i++, i<3) {analogRead (Pin(i))=thing(i)}
be carefull with this, this code will only read inputs from pin 1 and 2, you have whether to put
i<=3
, or
i<4
For (i=1, i++, i<3)
That is wrong for a couple of reasons. Don’t capitalize for , and it should be
(i = 1; i < 3; i++)
initialize, compare, increment is the order.
A short sketch to illustrate using arrays.
int thing[3];
const byte pins[] = {A1, A2, A3};
void setup()
{
Serial.begin(9600);
for(int i = 0; i < 3; i++)
{
thing[i] = analogRead(pins[i]);
Serial.print(" Thing ");
Serial.print(i);
Serial.print(" = ");
Serial.println(thing[i]);
}
Serial.println();
}
void loop()
{
}
Also
thing[i] = analogRead(Pin[i]);
Kerias
January 23, 2018, 11:31pm
#6
Thank you all so much for the help! I'll definitely work on fixing my grammar and using arrays, sorry it's been quite some time since I've used Arduino