Hello, my problem is that the code below correctly gets the temperature (which is converted from double to int, but it doesn't matter now), correctly moves to the right, it successfully prints the pixels UNTIL I reach the right side of the screen.
Then some shifting occurs, but as shown in my video- it shifts several values at once and then prints a straight line at some specified level. The same happens with millis() limit changed to 10 seconds.
What is wrong with my reasoning/algorithm?
For the purpose of video I changed the millis() limit to 1 second, instead of 1 minute.
PS. Should drawgraph and loop be synchronised?
int x=0;//index of array
int rev=0; //indicates that the screen was filled from left to right, x=63 was reached
int array[64];
int tempsave;//saved temperature
U8GLIB_DOGM128 u8g(11, 10, U8G_PIN_NONE); //U8GLIB_DOGM128(cs, a0 [, reset])
void setup()
{
memset(array,0,sizeof(array));
}
void loop()
{
// READ DATA
int chk = DHT.read22(DHT22_PIN);
unsigned long currentMillis = millis();
static unsigned long lastMillis = 0;
// This code gets executed every minute
if ((currentMillis - lastMillis) >= (60*1000UL))
{
lastMillis += (60*1000UL);
tempsave = DHT.temperature;
if(x<64)
{
array[x] = tempsave;
x++;
}
else
{
rev=1;
array[63] = tempsave;
}
}
// The rest gets executed every time
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(800);
}
void draw(void) {
drawgraph(rev);
}
void drawgraph(int &rev) {
if(rev == 0)
{
for(int i=0;i<=x;i++)
{
u8g.drawPixel(i,array[i]);
}
}
else
{
for(int i=0;i<63;i++)
{
array[i]=array[i+1];
u8g.drawPixel(i,array[i]);
}
}
}