I am having a hard time understanding why I can't read one analog pin's output with another analog pin. The docs state to put a delay in between, which I've done (I've tried up to one second with the same results). I've got this minimized code:
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A5, OUTPUT);
}
void loop() {
for (int i=0; i<1024; i++){
analogWrite(A5, i);
delay(100);
Serial.println(analogRead(A0));
}
Serial.println("done");
delay(10000);
}
When it starts, it displays 6-9 for a few dozen iterations, then suddenly jumps to ~1018 and remains throughout the rest of the run.
A5
is connected directly to A0
via a 4" jumper cable. Nothing is connected to AREF
. If I connect AREF
to 5v, the output does not change but by a single digit. If I connect it to ground, it immediately outputs 1023
.
I'm hoping this is a "do'h" moment here. Can someone please let me know what I'm not doing correctly?
Update: This is a legit Arduino Uno R3 board. When I connect A0
directly to 5v+, I get 1023
as expected as the output.