TFT_eSPI Code help

Hello. I have my esp32 and ili9341 up and running. I'm not a coder but more of a
play with it till it breaks kind of person :wink:
I'm trying to draw a 'HUD' on my display. It's a 320x240 display set to landscape.
I have it very close to what I want but am having difficulty with one piece of code...

     //SMALLEST_TOP bars_left
     // Draw tick -12th degree 
  for (int i = 330; i < 350; i += 3) 
  {
  // Coodinates of tick to draw
    float sx4 = cos((i - 90) * 0.0174532925);
    float sy4 = sin((i - 90) * 0.0174532925);
    uint16_t x0 = sx4 * 120 + 160;
    uint16_t y0 = sy4 * 120 + 120;
    uint16_t x1 = sx4 * 110 + 160;          //110 should increment by '1' each time.
    uint16_t y1 = sy4 * 110 + 120;          // higher number '110' will make the tick shorter.

    // Draw tick
    tft.drawLine(x0, y0, x1, y1, TFT_BLUE);
    }

This code draws 7 lines 3 degrees apart but I'd like them to get smaller by '1' each time
a new line is drawn.
I've tried adding another for loop but the results have been...not what I want lol

Thank you.

I'll try asking this in programing section.

Thanks

It is much wiser to ask Display related questions in the Displays Forum.

Personally, I avoid the "Programming" forums.
Yes, posting a photo or drawing to illustrate your question is very helpful.
Deleting the post is not !

David.

OK I figured it out. Was quite simple :blush:

 //SMALLEST_TOP bars_left
     // Draw tick -12th degree 
    
  //for (int j = 1; j < 7; j++)  {
  int j = 2;
  for (int i = 330; i < 350; i += 3) 
  {
    
  // Coodinates of tick to draw
    float sx4 = cos((i - 90) * 0.0174532925);
    float sy4 = sin((i - 90) * 0.0174532925);
    uint16_t x0 = sx4 * 120 + 160;
    uint16_t y0 = sy4 * 120 + 120;
    uint16_t x1 = sx4 * (120 - j++) + 160;          //120 should increment by 1 or 2 
    uint16_t y1 = sy4 * (120 - j) + 120;              // 120 here should be the same as above

    // Draw tick
    tft.drawLine(x0, y0, x1, y1, HUD_colour);
    
  }

I have circled the code.

Thank you David.

I was getting anxious that I may have posted this in the wrong Forum so I
tried deleting the post. Sorry if that was a bad thing.

Thanks for looking at my problem :wink:

I am pleased that you have solved it.

A picture beats a thousand words. The "programming" statements are trivial when you understand the problem.

David.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.