Don't understand why I get an error

I tried this code:

#include<TFT_eSPI.h>
#define BLUE    0x001F
TFT_eSprite tft = TFT_eSprite(&tft);

int x = 160;
int y =160;
int start_angle = 180;
int seg_count =3;
int rx =145;
int ry =145;
int w =15;
unsigned int colour = 255;

void setup() {
  // put your setup code here, to run once:

}

// #########################################################################
// Draw a circular or elliptical arc with a defined thickness
// #########################################################################

// x,y == coords of centre of arc
// start_angle = 0 - 359
// seg_count = number of 3 degree segments to draw (120 => 360 degree arc)
// rx = x axis radius
// yx = y axis radius
// w  = width (thickness) of arc in pixels
// colour = 16 bit colour value
// Note if rx and ry are the same then an arc of a circle is drawn

void loop() {
  int fillArc2(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour)
  {
    byte seg = 3; // Segments are 3 degrees wide = 120 segments for 360 degrees
    byte inc = 3; // Draw segments every 3 degrees, increase to 6 for segmented ring

      // Calculate first pair of coordinates for segment start
      float sx = cos((start_angle - 90) * DEG2RAD);
      float sy = sin((start_angle - 90) * DEG2RAD);
      uint16_t x0 = sx * (rx - w) + x;
      uint16_t y0 = sy * (ry - w) + y;
      uint16_t x1 = sx * rx + x;
      uint16_t y1 = sy * ry + y;

    // Draw colour blocks every inc degrees
   for (int i = start_angle; i < start_angle + seg * seg_count; i += inc) {

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

      tft.fillTriangle(x0, y0, x1, y1, x2, y2, BLUE);
      tft.fillTriangle(x1, y1, x2, y2, x3, y3, BLUE);

      // Copy segment end to sgement start for next segment
      x0 = x2;
      y0 = y2;
      x1 = x3;
      y1 = y3;
   }
  }
}

And I can’t compile:

/Users/gerd/Documents/Arduino/sketch_dec29b/sketch_dec29b.ino: In function 'void loop()':
sketch_dec29b:34:3: error: a function-definition is not allowed here before '{' token
   {
   ^
sketch_dec29b:67:1: error: expected '}' at end of input
 }
 ^
Mehrere Bibliotheken wurden für "TFT_eSPI.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/libraries/TFT_eSPI
Mehrere Bibliotheken wurden für "SPI.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/hardware/espressif/esp32/libraries/SPI
Mehrere Bibliotheken wurden für "FS.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/hardware/espressif/esp32/libraries/FS
Mehrere Bibliotheken wurden für "SPIFFS.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/hardware/espressif/esp32/libraries/SPIFFS
exit status 1
a function-definition is not allowed here before '{' token

I think the brackets are at the right positions :slightly_frowning_face:

You defined your fillArc2 function inside the loop function. You can't do that. You need to define the function outside of it.

Thx!

I tried to integrate this code to an other, but get an error again. I have tho cut the code, because I was not allowed to post more then 9000 characters.

//************************************************
//****  Screen and SPIFFS Headers and Defines ****
//************************************************

//#include<HardwareSerial.h>
#include<TFT_eSPI.h>
#include<SPI.h>
#include "LogoJR.h"
#include "LogoOV.h"
#include "FS.h"
#include "SPIFFS.h"

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x18E3
#define RXD2 16
#define TXD2 17
//#define DEG2RAD 0.0174532925

//HardwareSerial Serial(2);
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite needle = TFT_eSprite(&tft);
TFT_eSprite Nav1 = TFT_eSprite(&tft);
TFT_eSprite Nav2 = TFT_eSprite(&tft);


//******************************************
//****  FreeRTOS Headers and Variables  ****
//******************************************

#include"freertos/FreeRTOS.h"
#include"freertos/Task.h"
//#include"freertos/semphr.h"
#include"esp_system.h"
#include<stdio.h>
TaskHandle_t Task1,Task2;


#define OuterRadius 160
#define InnerRadius 130
#define xCenter 160
#define yCenter 160

