Forum Software Ferduino code Change in graph number

Change in graph number  [SOLVED]


Post Number:#1 Post Tue Jul 16, 2019 4:02 am
Posts: 69
Topics: 18
Images: 2
Solve rating: 1
Joined: Tue Apr 14, 2015 11:54 pm
Topics: 18
Age: 42
Gender: Male
National Flag:
Indonesia
Hallo Fernando,

I have trouble changing the chart sequence number, please help, how to calculate this math, I tried it was not good.

this is the code that I use
void LedgrphScreen()//------------------------------------------------------------ tela =61
{
  int x, y, z, grafico;
  int16_t n;
  char buf[8];
  float temperatura;
  int j = 0;
  int i = 0;
  int k = 0;
  float soma = 0.0f; // Soma dos valores de todos os elementos
  float media = 0.0f; // Média dos valores
  float linhaR;
  int f = 30;

  strcpy_P(buffer, (char*)pgm_read_word_near(&(tabela_textos[51])));
  printHeader("TEMP.LED GRAPHIC"); // "TEMP.WATER GRAPHIC"; // tabela_textos[51]

  setFont(SMALL, 255, 255, 255, 0, 0, 0);
  myGLCD.print("TEMP. LED NOW :", 5, 220);

  for (float i = 47; i > 25.0; i -= 2)
  {
    myGLCD.printNumF(i, 1, 5, 3 + f);

    f += 15;
  }

  f = 255;
  for (int i = 22; i > 0; i -= 2)
  {
    myGLCD.printNumI(i, f, 193);
    f -= 20;
  }

  myGLCD.print("0", 275, 193);
  myGLCD.drawCircle(15, 21, 2);
  myGLCD.print("C", 20, 18);
  myGLCD.print("H", 290, 193);
  myGLCD.drawLine(40, 30, 40, 190); // Eixo y
  myGLCD.drawLine(40, 190, 290, 190);  // Eixo x
  myGLCD.setColor(64, 64, 64);  // Malha

  //EIXO X
  for (int k = 30; k < 190; k += 7)
  {
    myGLCD.drawLine(40, k, 290, k);
  }

  //EIXO Y
  for (int l = 60; l < 300; l += 20)
  {
    myGLCD.drawLine(l, 30, l, 190);
  }

  linhaR = tempH;  //  Linhas de comparação

  if ((linhaR >= 27) && (linhaR <= 47))
  {
    x = (190 - ((linhaR - 27) * 10));
  }
  else if (linhaR > 47)
  {
    x = 30;
  }
  else if (linhaR < 27)
  {
    x = 190;
  }


  myGLCD.setColor(255, 0, 0);
  myGLCD.drawLine(40, x, 290, x);// Temperatura desejada

  strcpy_P(buffer, (char*)pgm_read_word_near(&(tabela_textos[11])));
  printButton(buffer, iniC[0], iniC[1], iniC[2], iniC[3], false, 4);

  strcpy_P(buffer, (char*)pgm_read_word_near(&(tabela_textos[1])));
  printButton(buffer, menU[0], menU[1], menU[2], menU[3]);

  strcpy_P(buffer, (char*)pgm_read_word_near(&(tabela_textos[66])));
  printButton(buffer, prOK[0], prOK[1], prOK[2], prOK[3]);

  setFont(SMALL, 255, 255, 0, 0, 0, 0);
  myGLCD.printNumF(tempH, 2, 135, 220);  // LED

  int d = 41 + (NumMins(t.hour, t.min) / 6);

  myGLCD.drawLine(d, 30, d, 190); // Linha de marcação do horário.
  myGLCD.print(rtc.getTimeStr(FORMAT_SHORT), d + 2, 75, 270);

  selecionar_SPI(SD_CARD);

  if (file.open("LOGTLED.TXT", O_READ))
  {
    while ((n = file.read(buf, sizeof(buf))) > 0)
    {
      temperatura = atof(buf);
      soma += temperatura;

      if (strlen(buf) == 5)
      {
        i++;
        k++;
      }

      if (temperatura <= 2 )
      {
        k -= 1;
      }

      if (i == 6)
      {
        media = soma / k;
        i = 0;
        j++;
        soma = 0;
        k = 0;

        if ((media) > 47)
        {
          grafico = 30;
        }
        else if ((media >= 27) && (media <= 47))
        {
          grafico = (190 - ((media - 27) * 10));
        }
        else
        {
          grafico = 190;
        }
        setFont(SMALL, 204, 32, 255, 0, 0, 0);

        if (j < 250)
        {
          myGLCD.drawPixel((40 + j), grafico);
          myGLCD.drawPixel((40 + j), (1 + grafico));
          myGLCD.drawPixel((41 + j), grafico);
          myGLCD.drawPixel((41 + j), (1 + grafico));
        }
      }
    }
    file.close();
  }
}


