Eksempel på for Indeholder også bl.a. en switch case for (int i = -50; i < 51; i += 5) { // Long scale tick length int tl = 15; // Coodinates of tick to draw float sx = cos((i - 90) * 0.0174532925); float sy = sin((i - 90) * 0.0174532925); uint16_t x0 = sx * (100 + tl) + 130; uint16_t y0 = sy * (100 + tl) + 180; uint16_t x1 = sx * 100 + 130; uint16_t y1 = sy * 100 + 180; // Coordinates of next tick for zone fill float sx2 = cos((i + 5 - 90) * 0.0174532925); float sy2 = sin((i + 5 - 90) * 0.0174532925); int x2 = sx2 * (100 + tl) + 130; int y2 = sy2 * (100 + tl) + 180; int x3 = sx2 * 100 + 130; int y3 = sy2 * 100 + 180; // Green zone limits if (i >= -50 && i < scaleColor[0]) { tft.fillTriangle(x0 , y0, x1 , y1, x2 , y2, GREEN); tft.fillTriangle(x1 , y1, x2 , y2, x3 , y3, GREEN); } // Yellow zone limits if (i >= scaleColor[0] && i < scaleColor[1]) { tft.fillTriangle(x0 , y0, x1 , y1, x2 , y2, YELLOW); tft.fillTriangle(x1 , y1, x2 , y2, x3 , y3, YELLOW); } // Red zone limits if (i >= scaleColor[1] && i < 50) { tft.fillTriangle(x0 , y0, x1 , y1, x2 , y2, RED); tft.fillTriangle(x1 , y1, x2 , y2, x3 , y3, RED); } // Short scale tick length if (i % 25 != 0) tl = 8; // Recalculate coords incase tick lenght changed x0 = sx * (100 + tl) + 130; y0 = sy * (100 + tl) + 180; x1 = sx * 100 + 130; y1 = sy * 100 + 180; // Draw tick tft.drawLine(x0 , y0, x1 , y1, BLACK); // Check if labels should be drawn, with position tweaks if (i % 25 == 0) { // Calculate label positions x0 = sx * (100 + tl + 10) + 130; y0 = sy * (100 + tl + 10) + 180; tft.setTextColor(BLACK); tft.setTextSize(1); switch (i / 25) { case -2: tft.setCursor(x0, y0 - 12); #ifdef DEBUG Serial.print(x0);Serial.print(" , ");Serial.println(y0 -12); #endif tft.print(swrString[0]); break; case -1: tft.setCursor(x0, y0 - 9); tft.print(swrString[1]); break; case 0: tft.setCursor(x0, y0 - 6); tft.print(swrString[2]); break; case 1: tft.setCursor(x0, y0 - 9); tft.print(swrString[3]); break; case 2: tft.setCursor(x0, y0 - 12); tft.print(swrString[4]); break; } } // Now draw the arc of the scale sx = cos((i + 5 - 90) * 0.0174532925); sy = sin((i + 5 - 90) * 0.0174532925); x0 = sx * 100 + 130; y0 = sy * 100 + 180; // Draw scale arc, don't draw the last part // if (i < 50) tft.drawLine(x0 , y0, x1 , y1, BLACK); }