Good afternoon friends, I'm creating a program in C # that should plot the current values of the serial port (arduino) in a picture box. To draw the graph I am creating points (x, y) and linking them forming drawline lines. In this way the graphic is drawn, but the "pen" that runs through the picturebox. I'm trying to do a similar effect to a seismograph (as if the picturebox that moved, such as the video link >). I think it's basically moving several lines. I'm currently doing this:
int contDRAW = 0, a; //contadores
private PointF[] vetpoint = new PointF[6000];//vetor para incrementar o X para fazer o deslocamento
float[] aquisicaoplot = new float[6000]; //vetor onde armazeno cada valor enviado pela serial
//a cada vez que for chamada a função desenhar já tenho um novo y
private void Desenhar()
{
vetpoint[contDRAW].Y = aquisicaoplot[contDRAW];
for (a = 0; a <= contDRAW; a++)
{
if (contDRAW != a)
{
vetpoint[a].X ++;
}
else vetpoint[a].X = 0;
if (contDRAW == 0 || a==0) timerDRAW.Enabled = true;
else graph.DrawLine(new Pen(Color.LightGreen, 0.1f), vetpoint[a - 1].X, 24 * aquisicaoplot[a-1], vetpoint[a].X, 24 *aquisicaoplot[a]);
}
contDRAW++;
}
private void timerDRAW_Tick(object sender, EventArgs e)
{
Refresh();
}
This code comes close to the intended result. The chart is currently shifting, but it is reset and redrawn every time it goes into "for". What can I do? Am I on the right track? If anyone knows or has any tips on how I can do this effect please answer.
EDIT1:
I updated the Draw () function to the following:
private void Desenhar()
{
System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.LimeGreen, 0.1f);
vetpoint[contDRAW].Y = 24*aquisicaoplot[contDRAW];
for (a = 0; a <= contDRAW; a++)
{
if (contDRAW != a) vetpoint[a].X++;
else vetpoint[a].X = 0;
}
if (contDRAW == 0) timerDRAW.Enabled = true;
else graph.DrawLines(myPen, vetpoint);
//else graph.DrawLine(myPen, vetpoint[contDRAW - 1].X, 24 * aquisicaoplot[contDRAW-1], vetpoint[contDRAW].X, 24 * aquisicaoplot[contDRAW]);
contDRAW++;
myPen.Dispose();
}
I've made a little progress in relation to the effect I want to produce, since the graph moves without being redrawn from the beginning, however, it is now very flicker and very delay after drawing several points.