result images this code
Image

thanks

Post Number:#2 Post Tue Jul 16, 2019 5:32 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

Happy to know you are trying learning coding yet.

I don't think good idea make one line per degress in grid lines.

I think it should be:

  // EIXO X
  for (int k = 40; k < 180; k += 15)
  {
    myGLCD.drawLine(40, k, 290, k);
  }


For others line you have to adjust basically this equation.

  if ((linhaR >= 27) && (linhaR <= 47))
  {
    x = (190 - ((linhaR - 27) * 10));
  }


or

  if ((linhaR >= 27) && (linhaR <= 47))
  {
    x = (190 - ((linhaR - 27) * multiplier));
  }



x here is the y coordinate for red line. So you have to think what should be the multiplier to make x be 40 when linhaR is 47 or make x be 190 when linhaR is 27.

So you can make for linhaR = 47:

40 = (190 - (47 - 27) * multiplier)
40 = 190 - 20 multiplier
20 multiplier = 190 - 40
multiplier = 150 / 20
multiplier = 7.5


Just to make sure when linhaR is 47 x should be 40:

x = 190 - (47 -27) * 7.5
x = 190 - 20 * 7.5
x = 190 - 150
x = 40


Therefore the equation is:

x = (190 - ((linhaR - 27) * 7.5));


Let me know if it help you.

Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#3 Post Wed Jul 17, 2019 10:57 pm
Posts: 69
Topics: 18
Images: 2
Solve rating: 1
Joined: Tue Apr 14, 2015 11:54 pm
Topics: 18
Age: 42
Gender: Male
National Flag:
Indonesia
Thank you answered quickly and detailed explanation,
I am really happy for this. :-bd

thank you I will try, I will post the results here


thanks.

Post Number:#4 Post Tue Jul 30, 2019 4:22 pm
Posts: 1699
Topics: 38
Images: 301
Solve rating: 233
Joined: Mon Mar 03, 2014 5:59 pm
Topics: 38
Age: 39
Location: São Paulo
Gender: Male
National Flag:
Brazil

Hi!

The problem was solved?

Best regards.
Post your doubts on forum because it can help another user too. Just PM me for support if it's absolutely necessary.

Post Number:#5 Post Thu Aug 01, 2019 6:40 am
Posts: 69
Topics: 18
Images: 2
Solve rating: 1
Joined: Tue Apr 14, 2015 11:54 pm
Topics: 18
Age: 42
Gender: Male
National Flag:
Indonesia
Hi!

The problem was solved?

Best regards.



sorry I haven't tried, this month I'm out of town, maybe next week I can try.

:-bd :-bd thank you

Post Number:#6 Post Wed Aug 07, 2019 7:39 pm
Posts: 69
Topics: 18
Images: 2
Solve rating: 1
Joined: Tue Apr 14, 2015 11:54 pm
Topics: 18
Age: 42
Gender: Male
National Flag:
Indonesia
thank you, this went perfectly, as I expected
This problem solved.

Thanks




Return to Ferduino code





Who is online

Users viewing this topic: No registered users and 1 guest

cron