Graph drawing from array woes. (SOLVED)

I want to change the x-axis scale of my 125x360 graph on the fly. To do this I plot for six minutes at one pixel a second while storing every fifth value in an array. At the end of six minutes, I clear the screen so that I can re-draw the graph using that data, and then carry on at five second intervals.

I can show the six-minute graph OK

        myGLCD.setColor(0,250,200);
    myGLCD.drawLine((pixKount-1),(125-int(oldiff*10)),pixKount, (125-int(diff*10)));
     myGLCD.setColor(255,150,0);
    myGLCD.drawLine((pixKount-1),(125-int(kW1*10)),pixKount, (125-int(kW*10)));

 oldiff=diff;
 kW1=kW;

and the same code is used OK for the second regular series at five second intervals.

I can accumulate the array OK

        q = q+1;   // q is the array count to 72
        rises[q] = int (diff*10);
        kWs[q] = int(kW*10);

With the following, I can regurgitate the array to the monitor OK but I can't draw the line. Something silly going on, I'm sure, but it complies OK.

void readArray()
{
  Serial.println("   array  ");
        myGLCD.setColor(0,250,200);
  for (int i=1; i<72; i++)  
{
  Serial.println(rises[i]);    // just for testing!
  
   myGLCD.drawLine((i+99),(125-(rises[i-1])),(i+100), (125-(rises[i])));
}
     myGLCD.setColor(255,150,0);
  for (int i=1; i<72; i++)     
    myGLCD.drawLine((i+99),(125-(kWs[i-1])),(i+100), (125-(kWs[i])));

}

Is your display 125 in the x axis or y axis? What does your output values look like?

Post the full code, I can test it on my screen with dummy values. I just need to know the min and max of diff and kW.

Using parentheses when needed is a good idea. (Using) (them) (unnecessarily) (makes) (for) (hard) (to) (read) (code).

If a function expects an int, and you supply something else, it will be implicitly cast to an int. It is not necessary for you to explicitly cast to an int.

but I can't draw the line. Something silly going on, I'm sure

But, you're not about to tell us what that is, I see. Well, good luck.

HazardsMind:
Is your display 125 in the x axis or y axis? What does your output values look like?

Post the full code, I can test it on my screen with dummy values. I just need to know the min and max of diff and kW.

My first reaction was that you are going to regret this, but if you have a 480x340 running under Henning Karlsen, this should run in a window. It might even show what I want in the wrong place where I cannot see it, I have been down that road before. The x-axis is 125 down and the y axis at x=100., the graph being 360x120 i.e. initially 12 degrees over 6 minutes. The only output is graphic at the moment. This is because the values are dummies derived from a single temperature input. Note that only 19 values in the 72-slot array actually get numbers put in them to save time. Everything works except the lines derived from the array - and even that compiles kosher.

UTFT_tempgraph_two_speed_HAZ_ino.ino (10.4 KB)

Everything works except the lines derived from the arra

Specifically, what is wrong with them?

What's the deal here?

        rises[q] = int (diff*10);

The only code that stores data in the array "casts" the value to an int before storing the data in a float array. So, why is the array type float?

 InTemp = (sensorValue(InThermo));

More useless parentheses. You really should get out of the habit of indiscriminately splattering parentheses all over the place.

Not going to lie, but I kinda expected the code to be better written. As Paul said there are a LOT of unneeded parentheses throughout your code. Things getting type casted from float to int only to end back in a float variable.

Your function "readArray()" has Serial.println(rises_); in it, so what does it output? Do you ever see them display in the serial monitor? What does kWs output? Do you see any kind of line at all?_

HazardsMind:
LOT of unneeded parentheses throughout your code. Things getting type casted from float to int only to end back in a float variable.

Yes, I'm feeling my way with this stuff, and the () are essentially a precautionary measure. I reposted the code with a swag of them removed, although the sensor reading stuff has been there for a couple of years. One thing I have learned from this is that I thought I was using the Hacktronics DS18B20 stuff essentially verbatim all along. Not true. I now believe it got bent after discussion with Stanley Seow in KL.

What I want is to convert the float to a pixel count - one pixel = 0.1 degrees for the graph 120 pixels high. I realise things are probably scruffy there but it works and is not the real problem