int x = 160;
int y =160;
int start_angle = 180;
int seg_count =3;
int rx =145;
int ry =145;
int w =15;
unsigned int colour = 255;
extern const unsigned char logobunny[];
extern uint16_t logoOV[];
float E;

void setup() {
  tft.init();
  tft.setRotation(0);
  splash();
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200, SERIAL_8N1);
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
  Serial.println("");
  Serial.println("Serial Txd is on pin: "+String(TX));  // Monitorausgabe
  Serial.println("Serial Rxd is on pin: "+String(RX));  // Monitorausgabe
  SPIFFSstart();  
  listFiles();
  xTaskCreatePinnedToCore(ScreenRefresh,"Screen Refresh",2500,NULL,30,&Task1,1);
  xTaskCreatePinnedToCore(SerialScan,"Serial Scan",2500,NULL,20,&Task2,0);
  //Serial1.begin(9600,SERIAL_8N1,1,3);
  //Serial1.println("Serial Started");
}

void ScreenRefresh(void *p){
  Serial.println("Task 1 created");
  float i;
  tft.loadFont("micross20");
  Nav1.loadFont("micross15");
  Nav2.loadFont("micross50");
  while(1){
    //xSemaphoreTake(ScreenKeeper,1000);
    float angle=(E*22)+180;
    //VarioNeedle(angle);
    DrawData("Avg.",E,1,85,80,true);
    DrawData("Alt.",1500,0,60,140,false);
    DrawData("Mc.",2,1,100,200,false);
    //delay(10);
  }
}

//*********************************
//****  Deg to Rad conversion  ****
//*********************************

float DEG2RAD(float* angle){
//  float tempangle=*angle;
  *angle=*angle/180*3.141516;
//  return angle;  
}

// #########################################################################
// Draw a circular or elliptical arc with a defined thickness
// #########################################################################

// x,y == coords of centre of arc
// start_angle = 0 - 359
// seg_count = number of 3 degree segments to draw (120 => 360 degree arc)
// rx = x axis radius
// yx = y axis radius
// w  = width (thickness) of arc in pixels
// colour = 16 bit colour value
// Note if rx and ry are the same then an arc of a circle is drawn

  int fillArc2(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour)
  {
    byte seg = 3; // Segments are 3 degrees wide = 120 segments for 360 degrees
    byte inc = 3; // Draw segments every 3 degrees, increase to 6 for segmented ring

      // Calculate first pair of coordinates for segment start
      float sx = cos((start_angle - 90) * DEG2RAD);
      float sy = sin((start_angle - 90) * DEG2RAD);
      uint16_t x0 = sx * (rx - w) + x;
      uint16_t y0 = sy * (ry - w) + y;
      uint16_t x1 = sx * rx + x;
      uint16_t y1 = sy * ry + y;

    // Draw colour blocks every inc degrees
   for (int i = start_angle; i < start_angle + seg * seg_count; i += inc) {

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

      tft.fillTriangle(x0, y0, x1, y1, x2, y2, BLUE);
      tft.fillTriangle(x1, y1, x2, y2, x3, y3, BLUE);

      // Copy segment end to sgement start for next segment
      x0 = x2;
      y0 = y2;
      x1 = x3;
      y1 = y3;
   }
  }
  
//*******************************
//**** Draw NavBox and Data  ****
//*******************************

void DrawData(char title[],float data,int precision, int x,int y,bool sign){
  Nav1.createSprite(30,15);
  //Nav1.fillScreen(YELLOW);
  Nav1.setCursor(0,0);
  Nav1.setTextColor(WHITE,BLACK);
  Nav1.println(title);
  Nav2.createSprite(140,50);
  Nav2.setCursor(0,0);
  Nav2.setTextColor(WHITE,BLACK);
  if ((data>0) && (sign)){
    Nav2.print("+");
  }
  Nav2.println(data,precision);
  Nav1.pushSprite(x,y);
  Nav1.deleteSprite();
  Nav2.pushSprite(x+30,y);
  Nav2.deleteSprite();
}

