当前位置: 首页>>代码示例>>C++>>正文


C++ Adafruit_ST7735::fillTriangle方法代码示例

本文整理汇总了C++中Adafruit_ST7735::fillTriangle方法的典型用法代码示例。如果您正苦于以下问题:C++ Adafruit_ST7735::fillTriangle方法的具体用法?C++ Adafruit_ST7735::fillTriangle怎么用?C++ Adafruit_ST7735::fillTriangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_ST7735的用法示例。


在下文中一共展示了Adafruit_ST7735::fillTriangle方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mediabuttons

void mediabuttons() {
    // play
    tft.fillScreen(ST7735_BLACK);
    tft.fillRoundRect(25, 10, 78, 60, 8, ST7735_WHITE);
    tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_RED);
    delay(500);
    // pause
    tft.fillRoundRect(25, 90, 78, 60, 8, ST7735_WHITE);
    tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_GREEN);
    tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_GREEN);
    delay(500);
    // play color
    tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_BLUE);
    delay(50);
    // pause color
    tft.fillRoundRect(39, 98, 20, 45, 5, ST7735_RED);
    tft.fillRoundRect(69, 98, 20, 45, 5, ST7735_RED);
    // play color
    tft.fillTriangle(42, 20, 42, 60, 90, 40, ST7735_GREEN);
}
开发者ID:ubirch,项目名称:ubirch-thgs,代码行数:20,代码来源:tft.cpp

示例2: ringMeter

// #########################################################################
//  Draw the meter on the screen, returns x coord of righthand side
// #########################################################################
int ringMeter(int value, int vmin, int vmax, int x, int y, int r, char *units, byte scheme)
{
  // Minimum value of r is about 52 before value text intrudes on ring
  // drawing the text first is an option
  
  x += r; y += r;   // Calculate coords of centre of ring
  int  w = r / 4;    // Width of outer ring is 1/4 of radius  
  int  angle = 150;  // Half the sweep angle of meter (300 degrees)
  int  text_colour = 0; // To hold the text colour
  int  v = map(value, vmin, vmax, -angle, angle); // Map the value to an angle v
  byte seg = 5; // Segments are 5 degrees wide = 60 segments for 300 degrees
  byte inc = 5; // Draw segments every 5 degrees, increase to 10 for segmented ring

  // Draw colour blocks every inc degrees
  for (int i = -angle; i < angle; i += inc) {

    // Choose colour from scheme
    int colour = 0;
    switch (scheme) {
      case 0: colour = ILI9341_RED; break; // Fixed colour
      case 1: colour = ILI9341_GREEN; break; // Fixed colour
      case 2: colour = ILI9341_BLUE; break; // Fixed colour
      case 3: colour = rainbow(map(i, -angle, angle, 0, 127)); break; // Full spectrum blue to red
      case 4: colour = rainbow(map(i, -angle, angle, 63, 127)); break; // Green to red (high temperature etc)
      case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break; // Red to green (low battery etc)
      default: colour = ILI9341_BLUE; break; // Fixed colour
    }

    // Calculate pair of coordinates for segment start
    float sx = cos((i - 90) * 0.0174532925);
    float sy = sin((i - 90) * 0.0174532925);
    uint16_t x0 = sx * (r - w) + x;
    uint16_t y0 = sy * (r - w) + y;
    uint16_t x1 = sx * r + x;
    uint16_t y1 = sy * r + y;

    // Calculate pair of coordinates for segment end
    float sx2 = cos((i + seg - 90) * 0.0174532925);
    float sy2 = sin((i + seg - 90) * 0.0174532925);
    int x2 = sx2 * (r - w) + x;
    int y2 = sy2 * (r - w) + y;
    int x3 = sx2 * r + x;
    int y3 = sy2 * r + y;

    if (i < v) { // Fill in coloured segments with 2 triangles
      tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
      tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
      text_colour = colour; // Save the last colour drawn
    }
    else // Fill in blank segments
    {
      tft.fillTriangle(x0, y0, x1, y1, x2, y2, 0x0005);
      tft.fillTriangle(x1, y1, x2, y2, x3, y3, 0x0005);
    }
  }

  // Convert value to a string
  char buf[10];
  byte len = 4; if (value > 999) len = 5;
  dtostrf(value, len, 0, buf);

  // Set the text colour to default
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
  // Uncomment next line to set the text colour to the last segment value!
  // tft.setTextColor(text_colour, ILI9341_BLACK);
  
  // Print value, if the meter is large then use big font 6, othewise use 4
  //if (r > 84) tft.drawCentreString(buf, x - 5, y - 20, 6); // Value in middle
 // else tft.drawCentreString(buf, x - 5, y - 20, 4); // Value in middle

  // Print units, if the meter is large then use big font 4, othewise use 2
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
  //if (r > 84) tft.drawCentreString(units, x, y + 30, 4); // Units display
 // else tft.drawCentreString(units, x, y + 5, 2); // Units display

  // Calculate and return right hand side x coordinate
  return x + r;
}
开发者ID:Nand-e,项目名称:STM32-Watering,代码行数:81,代码来源:rainbow.cpp


注:本文中的Adafruit_ST7735::fillTriangle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。