Your function "readArray()" has Serial.println(rises*); in it, so what does it output? Do you ever see them display in the serial monitor?*
[/quote]
Yes, as I said in OP, the subroutine regurgitates to monitor OK, I just can't draw the lines. I don't need the array on screen, but I see what I expect to see - 19 floats.
> What does kWs output? Do you see any kind of line at all?[/quote]
> No. As I said in the OP, the array is OK but I cannot draw the lines. What I did not properly explain is that I have three, actually four types of graph displayed sequentially.
> 1. the first 6 minutes at 1pxl/second.
> 2. the same 6 minutes derived from the array, displayed at 1pxl/5 seconds, followed by
> 3. the next 24 minutes at 1pxl/5 seconds to give a total of 360pxl = 30 minutes.
> 4. all subsequent graphs 30 minutes at 1pxl/5 seconds
> The only problem is that I can't draw the lines in case 2.
> I'm sure you understand the intent - the main action is at the start of the event and merits the expanded scale, while the combined graph of thirty minutes gives the overall picture. The subsequent displays are largely ceremonial and probably better handled by Android anyway.
> Note that I have only recently got this 400x240 TFT to work OK. It IS OK but I am obliged to use a code for a 480x320, which means that all this is just the sort of thing that can go wrong. It might also explain why some of the code might not look like one would expect.

The only problem is that I can't draw the lines in case 2.

And you STILL haven't explained what ACTUALLY happens. I give up.

PaulS:
I give up.

No surprise there. What I have said on more than one occasion is that I can't draw the lines. This means that, when I want the lines drawn, I try to draw lines, but I fail. I see nothing. Other than that, I obviously don't know what happens as there is nothing to see happening. I have also said that the lines may have been drawn, but off-screen. What I do know is is that the data required to draw the lines is in the right place and retrievable by other means. In the other instances, I do see lines and they are kosher - as clearly explained in the original post.

I see nothing.

That's the FIRST time you've said THAT.

So, what have you done about the converting floats to ints to store in a float array?

I have made the arrays int

int rises[72], kWs[72];

but Arduino doesn't care either way, and this doesn't address the problem. The attach above has been altered, also with some dummy prints stripped out

Have you though about your SRAM? 72*72 = 5184, now you made them ints, so now thats 10368 of the 2K on an UNO or 4K on a Mega. :cold_sweat:

Why do you need to record everything? Why not just draw the points as the data comes in? Of course you need two sets of coordinates, so that's where you have n_X/Ypoint(new) and o_X/Ypoint(old)

I'm sure you can work out the rest from there.

If you really need to record everything then look into other means of storage, like SD cards or maybe even use the Heap (limited there too).

HazardsMind:
Have you though about your SRAM? 72*72 = 5184, now you made them ints, so now thats 10368 of the 2K on an UNO or 4K on a Mega. :cold_sweat:

No, I haven't, and there isn't a problem. I would have thought any problem in this arena would have been immediately apparent when compiling, since I imagine the space would be demanded on declaration of the array. The array is 72x2, I can see the full 6 minute's worth read back to the monitor, and it works just fine. My only problem is drawing the graph using the numbers derived therefrom.

Why do you need to record everything?

I don't. Arduino could run for hours but it only loops once per second for the first six minutes and in that time the recording is only every fifth loop and only two numbers - hence 144.

Why not just draw the points as the data comes in? Of course you need two sets of coordinates, so that's where you have n_X/Ypoint(new) and o_X/Ypoint(old)

That is exactly what I do for the rest of it. The first graph is updated every second, The second graph is updated every five seconds after the first 6 mins (should be) redrawn from the array on the 5 second/pxl scale.. As it happens, the whole circus is continuously recorded on SD every ten seconds, and there is no problem with that either. Indeed, if the array did not work, one rather desperate option was to double the x increment and simply lift the values off the SD. I imagine it would be a lot slower, and it doesn't solve the problem anyway.

I'm sure you can work out the rest from there

Not really.............
.

Well then, I am out of ideas.

It had to be something stupid. The graphs were plotted OK but then erased and I always missed it. I think what happened was that, in order to be certain the array was kosher, I serial printed the whole thing for the first time and that gave me a chance to see the graph. The commands were kosher but the order was wrong and an extra flag was required. I believe I originally had the order right but changed it to simplify the change in the text along the x-axis.