// ************************************
// ****  Initialize SPIFFS memory  ****
// ************************************

void SPIFFSstart(){
  if (!SPIFFS.begin()){
    Serial.println("SPIFFS initialisation failed!");
    while (1) yield(); // Stay here twiddling thumbs waiting
    }
  Serial.println("\r\nInitialisation done.");
}
}
#endif
/Users/gerd/Documents/Arduino/OpenVarioGauge2/OpenVarioGauge2.ino: In function 'int fillArc2(int, int, int, int, int, int, int, unsigned int)':
OpenVarioGauge2:183:43: error: invalid operands of types 'int' and 'float(float*)' to binary 'operator*'
       float sx = cos((start_angle - 90) * DEG2RAD);
                                           ^
OpenVarioGauge2:184:43: error: invalid operands of types 'int' and 'float(float*)' to binary 'operator*'
       float sy = sin((start_angle - 90) * DEG2RAD);
                                           ^
OpenVarioGauge2:194:40: error: invalid operands of types 'int' and 'float(float*)' to binary 'operator*'
       float sx2 = cos((i + seg - 90) * DEG2RAD);
                                        ^
OpenVarioGauge2:195:40: error: invalid operands of types 'int' and 'float(float*)' to binary 'operator*'
       float sy2 = sin((i + seg - 90) * DEG2RAD);
                                        ^
Mehrere Bibliotheken wurden für "SPIFFS.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/hardware/espressif/esp32/libraries/SPIFFS
Mehrere Bibliotheken wurden für "TFT_eSPI.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/libraries/TFT_eSPI
Mehrere Bibliotheken wurden für "SPI.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/hardware/espressif/esp32/libraries/SPI
Mehrere Bibliotheken wurden für "FS.h" gefunden
 Benutzt: /Users/gerd/Documents/Arduino/hardware/espressif/esp32/libraries/FS
exit status 1
invalid operands of types 'int' and 'float(float*)' to binary 'operator*'

If I activate #define DEG2RAD 0.0174532925 and change float DEG2RAD(float* angle){ to float deg2rad(float* angle){ I can compile

Hi, I assume ESP32? You can attach the .ino file if it is too big for the post frame.

Tom.. :)

OK, thanks!!

If I upload the sketch I have no arc. If I test with this sketch I get one:

#include<TFT_eSPI.h>
#include<SPI.h>

#define DEG2RAD 0.0174532925
#define BLACK   0x0000

TFT_eSPI tft = TFT_eSPI();

void setup(void) {
  tft.begin();

  tft.setRotation(1);

  tft.fillScreen(BLACK);

}


void loop() {
  
    int sc = 35;
    fillArc(160, 80, 180, sc, 160, 160, 35, 0x07E0);
}

// #########################################################################
// Draw an arc with a defined thickness
// #########################################################################

// x,y == coords of centre of arc
// start_angle = 0 - 359
// seg_count = number of 3 degree segments to draw (120 => 360 degree arc)
// rx = x axis radius
// yx = y axis radius
// w  = width (thickness) of arc in pixels
// colour = 16 bit colour value
// Note if rx and ry are the same an arc of a circle is drawn

int fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour)
{

  byte seg = 3; // Segments are 3 degrees wide = 120 segments for 360 degrees
  byte inc = 3; // Draw segments every 3 degrees, increase to 6 for segmented ring

  // Draw colour blocks every inc degrees
  for (int i = start_angle; i < start_angle + seg * seg_count; i += inc) {
    // Calculate pair of coordinates for segment start
    float sx = cos((i - 90) * DEG2RAD);
    float sy = sin((i - 90) * DEG2RAD);
    uint16_t x0 = sx * (rx - w) + x;
    uint16_t y0 = sy * (ry - w) + y;
    uint16_t x1 = sx * rx + x;
    uint16_t y1 = sy * ry + y;

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

    tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
    tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
  }
}

OpenVarioGauge2.ino (8.39 KB)