My first post here so let's hope I get it right...
I'm not an experienced programmer so I was a bit surprised when the following code produced five different results.
#include "U8glib.h"
U8GLIB_LC7981_160X80 u8g(26, 27, 28, 29, 22, 23, 24, 25, 34, 30, 31, 33, 32); // 8Bit Com: D0..D7: 26,27,28,29,22,23,24,25, en=34, cs=30 ,di=31,rw=33, reset = 32
int analogIn0;
String displayValueStr;
void setup(void) {
u8g.setFont(u8g_font_6x10);
u8g.setRot180();
u8g.setColorIndex(1);
}
void loop(void) { // picture loop
u8g.firstPage();
do {
analogIn0=analogRead(A0);
displayValueStr = String(analogIn0, DEC);
u8g.setPrintPos(30,7);
u8g.print( "Variable displayValueStr = " + displayValueStr);
u8g.setPrintPos(30,17);
u8g.print( "Variable displayValueStr = " + displayValueStr);
u8g.setPrintPos(30,27);
u8g.print( "Variable displayValueStr = " + displayValueStr);
u8g.setPrintPos(30,37);
u8g.print( "Variable displayValueStr = " + displayValueStr);
u8g.setPrintPos(30,47);
u8g.print( "Variable displayValueStr = " + displayValueStr);
}
while( u8g.nextPage() );
delay(500);
}
The variable analogIn0 is assigned the value of analogRead(A0) only once, but thereafter each time it is used it has a different value.
It looks like each time the variable is used it is re-evaluated - in this case it looks like another analogRead of A0 is done resulting in a new value for each reference to the variable. Is this correct?
If so, what is the best way of preventing this dynamic re-evaluation of the variable?
I want to produce 240 readings of A0 with synchronous readings of A(1) and then manipulate them after the readings have been taken.
Thanks for any help,
Andy.